one
Version:
One is a new React Framework that makes Vite serve both native and web.
60 lines (58 loc) • 2.09 kB
JavaScript
"use client";
import { Children, isValidElement, useMemo } from "react";
import { StackHeaderComponent, appendStackHeaderPropsToOptions } from "./StackHeaderComponent.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
});
}
const VALID_PRESENTATIONS = ["card", "modal", "transparentModal", "containedModal", "containedTransparentModal", "fullScreenModal", "formSheet", "pageSheet"];
function validateStackPresentation(options) {
if (typeof options === "function") {
return (...args) => {
const resolved = options(...args);
validateStackPresentation(resolved);
return resolved;
};
}
if (process.env.NODE_ENV !== "production") {
const presentation = options.presentation;
if (presentation && !VALID_PRESENTATIONS.includes(presentation)) {
console.warn(`Invalid presentation value "${presentation}" passed to Stack.Screen. Valid values are: ${VALID_PRESENTATIONS.map(v => `"${v}"`).join(", ")}.`);
}
}
return options;
}
function appendScreenStackPropsToOptions(options, props) {
let updatedOptions = {
...options,
...props.options
};
validateStackPresentation(updatedOptions);
function appendChildOptions(child, options2) {
if (child.type === StackHeaderComponent) {
return appendStackHeaderPropsToOptions(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