one
Version:
One is a new React Framework that makes Vite serve both native and web.
80 lines • 2.65 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 TabRouter_exports = {};
__export(TabRouter_exports, {
ExpoTabRouter: () => ExpoTabRouter
});
module.exports = __toCommonJS(TabRouter_exports);
var import_native = require("@react-navigation/native");
function ExpoTabRouter(options) {
const rnTabRouter = (0, import_native.TabRouter)(options);
const router = {
...rnTabRouter,
getStateForAction(state, action, options2) {
if (action.type === "REPLACE") {
const payload = action.payload;
return router.getStateForAction(state, {
type: "JUMP_TO",
source: action.source,
target: action.target,
payload: {
name: payload?.name ?? "",
params: payload?.params
}
}, options2);
}
if (action.type !== "JUMP_TO") {
return rnTabRouter.getStateForAction(state, action, options2);
}
const route = state.routes.find(route2 => route2.name === action.payload.name);
if (!route) {
return null;
}
let shouldReset = !state.history.some(item => item.key === route?.key) && !route.state;
if (!shouldReset && "resetOnFocus" in action.payload && action.payload.resetOnFocus) {
shouldReset = state.routes[state.index].key !== route.key;
}
if (shouldReset) {
options2.routeParamList[route.name] = {
...options2.routeParamList[route.name]
};
state = {
...state,
routes: state.routes.map(r => {
if (r.key !== route.key) {
return r;
}
return {
...r,
state: void 0
};
})
};
return rnTabRouter.getStateForAction(state, action, options2);
} else {
return rnTabRouter.getStateForRouteFocus(state, route.key);
}
}
};
return router;
}