-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
156 lines (146 loc) · 3.94 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import AsyncStorage from '@react-native-community/async-storage'
import { createDrawerNavigator } from '@react-navigation/drawer'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import React, { useEffect, useState } from 'react'
import { Alert, StatusBar } from 'react-native'
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper'
import SplashScreen from 'react-native-splash-screen'
import { openDatabase } from 'react-native-sqlite-storage'
import AboutScreen from './screens/About'
import ExportScreen from './screens/Export'
import HomeScreen from './screens/Home'
import IntroScreen from './screens/Intro'
import SetPasswordScreen from './screens/SetPassword'
import SettingsScreen from './screens/Settings'
const db = openDatabase({
name: 'app.db',
location: 'default',
})
db.transaction((tx) => {
tx.executeSql(
`
CREATE TABLE IF NOT EXISTS credentials (
site TEXT,
password TEXT
)`,
[],
)
})
const theme = {
...DefaultTheme,
roundness: 20,
colors: {
...DefaultTheme.colors,
primary: '#444',
accent: '#f1c40f',
},
}
const Drawer = createDrawerNavigator()
const Stack = createStackNavigator()
const RootStack = createStackNavigator()
function drawerNavigator() {
return (
<Drawer.Navigator
initialRouteName="Home"
drawerType="slide"
screenOptions={{
headerStyle: {
backgroundColor: '#222',
},
headerTintColor: 'white',
headerShown: true,
}}
drawerStyle={{
backgroundColor: '#111',
width: 220,
}}
drawerContentOptions={{
activeTintColor: '#fff',
activeBackgroundColor: '#68f',
inactiveTintColor: 'grey',
}}
>
<Drawer.Screen
name="Home"
options={{
title: 'Generate Password',
drawerLabel: 'Home',
}}
component={HomeScreen}
/>
<Drawer.Screen name="Settings" component={settingsStack} />
<Drawer.Screen
name="Export"
component={ExportScreen}
options={{
title: 'Backup & Delete',
}}
/>
</Drawer.Navigator>
)
}
function settingsStack() {
return (
<Stack.Navigator
initialRouteName="SettingsScreen"
screenOptions={{
headerStyle: {
height: 40,
backgroundColor: '#efefef',
elevation: 0,
},
headerTitleStyle: { display: 'none' },
headerLeftContainerStyle: {
marginBottom: -20,
marginRight: 30,
},
}}
>
<Stack.Screen
name="SettingsScreen"
component={SettingsScreen}
options={{
headerShown: false,
headerLeftContainerStyle: { marginLeft: 50 },
}}
/>
<Stack.Screen name="SetMasterPassword" component={SetPasswordScreen} />
<Stack.Screen name="About" component={AboutScreen} />
</Stack.Navigator>
)
}
export default function App() {
const [defaultScreen, setDefaultScreen] = useState('Drawer')
const [isReady, setIsReady] = useState(false)
useEffect(() => {
AsyncStorage.getItem('@first_boot')
.then((value) => {
if (!value) setDefaultScreen('Intro')
setIsReady(true)
SplashScreen.hide()
})
.catch(() => {
Alert.alert('Error', 'Error launching the app.')
})
}, [isReady])
if (!isReady) {
return null
}
return (
<PaperProvider theme={theme}>
<StatusBar backgroundColor="black" barStyle="light-content" />
<NavigationContainer>
<RootStack.Navigator
initialRouteName={defaultScreen}
screenOptions={{
headerShown: false,
}}
>
<RootStack.Screen name="Drawer" component={drawerNavigator} />
<RootStack.Screen name="Intro" component={IntroScreen} />
</RootStack.Navigator>
</NavigationContainer>
</PaperProvider>
)
}