one
Version:
One is a new React Framework that makes Vite serve both native and web.
66 lines (64 loc) • 2.85 kB
JavaScript
"use client";
import { jsx } from "react/jsx-runtime";
import { Children, isValidElement, useMemo } from "react";
import { NAVIGATOR_CONFIG } from "../../headless/children.native.js";
import { StackHeaderComponent, appendStackHeaderPropsToOptions } from "./StackHeaderComponent.native.js";
import { StackToolbar, appendStackToolbarPropsToOptions } from "./StackToolbar.native.js";
import { getStackToolbarImplementation } from "./StackToolbarImplementation.native.js";
import { Screen } from "../../views/Screen.native.js";
function StackScreen(param) {
var {
children,
options,
...rest
} = param;
var toolbarImplementation = getStackToolbarImplementation();
var updatedOptions = useMemo(function () {
return appendScreenStackPropsToOptions(options !== null && options !== void 0 ? options : {}, {
children
}, toolbarImplementation);
}, [options, children, toolbarImplementation]);
return /* @__PURE__ */jsx(Screen, {
...rest,
options: updatedOptions
});
}
Object.assign(StackScreen, {
[NAVIGATOR_CONFIG]: true
});
var NATIVE_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];
return validateStackPresentation(options(...args));
};
if (!options.presentation) return options;
if (options.presentation === "sheet") return {
...options,
presentation: "formSheet"
};
return NATIVE_PRESENTATIONS.includes(options.presentation) ? options : {
...options,
presentation: "modal"
};
}
function appendScreenStackPropsToOptions(options, props, toolbarImplementation) {
var 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 {
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