one
Version:
One is a new React Framework that makes Vite serve both native and web.
121 lines • 5.4 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var Stack_exports = {};
__export(Stack_exports, {
Stack: () => Stack,
default: () => Stack_default
});
module.exports = __toCommonJS(Stack_exports);
var import_react = __toESM(require("react"), 1);
var import_children = require("../utils/children.cjs");
var import_Protected = require("../views/Protected.cjs");
var import_Screen = require("../views/Screen.cjs");
var import_stack_navigator = require("./stack-navigator.cjs");
var import_stack_utils = require("./stack-utils/index.cjs");
var import_withLayoutContext = require("./withLayoutContext.cjs");
var import_StackToolbarImplementation = require("./stack-utils/StackToolbarImplementation.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
const NativeStackNavigator = (0, import_stack_navigator.createStackNavigator)().Navigator;
const RNStack = (0, import_withLayoutContext.withLayoutContext)(NativeStackNavigator);
function mapChildren(children, toolbarImplementation) {
return import_react.Children.toArray(children).map((child, index) => {
if ((0, import_children.isChildOfType)(child, import_stack_utils.StackScreen)) {
const options = (0, import_stack_utils.appendScreenStackPropsToOptions)({}, child.props, toolbarImplementation);
const {
children: _,
...rest
} = child.props;
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
...rest,
options
}, child.props.name ?? index);
}
if ((0, import_children.isChildOfType)(child, import_Protected.Protected)) {
return import_react.default.cloneElement(child, {
key: `protected-${index}`
}, mapChildren(child.props.children, toolbarImplementation));
}
if ((0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent)) {
return null;
}
if ((0, import_children.isChildOfType)(child, import_Screen.Screen)) {
return child;
}
return null;
}).filter(Boolean);
}
const StackWithComposition = import_react.default.forwardRef((props, ref) => {
const {
children,
screenOptions,
...rest
} = props;
const toolbarImplementation = (0, import_StackToolbarImplementation.getStackToolbarImplementation)();
const screenOptionsWithHeader = (0, import_react.useMemo)(() => {
const stackHeader = import_react.Children.toArray(children).find(child => (0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent));
if (stackHeader && (0, import_children.isChildOfType)(stackHeader, import_stack_utils.StackHeaderComponent)) {
const headerProps = {
children: stackHeader
};
if (screenOptions) {
if (typeof screenOptions === "function") {
return (...args) => {
const opts = screenOptions(...args);
return (0, import_stack_utils.appendScreenStackPropsToOptions)(opts, headerProps, toolbarImplementation);
};
}
return (0, import_stack_utils.appendScreenStackPropsToOptions)(screenOptions, headerProps, toolbarImplementation);
}
return (0, import_stack_utils.appendScreenStackPropsToOptions)({}, headerProps, toolbarImplementation);
}
return screenOptions;
}, [children, screenOptions, toolbarImplementation]);
const processedChildren = (0, import_react.useMemo)(() => mapChildren(children, toolbarImplementation), [children, toolbarImplementation]);
const navigatorProps = (0, import_react.useMemo)(() => (0, import_stack_navigator.getStackNavigatorProps)(children), [children]);
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(RNStack, {
...rest,
...navigatorProps,
ref,
screenOptions: screenOptionsWithHeader,
children: processedChildren
});
});
const Stack = Object.assign(StackWithComposition, {
Screen: import_stack_utils.StackScreen,
Header: import_stack_utils.StackHeader,
Protected: import_Protected.Protected,
SearchBar: import_stack_utils.StackHeaderSearchBar,
Toolbar: import_stack_utils.StackToolbar
});
var Stack_default = Stack;