UNPKG

one

Version:

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

192 lines (189 loc) 7.7 kB
"use strict"; 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_jsx_runtime = require("react/jsx-runtime"), import_native = require("@react-navigation/native"), import_react = require("react"), import_react_native = require("react-native"), import_hooks = require("../hooks.native.js"), import_href = require("../link/href.native.js"), import_Route = require("../router/Route.native.js"), import_url = require("../utils/url.native.js"), import_Navigator = require("../views/Navigator.native.js"), import_common = require("./common.native.js"), import_TabContext = require("./TabContext.native.js"), import_TabList = require("./TabList.native.js"), import_TabRouter = require("./TabRouter.native.js"), import_TabSlot = require("./TabSlot.native.js"), import_TabTrigger = require("./TabTrigger.native.js"), import_useComponent = require("./useComponent.native.js"); __reExport(Tabs_exports, require("./TabContext.native.js"), module.exports); __reExport(Tabs_exports, require("./TabList.native.js"), module.exports); __reExport(Tabs_exports, require("./TabSlot.native.js"), module.exports); __reExport(Tabs_exports, require("./TabTrigger.native.js"), module.exports); function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function Tabs(props) { var { 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 && /* @__PURE__ */(0, import_react.isValidElement)(children) && children.props && _type_of(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) { var { children, ...rest } = options; return useTabsWithTriggers({ triggers: parseTriggersFromChildren(children), ...rest }); } function useTabsWithTriggers(options) { var { 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."); var 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)(function () { return { ...navigatorContext, contextKey, router: import_TabRouter.ExpoTabRouter }; }, [navigatorContext, contextKey, import_TabRouter.ExpoTabRouter]), NavigationContent = (0, import_useComponent.useComponent)(function (children2) { return /* @__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) { var screenTriggers = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], isInTabList = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1; return import_react.Children.forEach(children, function (child) { if (!(!child || ! /* @__PURE__ */(0, import_react.isValidElement)(child) || (0, import_TabSlot.isTabSlot)(child))) { 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") { var _$children = child.props.children; return child.props.asChild && /* @__PURE__ */(0, import_react.isValidElement)(_$children) && _$children.props && _type_of(_$children.props) === "object" && "children" in _$children.props && (_$children = _$children.props.children), parseTriggersFromChildren(_$children, screenTriggers, isInTabList || (0, import_TabList.isTabList)(child)); } if (!(!isInTabList || !(0, import_TabTrigger.isTabTrigger)(child))) { var { 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; } var 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; } var styles = import_react_native.StyleSheet.create({ tabsRoot: { flex: 1 } }); //# sourceMappingURL=Tabs.native.js.map