UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

95 lines 3.03 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var TabSlot_web_exports = {}; __export(TabSlot_web_exports, { TabSlot: () => TabSlot, defaultTabsSlotRender: () => defaultTabsSlotRender, isTabSlot: () => isTabSlot, useTabSlot: () => useTabSlot }); module.exports = __toCommonJS(TabSlot_web_exports); var import_react = require("react"); var import_Navigator = require("../views/Navigator.cjs"); var import_TabContext = require("./TabContext.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function useTabSlot({ detachInactiveScreens = true, renderFn = defaultTabsSlotRender } = {}) { const { state, descriptorsRef } = (0, import_Navigator.useNavigatorContext)(); const descriptors = descriptorsRef.current; const focusedRouteKey = state.routes[state.index].key; const [loaded, setLoaded] = (0, import_react.useState)({ [focusedRouteKey]: true }); if (!loaded[focusedRouteKey]) { setLoaded({ ...loaded, [focusedRouteKey]: true }); } return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.Fragment, { children: state.routes.map((route, index) => { const descriptor = descriptors[route.key]; return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_TabContext.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, { isFocused, loaded, detachInactiveScreens }) { const { lazy = true, unmountOnBlur } = descriptor.options; if ((unmountOnBlur || detachInactiveScreens) && !isFocused) return null; if (lazy && !loaded && !isFocused) return null; if (!isFocused) { return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.Activity, { mode: "hidden", children: descriptor.render() }, descriptor.route.key); } return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.Fragment, { children: descriptor.render() }, descriptor.route.key); } function isTabSlot(child) { return child.type === TabSlot; }