one
Version:
One is a new React Framework that makes Vite serve both native and web.
72 lines (71 loc) • 3.06 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React, { Children, useMemo } from "react";
import { StackScreen, StackHeader, StackHeaderComponent, StackHeaderSearchBar, appendScreenStackPropsToOptions } from "./stack-utils";
import { withLayoutContext } from "./withLayoutContext.native.js";
import { isChildOfType } from "../utils/children.native.js";
import { Protected } from "../views/Protected.native.js";
import { Screen } from "../views/Screen.native.js";
var NativeStackNavigator = createNativeStackNavigator().Navigator,
RNStack = withLayoutContext(NativeStackNavigator);
function mapChildren(children) {
return Children.toArray(children).map(function (child, index) {
if (isChildOfType(child, StackScreen)) {
var _child_props_name,
options = appendScreenStackPropsToOptions({}, child.props),
{
children: _,
...rest
} = child.props;
return /* @__PURE__ */_jsx(Screen, {
...rest,
options
}, (_child_props_name = child.props.name) !== null && _child_props_name !== void 0 ? _child_props_name : index);
}
return isChildOfType(child, Protected) ? /* @__PURE__ */_jsx(Protected, {
guard: child.props.guard,
children: mapChildren(child.props.children)
}, `protected-${index}`) : isChildOfType(child, StackHeaderComponent) ? null : child;
}).filter(Boolean);
}
var StackWithComposition = /* @__PURE__ */React.forwardRef(function (props, ref) {
var {
children,
screenOptions,
...rest
} = props,
screenOptionsWithHeader = useMemo(function () {
var stackHeader = Children.toArray(children).find(function (child) {
return isChildOfType(child, StackHeaderComponent);
});
if (stackHeader && isChildOfType(stackHeader, StackHeaderComponent)) {
var headerProps = {
children: stackHeader
};
return screenOptions ? typeof screenOptions == "function" ? function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
var opts = screenOptions(...args);
return appendScreenStackPropsToOptions(opts, headerProps);
} : appendScreenStackPropsToOptions(screenOptions, headerProps) : appendScreenStackPropsToOptions({}, headerProps);
}
return screenOptions;
}, [children, screenOptions]),
processedChildren = useMemo(function () {
return mapChildren(children);
}, [children]);
return /* @__PURE__ */_jsx(RNStack, {
...rest,
ref,
screenOptions: screenOptionsWithHeader,
children: processedChildren
});
}),
Stack = Object.assign(StackWithComposition, {
Screen: StackScreen,
Header: StackHeader,
Protected,
SearchBar: StackHeaderSearchBar
}),
Stack_default = Stack;
export { Stack, Stack_default as default };
//# sourceMappingURL=Stack.native.js.map