-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
44 lines (38 loc) · 1.11 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, {useEffect, useRef, useState} from 'react';
import {
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import {MainNavigationStack, MainStack} from './MainStackNavigation';
import {AppHeader} from './AppHeader';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<SafeAreaProvider>
<NavWrapper />
</SafeAreaProvider>
);
};
export default App;
const NavWrapper = () => {
const navRef = useNavigationContainerRef<MainStack>();
const routeNameRef = useRef<string>();
const [ready, setIsReady] = useState(false);
return (
<>
{ready && <AppHeader navRef={navRef} />}
<NavigationContainer
ref={navRef}
onReady={() => {
setIsReady(true);
routeNameRef.current = navRef.current?.getCurrentRoute()?.name;
}}
onStateChange={async () => {
const currentRouteName = navRef.current?.getCurrentRoute()?.name;
routeNameRef.current = currentRouteName;
}}>
<MainNavigationStack />
</NavigationContainer>
</>
);
};