-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathApp.tsx
82 lines (76 loc) · 2.49 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
import * as React from "react";
import { SQLiteProvider } from "expo-sqlite/next";
import { ActivityIndicator, Platform, Text, View } from "react-native";
import * as FileSystem from "expo-file-system";
import { Asset } from "expo-asset";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NavigationContainer } from "@react-navigation/native";
import Home from "./screens/Home";
import Payment from "./screens/sheets/Payment";
const Stack = createNativeStackNavigator();
const loadDatabase = async () => {
const dbName = "mySQLiteDB.db";
const dbAsset = require("./assets/mySQLiteDB.db");
const dbUri = Asset.fromModule(dbAsset).uri;
const dbFilePath = `${FileSystem.documentDirectory}SQLite/${dbName}`;
const fileInfo = await FileSystem.getInfoAsync(dbFilePath);
if (!fileInfo.exists) {
await FileSystem.makeDirectoryAsync(
`${FileSystem.documentDirectory}SQLite`,
{ intermediates: true }
);
await FileSystem.downloadAsync(dbUri, dbFilePath);
}
};
export default function App() {
const [dbLoaded, setDbLoaded] = React.useState<boolean>(false);
React.useEffect(() => {
loadDatabase()
.then(() => setDbLoaded(true))
.catch((e) => console.error(e));
}, []);
if (!dbLoaded)
return (
<View style={{ flex: 1 }}>
<ActivityIndicator size={"large"} />
<Text>Loading Database...</Text>
</View>
);
return (
<NavigationContainer>
<React.Suspense
fallback={
<View style={{ flex: 1 }}>
<ActivityIndicator size={"large"} />
<Text>Loading Database...</Text>
</View>
}
>
<SQLiteProvider databaseName="mySQLiteDB.db" useSuspense>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{
headerTitle: "Budget Buddy",
headerLargeTitle: true,
headerTransparent: Platform.OS === "ios" ? true : false,
headerBlurEffect: "light",
}}
/>
<Stack.Screen
name="Payment"
component={Payment}
options={{
presentation: "transparentModal",
animation: "slide_from_bottom",
animationTypeForReplace: "pop",
headerShown: false,
}}
/>
</Stack.Navigator>
</SQLiteProvider>
</React.Suspense>
</NavigationContainer>
);
}