-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
96 lines (88 loc) · 2.49 KB
/
App.jsx
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
import React, { useEffect, useState } from "react"
import { StatusBar } from "expo-status-bar"
import { NavigationContainer } from "@react-navigation/native"
import { createNativeStackNavigator } from "@react-navigation/native-stack"
import AppLoading from "expo-app-loading"
import { useTheme, ThemeProvider } from "./src/constants/ThemeProvider"
import AllPlaces from "./src/screens/AllPlaces"
import AddPlace from "./src/screens/AddPlace"
import PlaceDetail from "./src/screens/PlaceDetail"
import Map from "./src/screens/Map"
import { init } from "./src/util/database"
import IconButton from "./src/components/ui/IconButton"
import ToggleButton from "./src/components/ui/ToggleButton"
import * as SplashScreen from "expo-splash-screen"
const Stack = createNativeStackNavigator()
SplashScreen.preventAutoHideAsync()
function MainApp() {
const [dbInitialized, setDbInitialized] = useState(false)
const { colors, isDarkTheme } = useTheme()
useEffect(() => {
async function initializeDatabase() {
try {
await init()
setDbInitialized(true)
console.log("Database initialized successfully")
} catch (err) {
console.error("Error initializing database:", err)
}
}
initializeDatabase()
}, [])
if (!dbInitialized) {
return <AppLoading />
}
if (!colors) {
console.error("Colors are undefined. Check your ThemeProvider setup.")
return null
}
return (
<>
<StatusBar style={isDarkTheme ? "light" : "dark"} />
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: colors.primary500 },
headerTintColor: colors.gray700,
contentStyle: { backgroundColor: colors.background },
}}>
<Stack.Screen
name="AllPlaces"
component={AllPlaces}
options={({ navigation }) => ({
headerLeft: () => <ToggleButton />,
headerRight: () => (
<IconButton
icon="airplane-plus"
size={28}
color={colors.gray700}
onPress={() => navigation.navigate("AddPlace")}
/>
),
})}
/>
<Stack.Screen
name="AddPlace"
component={AddPlace}
options={{
title: "Places I've been....",
}}
/>
<Stack.Screen name="Map" component={Map} />
<Stack.Screen
name="PlaceDetail"
component={PlaceDetail}
options={{ title: "Loading Place...ls" }}
/>
</Stack.Navigator>
</NavigationContainer>
</>
)
}
export default function App() {
return (
<ThemeProvider>
<MainApp />
</ThemeProvider>
)
}