one
Version:
One is a new React Framework that makes Vite serve both native and web.
133 lines (131 loc) • 3.88 kB
JavaScript
;
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_exports = {};
__export(TabSlot_exports, {
TabSlot: () => TabSlot,
defaultTabsSlotRender: () => defaultTabsSlotRender,
isTabSlot: () => isTabSlot,
useTabSlot: () => useTabSlot
});
module.exports = __toCommonJS(TabSlot_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_react_native = require("react-native");
var import_react_native_screens = require("react-native-screens");
var import_Navigator = require("../views/Navigator.native.js");
var import_TabContext = require("./TabContext.native.js");
function useTabSlot() {
var {
detachInactiveScreens = ["android", "ios", "web"].includes(import_react_native.Platform.OS),
style,
renderFn = defaultTabsSlotRender
} = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
var {
state,
descriptorsRef
} = (0, import_Navigator.useNavigatorContext)();
var descriptors = descriptorsRef.current;
var focusedRouteKey = state.routes[state.index].key;
var [loaded, setLoaded] = (0, import_react.useState)({
[focusedRouteKey]: true
});
if (!loaded[focusedRouteKey]) {
setLoaded({
...loaded,
[focusedRouteKey]: true
});
}
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native_screens.ScreenContainer, {
enabled: detachInactiveScreens,
hasTwoStates: true,
style: [styles.screenContainer, style],
children: state.routes.map(function (route, index) {
var 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, param) {
var {
isFocused,
loaded,
detachInactiveScreens
} = param;
var {
lazy = true,
unmountOnBlur,
freezeOnBlur
} = descriptor.options;
if (unmountOnBlur && !isFocused) {
return null;
}
if (lazy && !loaded && !isFocused) {
return null;
}
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native_screens.Screen, {
enabled: detachInactiveScreens,
activityState: isFocused ? 2 : 0,
freezeOnBlur,
style: [styles.screen, isFocused ? styles.focused : styles.unfocused],
children: descriptor.render()
}, descriptor.route.key);
}
function isTabSlot(child) {
return child.type === TabSlot;
}
var styles = import_react_native.StyleSheet.create({
screen: {
flex: 1,
position: "relative",
height: "100%"
},
screenContainer: {
flexShrink: 0,
flexGrow: 1
},
focused: {
zIndex: 1,
display: "flex",
flexShrink: 0,
flexGrow: 1
},
unfocused: {
zIndex: -1,
display: "none",
flexShrink: 1,
flexGrow: 0
}
});
//# sourceMappingURL=TabSlot.native.js.map