Skip to content

Commit

Permalink
Add navigationRef to Main Navigation Container
Browse files Browse the repository at this point in the history
  • Loading branch information
roycechua committed Jun 21, 2021
1 parent afb1c2d commit f655040
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/navigation/MainNavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useAppDispatch, useAppSelector } from '../redux/hooks';
import { useTheme } from 'react-native-paper';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { setLogout } from '../features/auth/authSlice';
import { isReadyRef, navigationRef } from './RootNavigation';

export type RootStackParamsList = {
SignIn: undefined;
Expand All @@ -29,9 +30,6 @@ const Stack = createStackNavigator();
const MainNavigationContainer: React.FC<Props> = (props: Props) => {
const { colors } = useTheme();

// to be replaced later by redux state variables
const [isSignout, setIsSignout] = useState(false);

const dispatch = useAppDispatch();
const isLoggedIn = useAppSelector((state) => state.auth.isLoggedIn);
const isAttemptingFetchConfiguration = useAppSelector(
Expand All @@ -50,7 +48,13 @@ const MainNavigationContainer: React.FC<Props> = (props: Props) => {
const handleLogout = () => dispatch(setLogout());

return (
<NavigationContainer>
<NavigationContainer
ref={navigationRef}
onReady={() => {
// @ts-ignore
isReadyRef.current = true;
}}
>
<Stack.Navigator>
{!isLoggedIn ? (
<>
Expand All @@ -60,11 +64,6 @@ const MainNavigationContainer: React.FC<Props> = (props: Props) => {
component={SignInScreen}
options={{
title: 'Sign In',
// When logging out, a pop animation feels intuitive
// You can remove this if you want the default 'push' animation
animationTypeForReplace: isSignout
? 'pop'
: 'push',
headerShown: false,
}}
/>
Expand Down Expand Up @@ -93,7 +92,7 @@ const MainNavigationContainer: React.FC<Props> = (props: Props) => {
},
headerRight: () => (
<TouchableOpacity onPress={handleLogout}>
<View style={{margin: 10}}>
<View style={{ margin: 10 }}>
<MaterialCommunityIcons
name='logout'
size={24}
Expand Down

0 comments on commit f655040

Please sign in to comment.