2022-04-11 18:01:43 +00:00
|
|
|
import React, { useContext, memo, useEffect } from 'react';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
|
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2023-08-18 17:48:33 +00:00
|
|
|
import { SetUsernameStackParamList, StackParamList } from './definitions/navigationTypes';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from './lib/navigation/appNavigation';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { defaultHeader, getActiveRouteName, navigationTheme } from './lib/methods/helpers/navigation';
|
2022-02-02 18:27:10 +00:00
|
|
|
import { RootEnum } from './definitions';
|
2023-08-18 17:48:33 +00:00
|
|
|
// Stacks
|
2020-06-15 14:00:46 +00:00
|
|
|
import AuthLoadingView from './views/AuthLoadingView';
|
2023-08-18 17:48:33 +00:00
|
|
|
// SetUsername Stack
|
2020-06-15 14:00:46 +00:00
|
|
|
import SetUsernameView from './views/SetUsernameView';
|
|
|
|
import OutsideStack from './stacks/OutsideStack';
|
|
|
|
import InsideStack from './stacks/InsideStack';
|
|
|
|
import MasterDetailStack from './stacks/MasterDetailStack';
|
|
|
|
import { ThemeContext } from './theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { setCurrentScreen } from './lib/methods/helpers/log';
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
// SetUsernameStack
|
2021-12-03 19:27:57 +00:00
|
|
|
const SetUsername = createStackNavigator<SetUsernameStackParamList>();
|
2020-06-15 14:00:46 +00:00
|
|
|
const SetUsernameStack = () => (
|
|
|
|
<SetUsername.Navigator screenOptions={defaultHeader}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<SetUsername.Screen name='SetUsernameView' component={SetUsernameView} />
|
2020-06-15 14:00:46 +00:00
|
|
|
</SetUsername.Navigator>
|
|
|
|
);
|
|
|
|
|
|
|
|
// App
|
2021-12-03 19:27:57 +00:00
|
|
|
const Stack = createStackNavigator<StackParamList>();
|
2022-04-11 18:01:43 +00:00
|
|
|
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]);
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
if (!root) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const navTheme = navigationTheme(theme);
|
|
|
|
|
|
|
|
return (
|
2020-06-16 20:32:30 +00:00
|
|
|
<NavigationContainer
|
|
|
|
theme={navTheme}
|
|
|
|
ref={Navigation.navigationRef}
|
2021-09-13 20:41:05 +00:00
|
|
|
onStateChange={state => {
|
2020-06-16 20:32:30 +00:00
|
|
|
const previousRouteName = Navigation.routeNameRef.current;
|
|
|
|
const currentRouteName = getActiveRouteName(state);
|
|
|
|
if (previousRouteName !== currentRouteName) {
|
|
|
|
setCurrentScreen(currentRouteName);
|
|
|
|
}
|
|
|
|
Navigation.routeNameRef.current = currentRouteName;
|
2022-08-08 21:02:08 +00:00
|
|
|
}}
|
|
|
|
>
|
2020-06-16 20:32:30 +00:00
|
|
|
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
2024-01-25 14:11:07 +00:00
|
|
|
{root === RootEnum.ROOT_LOADING ? <Stack.Screen name='AuthLoading' component={AuthLoadingView} /> : null}
|
|
|
|
{root === RootEnum.ROOT_OUTSIDE ? <Stack.Screen name='OutsideStack' component={OutsideStack} /> : null}
|
|
|
|
{root === RootEnum.ROOT_INSIDE && isMasterDetail ? (
|
|
|
|
<Stack.Screen name='MasterDetailStack' component={MasterDetailStack} />
|
|
|
|
) : null}
|
|
|
|
{root === RootEnum.ROOT_INSIDE && !isMasterDetail ? <Stack.Screen name='InsideStack' component={InsideStack} /> : null}
|
|
|
|
{root === RootEnum.ROOT_SET_USERNAME ? <Stack.Screen name='SetUsernameStack' component={SetUsernameStack} /> : null}
|
2020-06-16 20:32:30 +00:00
|
|
|
</Stack.Navigator>
|
|
|
|
</NavigationContainer>
|
2020-06-15 14:00:46 +00:00
|
|
|
);
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
const mapStateToProps = (state: any) => ({
|
2020-06-15 14:00:46 +00:00
|
|
|
root: state.app.root,
|
|
|
|
isMasterDetail: state.app.isMasterDetail
|
|
|
|
});
|
|
|
|
|
|
|
|
const AppContainer = connect(mapStateToProps)(App);
|
|
|
|
export default AppContainer;
|