Fakultas Ilmu Komputer UI

index.tsx 1.57 KB
Newer Older
Wulan Mantiri's avatar
Wulan Mantiri committed
1
import React, { FC, useContext } from 'react';
2
3
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
4
import { ThemeProvider } from 'react-native-elements';
5
import Toast from 'react-native-toast-message';
6

Wulan Mantiri's avatar
Wulan Mantiri committed
7
import ContextProvider, { UserContext } from 'provider';
8
import { theme } from 'styles/theme';
9

10
import { screenOptions, toastConfig } from './styles';
11
import LogoutButton from './LogoutButton';
Wulan Mantiri's avatar
Wulan Mantiri committed
12
import { getNavigation } from './schema';
13

14
15
const Stack = createStackNavigator();

Wulan Mantiri's avatar
Wulan Mantiri committed
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
45
46
47
const NavigationStack: FC = () => {
  const { isAuthenticated, isUnpaidClient } = useContext(UserContext);

  const { initialRoute, navigation } = getNavigation(
    isAuthenticated,
    isUnpaidClient,
  );

  return (
    <NavigationContainer>
      <Stack.Navigator
        initialRouteName={initialRoute}
        screenOptions={screenOptions}>
        <>
          {navigation.map((nav, i) => (
            <Stack.Screen
              key={`nav${i}`}
              name={nav.name}
              component={nav.component}
              options={{
                title: nav.header,
                headerShown: Boolean(nav.header),
                headerRight: LogoutButton,
              }}
            />
          ))}
        </>
      </Stack.Navigator>
    </NavigationContainer>
  );
};

48
49
const App: FC = () => {
  return (
Wulan Mantiri's avatar
Wulan Mantiri committed
50
    <ThemeProvider theme={theme}>
51
      <ContextProvider>
Wulan Mantiri's avatar
Wulan Mantiri committed
52
        <NavigationStack />
53
54
        <Toast config={toastConfig} ref={Toast.setRef} />
      </ContextProvider>
Wulan Mantiri's avatar
Wulan Mantiri committed
55
    </ThemeProvider>
56
57
58
59
  );
};

export default App;