one
Version:
One is a React framework for web, iOS, and Android apps.
53 lines (50 loc) • 1.86 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { Activity, Fragment, useState } from "react";
import { useNavigatorContext } from "../views/Navigator.native.js";
import { TabContext } from "./TabContext.native.js";
function useTabSlot() {
var { detachInactiveScreens = true, renderFn = defaultTabsSlotRender } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
var { state, descriptorsRef } = useNavigatorContext();
var descriptors = descriptorsRef.current;
var focusedRouteKey = state.routes[state.index].key;
var [loaded, setLoaded] = useState({ [focusedRouteKey]: true });
if (!loaded[focusedRouteKey]) {
setLoaded({
...loaded,
[focusedRouteKey]: true
});
}
return /* @__PURE__ */ jsx(Fragment, { children: state.routes.map(function(route, index) {
var descriptor = descriptors[route.key];
return /* @__PURE__ */ jsx(TabContext.Provider, {
value: descriptor.options,
children: renderFn(descriptor, {
index,
isFocused: state.index === index,
loaded: loaded[route.key],
detachInactiveScreens
})
}, descriptor.route.key);
}) });
}
function TabSlot(props) {
return useTabSlot(props);
}
function defaultTabsSlotRender(descriptor, param) {
var { isFocused, loaded, detachInactiveScreens } = param;
var { lazy = true, unmountOnBlur } = descriptor.options;
if ((unmountOnBlur || detachInactiveScreens) && !isFocused) return null;
if (lazy && !loaded && !isFocused) return null;
if (!isFocused) {
return /* @__PURE__ */ jsx(Activity, {
mode: "hidden",
children: descriptor.render()
}, descriptor.route.key);
}
return /* @__PURE__ */ jsx(Fragment, { children: descriptor.render() }, descriptor.route.key);
}
function isTabSlot(child) {
return child.type === TabSlot;
}
export { TabSlot, defaultTabsSlotRender, isTabSlot, useTabSlot };
//# sourceMappingURL=TabSlot.native.js.map