one
Version:
One is a React framework for web, iOS, and Android apps.
75 lines (73 loc) • 3.19 kB
JavaScript
"use client";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Drawer_web_exports = {};
__export(Drawer_web_exports, {
Drawer: () => Drawer,
default: () => Drawer_web_default
});
module.exports = __toCommonJS(Drawer_web_exports);
var import_core = require("@react-navigation/core");
var import_routers = require("@react-navigation/routers");
var import_react = require("react");
var import_children = require("../headless/children.cjs");
var import_keepMounted = require("../headless/keepMounted.cjs");
var import_useDrawer = require("../headless/useDrawer.cjs");
var import_withLayoutContext = require("./withLayoutContext.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function WebDrawerNavigator({ children, headlessChildren, initialRouteName, defaultStatus, backBehavior, screenOptions, ...rest }) {
const { state, descriptors, navigation, render } = (0, import_core.useNavigationBuilder)(import_routers.DrawerRouter, {
...rest,
children,
initialRouteName,
defaultStatus,
backBehavior,
screenOptions
});
return render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_useDrawer.DrawerStateProvider, {
state,
descriptors,
navigation,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HeadlessDrawerView, { customChildren: headlessChildren })
}));
}
function HeadlessDrawerView({ customChildren }) {
const { screens, focused } = (0, import_useDrawer.useDrawer)();
const visited = (0, import_keepMounted.useVisitedScreens)(focused.key);
if (customChildren?.length) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: customChildren });
}
return (0, import_keepMounted.renderKeptMountedScreens)(screens, visited);
}
const DrawerNavigator = (0, import_core.createNavigatorFactory)(WebDrawerNavigator)().Navigator;
const RNDrawer = (0, import_withLayoutContext.withLayoutContext)(DrawerNavigator);
const DrawerWithHeadless = (0, import_react.forwardRef)((props, ref) => {
const { children, ...rest } = props;
const customChildren = (0, import_children.getCustomNavigatorChildren)(children);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNDrawer, {
...rest,
ref,
headlessChildren: customChildren.length ? customChildren : void 0,
children: import_react.Children.toArray(children).filter(import_children.isNavigatorConfigChild)
});
});
const Drawer = Object.assign(DrawerWithHeadless, { Screen: RNDrawer.Screen });
var Drawer_web_default = Drawer;