one
Version:
One is a new React Framework that makes Vite serve both native and web.
95 lines (93 loc) • 4.05 kB
JavaScript
;
"use client";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var StackScreen_exports = {};
__export(StackScreen_exports, {
StackScreen: () => StackScreen,
appendScreenStackPropsToOptions: () => appendScreenStackPropsToOptions,
validateStackPresentation: () => validateStackPresentation
});
module.exports = __toCommonJS(StackScreen_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_children = require("../../headless/children.native.js");
var import_StackHeaderComponent = require("./StackHeaderComponent.native.js");
var import_StackToolbar = require("./StackToolbar.native.js");
var import_StackToolbarImplementation = require("./StackToolbarImplementation.native.js");
var import_Screen = require("../../views/Screen.native.js");
function StackScreen(param) {
var {
children,
options,
...rest
} = param;
var toolbarImplementation = (0, import_StackToolbarImplementation.getStackToolbarImplementation)();
var updatedOptions = (0, import_react.useMemo)(function () {
return appendScreenStackPropsToOptions(options !== null && options !== void 0 ? options : {}, {
children
}, toolbarImplementation);
}, [options, children, toolbarImplementation]);
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
...rest,
options: updatedOptions
});
}
Object.assign(StackScreen, {
[import_children.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 === import_StackHeaderComponent.StackHeaderComponent) return (0, import_StackHeaderComponent.appendStackHeaderPropsToOptions)(options2, child.props);else if (child.type === import_StackToolbar.StackToolbar) return (0, import_StackToolbar.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;
}
import_react.Children.forEach(props.children, function (child) {
if (/* @__PURE__ */(0, import_react.isValidElement)(child)) updatedOptions = appendChildOptions(child, updatedOptions);
});
return updatedOptions;
}
//# sourceMappingURL=StackScreen.native.js.map