one
Version:
One is a new React Framework that makes Vite serve both native and web.
96 lines (95 loc) • 3.26 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { BottomTabBar, createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import React, { useMemo } from "react";
import { Platform, Pressable } from "react-native";
import { Link } from "../link/Link.native.js";
import { Protected } from "../views/Protected.native.js";
import { getRenderingConfig } from "../router/renderingRegistry.native.js";
import { withLayoutContext } from "./withLayoutContext.native.js";
var DefaultTabBar = function (param) {
var {
state,
...restProps
} = param;
var filteredRoutes = state.routes.filter(function (r) {
return r.name !== "+not-found" && !r.name.startsWith("_sitemap");
});
return /* @__PURE__ */_jsx(BottomTabBar, {
state: {
...state,
routes: filteredRoutes
},
...restProps
});
};
var BottomTabNavigator = createBottomTabNavigator().Navigator;
var RNTabs = withLayoutContext(BottomTabNavigator, function (screens) {
return screens.map(function (screen) {
var _screen_options;
if (typeof screen.options !== "function" && ((_screen_options = screen.options) === null || _screen_options === void 0 ? void 0 : _screen_options.href) !== void 0) {
var {
href,
...options
} = screen.options;
if (options.tabBarButton) {
throw new Error("Cannot use `href` and `tabBarButton` together.");
}
return {
...screen,
options: {
...options,
tabBarButton: function (props) {
if (href == null) {
return null;
}
var children = Platform.OS === "web" ? props.children : /* @__PURE__ */_jsx(Pressable, {
children: props.children
});
return /* @__PURE__ */_jsx(Link, {
...props,
style: [{
display: "flex"
}, props.style],
href,
asChild: Platform.OS !== "web",
// biome-ignore lint/correctness/noChildrenProp: children prop needed for asChild pattern
children
});
}
}
};
}
return screen;
});
});
var TabsWithRender = /* @__PURE__ */React.forwardRef(function (props, ref) {
var {
render,
tabBar,
...rest
} = props;
var effectiveTabBar = useMemo(function () {
var _getRenderingConfig_Tabs;
if (tabBar) return tabBar;
var platform = Platform.OS;
var fromProp = render === null || render === void 0 ? void 0 : render[platform];
if (fromProp) return fromProp;
var fromGlobal = (_getRenderingConfig_Tabs = getRenderingConfig().Tabs) === null || _getRenderingConfig_Tabs === void 0 ? void 0 : _getRenderingConfig_Tabs[platform];
if (fromGlobal) return fromGlobal;
return DefaultTabBar;
}, [tabBar, render]);
return /* @__PURE__ */_jsx(RNTabs, {
...rest,
ref,
tabBar: effectiveTabBar
});
});
var Tabs = Object.assign(TabsWithRender, {
Protected,
// Preserve withLayoutContext's static Screen so user code like
// `<Tabs.Screen ... />` keeps working through the render wrapper.
Screen: RNTabs.Screen
});
var Tabs_default = Tabs;
export { Tabs, Tabs_default as default };
//# sourceMappingURL=Tabs.native.js.map