one
Version:
One is a React framework for web, iOS, and Android apps.
44 lines (40 loc) • 1.8 kB
JavaScript
"use client";
import { Children, isValidElement, useMemo } from "react";
import { NAVIGATOR_CONFIG } from "../../headless/children.mjs";
import { StackHeaderComponent, appendStackHeaderPropsToOptions } from "./StackHeaderComponent.mjs";
import { StackToolbarComponent, appendStackToolbarPropsToOptions } from "./StackToolbar.mjs";
import { Screen } from "../../views/Screen.mjs";
import { jsx } from "react/jsx-runtime";
function StackScreen({ children, options, ...rest }) {
const updatedOptions = useMemo(() => appendScreenStackPropsToOptions(options ?? {}, { children }), [options, children]);
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) {
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 === StackToolbarComponent) return appendStackToolbarPropsToOptions(options2, child.props);
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