37 lines
935 B
JavaScript
37 lines
935 B
JavaScript
|
import firebase from 'react-native-firebase';
|
||
|
|
||
|
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) {
|
||
|
firebase.analytics().setCurrentScreen(currentScreen);
|
||
|
}
|
||
|
};
|