import { analytics, leaveBreadcrumb } from './log'; import { HEADER_BACKGROUND, HEADER_TITLE, HEADER_BACK } from '../constants/colors'; export const defaultHeader = { headerStyle: { backgroundColor: HEADER_BACKGROUND }, headerTitleStyle: { color: HEADER_TITLE }, headerBackTitle: null, headerTintColor: HEADER_BACK }; // gets the current screen from navigation state export const getActiveRouteName = (navigationState) => { if (!navigationState) { return null; } const route = navigationState.routes[navigationState.index]; // dive into nested navigators if (route.routes) { return getActiveRouteName(route); } return route.routeName; }; export const onNavigationStateChange = (prevState, currentState) => { const currentScreen = getActiveRouteName(currentState); const prevScreen = getActiveRouteName(prevState); if (prevScreen !== currentScreen) { analytics().setCurrentScreen(currentScreen); leaveBreadcrumb(currentScreen, { type: 'navigation' }); } };