one
Version:
One is a new React Framework that makes Vite serve both native and web.
142 lines (141 loc) • 4.94 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 Tabs_web_exports = {};
__export(Tabs_web_exports, {
Tabs: () => Tabs,
default: () => Tabs_web_default
});
module.exports = __toCommonJS(Tabs_web_exports);
var import_core = require("@react-navigation/core");
var import_routers = require("@react-navigation/routers");
var import_react = require("react");
var import_getPathFromState = require("../fork/getPathFromState.cjs");
var import_children = require("../headless/children.cjs");
var import_devHeadlessNote = require("../headless/devHeadlessNote.cjs");
var import_keepMounted = require("../headless/keepMounted.cjs");
var import_useTabs = require("../headless/useTabs.cjs");
var import_linkingConfig = require("../router/linkingConfig.cjs");
var import_TabContext = require("../ui/TabContext.cjs");
var import_Navigator = require("../views/Navigator.cjs");
var import_Protected = require("../views/Protected.cjs");
var import_Screen = require("../views/Screen.cjs");
var import_withLayoutContext = require("./withLayoutContext.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function WebTabsNavigator({
children,
headlessChildren,
initialRouteName,
screenOptions,
id,
...rest
}) {
const {
state,
navigation,
descriptors,
NavigationContent
} = (0, import_core.useNavigationBuilder)(import_routers.TabRouter, {
...rest,
children,
initialRouteName,
screenOptions
});
const descriptorsRef = (0, import_react.useRef)(descriptors);
descriptorsRef.current = descriptors;
const linking = (0, import_linkingConfig.getResolvedLinking)();
const navigatorContextValue = (0, import_react.useMemo)(() => ({
contextKey: id ?? "",
state,
navigation,
descriptorsRef,
router: import_routers.TabRouter
}), [id, navigation, state]);
const triggerMap = (0, import_react.useMemo)(() => {
return Object.fromEntries(state.routes.map((route, index) => {
const options = descriptors[route.key]?.options ?? {};
const href = typeof options.href === "string" ? options.href : (linking?.getPathFromState ?? import_getPathFromState.getPathFromState)({
...state,
index
}, linking?.config);
return [route.name, {
type: "internal",
name: route.name,
href,
action: {
type: "JUMP_TO",
payload: {
name: route.name
}
},
index
}];
}));
}, [descriptors, linking, state]);
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(NavigationContent, {
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_TabContext.TabTriggerMapContext.Provider, {
value: triggerMap,
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Navigator.NavigatorContext.Provider, {
value: navigatorContextValue,
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(HeadlessTabsView, {
customChildren: headlessChildren
})
})
})
});
}
function HeadlessTabsView({
customChildren
}) {
const {
screens,
focused
} = (0, import_useTabs.useTabs)();
const visited = (0, import_keepMounted.useVisitedScreens)(focused.key);
(0, import_devHeadlessNote.devHeadlessNote)("Tabs");
if (customChildren?.length) {
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.Fragment, {
children: customChildren
});
}
return (0, import_keepMounted.renderKeptMountedScreens)(screens, visited);
}
const RNTabs = (0, import_withLayoutContext.withLayoutContext)(WebTabsNavigator);
const TabsWithChildren = (0, import_react.forwardRef)(function TabsWithChildren2({
children,
...props
}, ref) {
const configChildren = import_react.Children.toArray(children).filter(import_children.isNavigatorConfigChild);
const customChildren = (0, import_children.getCustomNavigatorChildren)(children);
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(RNTabs, {
...props,
ref,
headlessChildren: customChildren,
children: configChildren
});
});
const Tabs = Object.assign(TabsWithChildren, {
Protected: import_Protected.Protected,
Screen: import_Screen.Screen
});
var Tabs_web_default = Tabs;