Rocket.Chat.ReactNative/app/utils/navigation.js

37 lines
935 B
JavaScript
Raw Normal View History

2019-07-18 17:44:02 +00:00
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);
}
};