import React, { useContext, memo, useEffect } from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import { connect } from 'react-redux'; import { SetUsernameStackParamList, StackParamList } from './definitions/navigationTypes'; import Navigation from './lib/navigation/appNavigation'; import { defaultHeader, getActiveRouteName, navigationTheme } from './lib/methods/helpers/navigation'; import { RootEnum } from './definitions'; // Stacks import AuthLoadingView from './views/AuthLoadingView'; // SetUsername Stack import SetUsernameView from './views/SetUsernameView'; import OutsideStack from './stacks/OutsideStack'; import InsideStack from './stacks/InsideStack'; import MasterDetailStack from './stacks/MasterDetailStack'; import { ThemeContext } from './theme'; import { setCurrentScreen } from './lib/methods/helpers/log'; // SetUsernameStack const SetUsername = createStackNavigator(); const SetUsernameStack = () => ( ); // App const Stack = createStackNavigator(); const App = memo(({ root, isMasterDetail }: { root: string; isMasterDetail: boolean }) => { const { theme } = useContext(ThemeContext); useEffect(() => { if (root) { const state = Navigation.navigationRef.current?.getRootState(); const currentRouteName = getActiveRouteName(state); Navigation.routeNameRef.current = currentRouteName; setCurrentScreen(currentRouteName); } }, [root]); if (!root) { return null; } const navTheme = navigationTheme(theme); return ( { const previousRouteName = Navigation.routeNameRef.current; const currentRouteName = getActiveRouteName(state); if (previousRouteName !== currentRouteName) { setCurrentScreen(currentRouteName); } Navigation.routeNameRef.current = currentRouteName; }} > {root === RootEnum.ROOT_LOADING ? : null} {root === RootEnum.ROOT_OUTSIDE ? : null} {root === RootEnum.ROOT_INSIDE && isMasterDetail ? ( ) : null} {root === RootEnum.ROOT_INSIDE && !isMasterDetail ? : null} {root === RootEnum.ROOT_SET_USERNAME ? : null} ); }); const mapStateToProps = (state: any) => ({ root: state.app.root, isMasterDetail: state.app.isMasterDetail }); const AppContainer = connect(mapStateToProps)(App); export default AppContainer;