-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
68 lines (58 loc) · 2.46 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
import { NavigationContainer, NavigationProp, useNavigation } from '@react-navigation/native';
import { NativeStackScreenProps, createNativeStackNavigator } from '@react-navigation/native-stack';
import Home from './app/screens/Home';
import NewProduct from './app/screens/NewProduct';
import Product from './app/screens/Product';
import { TouchableOpacity } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useState } from 'react';
import { Asset } from 'expo-asset';
import * as FileSystem from 'expo-file-system';
// Define Stack on TypeScript
type RootStackParamList = {
Products: undefined;
Modal: undefined;
Details: {
id: string;
};
};
const RootStack = createNativeStackNavigator<RootStackParamList>();
// Although it was working without the type definition, we define this for TypeScript
export type StackNavigation = NavigationProp<RootStackParamList>;
export type ProductsPageProps = NativeStackScreenProps<RootStackParamList, 'Products'>;
export type ModalPageProps = NativeStackScreenProps<RootStackParamList, 'Modal'>;
export type DetailsPageProps = NativeStackScreenProps<RootStackParamList, 'Details'>;
const RootStackNavigation = () => {
const navigation = useNavigation<StackNavigation>();
return (
<RootStack.Navigator>
<RootStack.Screen name="Products"
component={Home}
options={{
headerRight: () => (
<TouchableOpacity onPress={() => navigation.navigate('Modal')}>
<Ionicons name="add" size={24} color="black" />
</TouchableOpacity>
),
}}
/>
<RootStack.Screen name="Modal" component={NewProduct}
options={{ presentation: 'modal' }} />
<RootStack.Screen name="Details" component={Product} />
</RootStack.Navigator>
)
}
export default function App() {
const [isReady, setIsReady] = useState(true);
// FileSystem.deleteAsync(FileSystem.documentDirectory + 'SQLite/store.db');
// const openDatabase = async () => {
// if (!(await FileSystem.getInfoAsync(FileSystem.documentDirectory + 'SQLite')).exists) {
// await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'SQLite');
// }
// const asset = Asset.fromModule(require('./assets/store.db'));
// await FileSystem.downloadAsync(asset.uri, FileSystem.documentDirectory + 'SQLite/store.db');
// setIsReady(true);
// };
// openDatabase();
return <NavigationContainer>{isReady ? <RootStackNavigation /> : <></>}</NavigationContainer>;
}