one
Version:
One is a new React Framework that makes Vite serve both native and web.
69 lines (67 loc) • 2.51 kB
JavaScript
"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { Children, isValidElement, useMemo } from "react";
import { StackHeaderComponent, appendStackHeaderPropsToOptions } from "./StackHeaderComponent.native.js";
import { Screen } from "../../views/Screen.native.js";
function StackScreen(param) {
var {
children,
options,
...rest
} = param;
var updatedOptions = useMemo(function () {
return appendScreenStackPropsToOptions(options !== null && options !== void 0 ? options : {}, {
children
});
}, [options, children]);
return /* @__PURE__ */_jsx(Screen, {
...rest,
options: updatedOptions
});
}
var VALID_PRESENTATIONS = ["card", "modal", "transparentModal", "containedModal", "containedTransparentModal", "fullScreenModal", "formSheet", "pageSheet"];
function validateStackPresentation(options) {
if (typeof options === "function") {
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var resolved = options(...args);
validateStackPresentation(resolved);
return resolved;
};
}
if (process.env.NODE_ENV !== "production") {
var 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(function (v) {
return `"${v}"`;
}).join(", ")}.`);
}
}
return options;
}
function appendScreenStackPropsToOptions(options, props) {
var updatedOptions = {
...options,
...props.options
};
validateStackPresentation(updatedOptions);
function appendChildOptions(child, options2) {
if (child.type === StackHeaderComponent) {
return appendStackHeaderPropsToOptions(options2, child.props);
} else {
var _child_type_name;
console.warn(`Warning: Unknown child element passed to Stack.Screen: ${(_child_type_name = child.type.name) !== null && _child_type_name !== void 0 ? _child_type_name : child.type}`);
}
return options2;
}
Children.forEach(props.children, function (child) {
if (/* @__PURE__ */isValidElement(child)) {
updatedOptions = appendChildOptions(child, updatedOptions);
}
});
return updatedOptions;
}
export { StackScreen, appendScreenStackPropsToOptions, validateStackPresentation };
//# sourceMappingURL=StackScreen.native.js.map