2019-08-23 13:18:47 +00:00
|
|
|
import { analytics, leaveBreadcrumb } from './log';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
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) {
|
2019-08-23 13:18:47 +00:00
|
|
|
analytics().setCurrentScreen(currentScreen);
|
|
|
|
leaveBreadcrumb(currentScreen, { type: 'navigation' });
|
2019-07-18 17:44:02 +00:00
|
|
|
}
|
|
|
|
};
|