one
Version:
One is a new React Framework that makes Vite serve both native and web.
90 lines (89 loc) • 2.73 kB
JavaScript
import { BottomTabBar, createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import React, { useMemo } from "react";
import { Platform, Pressable } from "react-native-web";
import { Link } from "../link/Link.mjs";
import { Protected } from "../views/Protected.mjs";
import { getRenderingConfig } from "../router/renderingRegistry.mjs";
import { withLayoutContext } from "./withLayoutContext.mjs";
import { jsx } from "react/jsx-runtime";
const DefaultTabBar = ({
state,
...restProps
}) => {
const filteredRoutes = state.routes.filter(r => r.name !== "+not-found" && !r.name.startsWith("_sitemap"));
return /* @__PURE__ */jsx(BottomTabBar, {
state: {
...state,
routes: filteredRoutes
},
...restProps
});
};
const BottomTabNavigator = createBottomTabNavigator().Navigator;
const RNTabs = withLayoutContext(BottomTabNavigator, screens => {
return screens.map(screen => {
if (typeof screen.options !== "function" && screen.options?.href !== void 0) {
const {
href,
...options
} = screen.options;
if (options.tabBarButton) {
throw new Error("Cannot use `href` and `tabBarButton` together.");
}
return {
...screen,
options: {
...options,
tabBarButton: props => {
if (href == null) {
return null;
}
const 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",
children
});
}
}
};
}
return screen;
});
});
const TabsWithRender = React.forwardRef((props, ref) => {
const {
render,
tabBar,
...rest
} = props;
const effectiveTabBar = useMemo(() => {
if (tabBar) return tabBar;
const platform = Platform.OS;
const fromProp = render?.[platform];
if (fromProp) return fromProp;
const fromGlobal = getRenderingConfig().Tabs?.[platform];
if (fromGlobal) return fromGlobal;
return DefaultTabBar;
}, [tabBar, render]);
return /* @__PURE__ */jsx(RNTabs, {
...rest,
ref,
tabBar: effectiveTabBar
});
});
const 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.mjs.map