UNPKG

one

Version:

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

50 lines (48 loc) 2.05 kB
"use client"; import { Children, isValidElement, useMemo } from "react"; import { NAVIGATOR_CONFIG } from "../../headless/children.mjs"; import { StackHeaderComponent, appendStackHeaderPropsToOptions } from "./StackHeaderComponent.mjs"; import { StackToolbar, appendStackToolbarPropsToOptions } from "./StackToolbar.mjs"; import { getStackToolbarImplementation } from "./StackToolbarImplementation.mjs"; import { Screen } from "../../views/Screen.mjs"; import { jsx } from "react/jsx-runtime"; function StackScreen({ children, options, ...rest }) { const toolbarImplementation = getStackToolbarImplementation(); const updatedOptions = useMemo(() => appendScreenStackPropsToOptions(options ?? {}, { children }, toolbarImplementation), [options, children, toolbarImplementation]); return /* @__PURE__ */jsx(Screen, { ...rest, options: updatedOptions }); } Object.assign(StackScreen, { [NAVIGATOR_CONFIG]: true }); function validateStackPresentation(options) { if (typeof options === "function") return (...args) => { return validateStackPresentation(options(...args)); }; return options; } function appendScreenStackPropsToOptions(options, props, toolbarImplementation) { let updatedOptions = { ...options, ...props.options }; updatedOptions = validateStackPresentation(updatedOptions); function appendChildOptions(child, options2) { if (child.type === StackHeaderComponent) return appendStackHeaderPropsToOptions(options2, child.props);else if (child.type === StackToolbar) return appendStackToolbarPropsToOptions(options2, child.props, toolbarImplementation);else console.warn(`Warning: Unknown child element passed to Stack.Screen: ${child.type.name ?? child.type}`); return options2; } Children.forEach(props.children, child => { if (isValidElement(child)) updatedOptions = appendChildOptions(child, updatedOptions); }); return updatedOptions; } export { StackScreen, appendScreenStackPropsToOptions, validateStackPresentation }; //# sourceMappingURL=StackScreen.mjs.map