UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

67 lines (65 loc) • 2.87 kB
"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 StackScreen_exports = {}; __export(StackScreen_exports, { StackScreen: () => StackScreen, appendScreenStackPropsToOptions: () => appendScreenStackPropsToOptions, validateStackPresentation: () => validateStackPresentation }); module.exports = __toCommonJS(StackScreen_exports); var import_react = require("react"); var import_children = require("../../headless/children.cjs"); var import_StackHeaderComponent = require("./StackHeaderComponent.cjs"); var import_StackToolbar = require("./StackToolbar.cjs"); var import_Screen = require("../../views/Screen.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function StackScreen({ children, options, ...rest }) { const updatedOptions = (0, import_react.useMemo)(() => appendScreenStackPropsToOptions(options ?? {}, { children }), [options, children]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Screen.Screen, { ...rest, options: updatedOptions }); } Object.assign(StackScreen, { [import_children.NAVIGATOR_CONFIG]: true }); function validateStackPresentation(options) { if (typeof options === "function") return (...args) => { return validateStackPresentation(options(...args)); }; return options; } function appendScreenStackPropsToOptions(options, props) { let updatedOptions = { ...options, ...props.options }; updatedOptions = validateStackPresentation(updatedOptions); function appendChildOptions(child, options2) { if (child.type === import_StackHeaderComponent.StackHeaderComponent) return (0, import_StackHeaderComponent.appendStackHeaderPropsToOptions)(options2, child.props); else if (child.type === import_StackToolbar.StackToolbarComponent) return (0, import_StackToolbar.appendStackToolbarPropsToOptions)(options2, child.props); else console.warn(`Warning: Unknown child element passed to Stack.Screen: ${child.type.name ?? child.type}`); return options2; } import_react.Children.forEach(props.children, (child) => { if ((0, import_react.isValidElement)(child)) updatedOptions = appendChildOptions(child, updatedOptions); }); return updatedOptions; }