@embrace-io/react-navigation
Version:
This is used to track React Native screens with the Embrace SDK
37 lines (36 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findNavigationHistory = void 0;
/**
* This method loops into the Navigation history state and returns the whole history sorted
* @param navigationState This Object is the current Navigation State
* @param historyName This array stores the founded active Screens
* @returns Returns an Array with the whole navigation History
*/
const findNavigationHistory = (navigationState, historyName = []) => {
if (!navigationState) {
return historyName;
}
const { state, name } = navigationState;
if (name) {
historyName.push({ name });
}
if (state) {
(0, exports.findNavigationHistory)(state, historyName);
}
else {
const { index, routes, type } = navigationState;
if (routes && routes.length > 0) {
if (type === "stack") {
routes.forEach(route => {
(0, exports.findNavigationHistory)(route, historyName);
});
}
else {
(0, exports.findNavigationHistory)(routes[index], historyName);
}
}
}
return historyName;
};
exports.findNavigationHistory = findNavigationHistory;