UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

122 lines (121 loc) 6.77 kB
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: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var Tabs_exports = {}; __export(Tabs_exports, { Tabs: () => Tabs, useTabsWithChildren: () => useTabsWithChildren, useTabsWithTriggers: () => useTabsWithTriggers }); module.exports = __toCommonJS(Tabs_exports); var import_native = require("@react-navigation/native"), import_react = require("react"), import_react_native = require("react-native-web"), import_TabContext = require("./TabContext"), import_TabList = require("./TabList"), import_TabRouter = require("./TabRouter"), import_TabSlot = require("./TabSlot"), import_TabTrigger = require("./TabTrigger"), import_common = require("./common"), import_useComponent = require("./useComponent"), import_Route = require("../router/Route"), import_hooks = require("../hooks"), import_href = require("../link/href"), import_url = require("../utils/url"), import_Navigator = require("../views/Navigator"); __reExport(Tabs_exports, require("./TabContext"), module.exports); __reExport(Tabs_exports, require("./TabList"), module.exports); __reExport(Tabs_exports, require("./TabSlot"), module.exports); __reExport(Tabs_exports, require("./TabTrigger"), module.exports); var import_jsx_runtime = require("react/jsx-runtime"); function Tabs(props) { const { children, asChild, options, ...rest } = props, Comp = asChild ? import_common.ViewSlot : import_react_native.View, { NavigationContent } = useTabsWithChildren({ // asChild adds an extra layer, so we need to process the child's children children: asChild && (0, import_react.isValidElement)(children) && children.props && typeof children.props == "object" && "children" in children.props ? children.props.children : children, ...options }); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { style: styles.tabsRoot, ...rest, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NavigationContent, { children }) }); } function useTabsWithChildren(options) { const { children, ...rest } = options; return useTabsWithTriggers({ triggers: parseTriggersFromChildren(children), ...rest }); } function useTabsWithTriggers(options) { const { triggers, ...rest } = options, parentTriggerMap = (0, import_react.use)(import_TabContext.TabTriggerMapContext), routeNode = (0, import_Route.useRouteNode)(), contextKey = (0, import_Route.useContextKey)(), linking = (0, import_react.use)(import_native.LinkingContext).options, routeInfo = (0, import_hooks.useRouteInfo)(); if (!routeNode || !linking) throw new Error("No RouteNode. This is likely a bug in one router."); const initialRouteName = routeNode.initialRouteName, { children, triggerMap } = (0, import_common.triggersToScreens)( triggers, routeNode, linking, initialRouteName, parentTriggerMap, routeInfo, contextKey ), navigatorContext = (0, import_native.useNavigationBuilder)(import_TabRouter.ExpoTabRouter, { children, ...rest, triggerMap, id: contextKey, initialRouteName }), { state, descriptors, navigation, describe, NavigationContent: RNNavigationContent } = navigatorContext, navigatorContextValue = (0, import_react.useMemo)( () => ({ ...navigatorContext, contextKey, router: import_TabRouter.ExpoTabRouter }), [navigatorContext, contextKey, import_TabRouter.ExpoTabRouter] ), NavigationContent = (0, import_useComponent.useComponent)((children2) => /* @__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)(RNNavigationContent, { children: children2 }) }) })); return { state, descriptors, navigation, NavigationContent, describe }; } function parseTriggersFromChildren(children, screenTriggers = [], isInTabList = !1) { return import_react.Children.forEach(children, (child) => { if (!child || !(0, import_react.isValidElement)(child) || (0, import_TabSlot.isTabSlot)(child)) return; if (isFragment(child) && typeof child.props.children != "function") return parseTriggersFromChildren( child.props.children, screenTriggers, isInTabList || (0, import_TabList.isTabList)(child) ); if ((0, import_TabList.isTabList)(child) && typeof child.props.children != "function") { let children2 = child.props.children; return child.props.asChild && (0, import_react.isValidElement)(children2) && children2.props && typeof children2.props == "object" && "children" in children2.props && (children2 = children2.props.children), parseTriggersFromChildren(children2, screenTriggers, isInTabList || (0, import_TabList.isTabList)(child)); } if (!isInTabList || !(0, import_TabTrigger.isTabTrigger)(child)) return; const { href, name } = child.props; if (!href) { process.env.NODE_ENV === "development" && console.warn( `<TabTrigger name={${name}}> does not have a 'href' prop. TabTriggers within a <TabList /> are required to have an href.` ); return; } const resolvedHref = (0, import_href.resolveHref)(href); if ((0, import_url.shouldLinkExternally)(resolvedHref)) return screenTriggers.push({ type: "external", name, href: resolvedHref }); if (!name) { process.env.NODE_ENV === "development" && console.warn( "<TabTrigger> does not have a 'name' prop. TabTriggers within a <TabList /> are required to have a name." ); return; } return screenTriggers.push({ type: "internal", href: resolvedHref, name }); }), screenTriggers; } function isFragment(child) { return child.type === import_react.Fragment; } const styles = import_react_native.StyleSheet.create({ tabsRoot: { flex: 1 } }); //# sourceMappingURL=Tabs.js.map