UNPKG

one

Version:

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

100 lines 4.71 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __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; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod)), __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var Stack_exports = {}; __export(Stack_exports, { Stack: () => Stack, default: () => Stack_default }); module.exports = __toCommonJS(Stack_exports); var import_native_stack = require("@react-navigation/native-stack"), import_react = __toESM(require("react"), 1), import_stack_utils = require("./stack-utils/index.cjs"), import_withLayoutContext = require("./withLayoutContext.cjs"), import_children = require("../utils/children.cjs"), import_Protected = require("../views/Protected.cjs"), import_Screen = require("../views/Screen.cjs"), import_jsx_runtime = require("react/jsx-runtime"); const NativeStackNavigator = (0, import_native_stack.createNativeStackNavigator)().Navigator, RNStack = (0, import_withLayoutContext.withLayoutContext)(NativeStackNavigator); function mapChildren(children) { return import_react.Children.toArray(children).map((child, index) => { if ((0, import_children.isChildOfType)(child, import_stack_utils.StackScreen)) { const options = (0, import_stack_utils.appendScreenStackPropsToOptions)({}, child.props), { children: _, ...rest } = child.props; return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { ...rest, options }, child.props.name ?? index); } return (0, import_children.isChildOfType)(child, import_Protected.Protected) ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: child.props.guard, children: mapChildren(child.props.children) }, `protected-${index}`) : (0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent) ? null : child; }).filter(Boolean); } const StackWithComposition = import_react.default.forwardRef((props, ref) => { const { children, screenOptions, ...rest } = props, screenOptionsWithHeader = (0, import_react.useMemo)(() => { const stackHeader = import_react.Children.toArray(children).find(child => (0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent)); if (stackHeader && (0, import_children.isChildOfType)(stackHeader, import_stack_utils.StackHeaderComponent)) { const headerProps = { children: stackHeader }; return screenOptions ? typeof screenOptions == "function" ? (...args) => { const opts = screenOptions(...args); return (0, import_stack_utils.appendScreenStackPropsToOptions)(opts, headerProps); } : (0, import_stack_utils.appendScreenStackPropsToOptions)(screenOptions, headerProps) : (0, import_stack_utils.appendScreenStackPropsToOptions)({}, headerProps); } return screenOptions; }, [children, screenOptions]), processedChildren = (0, import_react.useMemo)(() => mapChildren(children), [children]); return /* @__PURE__ */(0, import_jsx_runtime.jsx)(RNStack, { ...rest, ref, screenOptions: screenOptionsWithHeader, children: processedChildren }); }), Stack = Object.assign(StackWithComposition, { Screen: import_stack_utils.StackScreen, Header: import_stack_utils.StackHeader, Protected: import_Protected.Protected, SearchBar: import_stack_utils.StackHeaderSearchBar }); var Stack_default = Stack;