one
Version:
One is a new React Framework that makes Vite serve both native and web.
61 lines (60 loc) • 2.04 kB
JavaScript
import { TabRouter as RNTabRouter } from "@react-navigation/native";
function ExpoTabRouter(options) {
var rnTabRouter = RNTabRouter(options);
var router = {
...rnTabRouter,
getStateForAction(state, action, options2) {
if (action.type === "REPLACE") {
var _ref;
var payload = action.payload;
return router.getStateForAction(state, {
type: "JUMP_TO",
source: action.source,
target: action.target,
payload: {
name: (_ref = payload === null || payload === void 0 ? void 0 : payload.name) !== null && _ref !== void 0 ? _ref : "",
params: payload === null || payload === void 0 ? void 0 : payload.params
}
}, options2);
}
if (action.type !== "JUMP_TO") {
return rnTabRouter.getStateForAction(state, action, options2);
}
var route = state.routes.find(function (route2) {
return route2.name === action.payload.name;
});
if (!route) {
return null;
}
var shouldReset = !state.history.some(function (item) {
return item.key === (route === null || route === void 0 ? void 0 : 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(function (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;
}
export { ExpoTabRouter };
//# sourceMappingURL=TabRouter.native.js.map