one
Version:
One is a new React Framework that makes Vite serve both native and web.
68 lines (66 loc) • 2.24 kB
JavaScript
"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { DrawerActions } from "@react-navigation/routers";
import { createContext, useContext, useMemo } from "react";
import { getPathFromState } from "../fork/getPathFromState.native.js";
import { getResolvedLinking } from "../router/linkingConfig.native.js";
var DrawerContext = /* @__PURE__ */createContext(null);
function DrawerStateProvider(param) {
var {
state,
descriptors,
navigation,
children
} = param;
var linking = getResolvedLinking();
var value = useMemo(function () {
var screens = state.routes.map(function (route, index) {
var _ref, _route_params;
var descriptor = descriptors[route.key];
var options = descriptor.options;
var href = ((_ref = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _ref !== void 0 ? _ref : getPathFromState)({
...state,
index
}, linking === null || linking === void 0 ? void 0 : linking.config);
return {
key: route.key,
name: route.name,
params: (_route_params = route.params) !== null && _route_params !== void 0 ? _route_params : {},
href,
isFocused: index === state.index,
keepMounted: options.keepMounted === true,
options,
element: descriptor.render()
};
});
return {
screens,
focused: screens[state.index],
isOpen: state.history.some(function (entry) {
return entry.type === "drawer";
}),
open: function () {
return navigation.dispatch(DrawerActions.openDrawer());
},
close: function () {
return navigation.dispatch(DrawerActions.closeDrawer());
},
toggle: function () {
return navigation.dispatch(DrawerActions.toggleDrawer());
}
};
}, [descriptors, linking, navigation, state]);
return /* @__PURE__ */_jsx(DrawerContext.Provider, {
value,
children
});
}
function useDrawer() {
var value = useContext(DrawerContext);
if (!value) {
throw new Error("useDrawer must be used inside a Drawer navigator");
}
return value;
}
export { DrawerStateProvider, useDrawer };
//# sourceMappingURL=useDrawer.native.js.map