This repository was archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathApp.tsx
More file actions
73 lines (64 loc) · 1.69 KB
/
App.tsx
File metadata and controls
73 lines (64 loc) · 1.69 KB
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
import React, { ComponentType } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import { useNavigation } from 'react-navigation-hooks';
import { createAppContainer } from 'react-navigation';
const Screen1 = () => (
<View style={{ flex: 1, width: '100%', backgroundColor: 'grey' }}>
<Text>Screen1</Text>
</View>
);
const Screen2 = () => (
<View style={{ flex: 1, width: '100%', backgroundColor: 'red' }}>
<Text>Screen1</Text>
</View>
);
const Screens: { [key: string]: ComponentType<any> } = {
Screen1,
Screen2,
};
const Home = () => {
const { navigate } = useNavigation();
return (
<View style={{ flex: 1, width: '100%', backgroundColor: 'grey' }}>
<Text>Home</Text>
{Object.keys(Screens).map(screenName => {
return (
<TouchableOpacity
onPress={() => navigate({ routeName: screenName })}
style={{
margin: 10,
padding: 10,
borderWidth: 1,
borderRadius: 5,
backgroundColor: 'blue',
}}
>
<Text style={{ color: 'black' }}>{screenName}</Text>
</TouchableOpacity>
);
})}
</View>
);
};
const ScreenRoutes = Object.keys(Screens).map(screenName => {
const Screen = Screens[screenName]!;
return {
screen: Screen,
navigationOptions: {
title: screenName,
},
};
}) as any;
const MainNavigator = createStackNavigator(
{
Home,
...ScreenRoutes,
},
{
headerMode: 'none',
mode: 'modal',
}
);
const AppContainer = createAppContainer(MainNavigator);
export default AppContainer;