This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathApp.tsx
128 lines (115 loc) · 3.24 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
import React, { useMemo } from "react";
import { View, Text, Button } from "react-native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import * as Linking from "expo-linking";
import {
NavigationContainer,
LinkingOptions,
useLinkTo,
NavigatorScreenParams,
} from "@react-navigation/native";
import {
createStackNavigator,
StackScreenProps,
} from "@react-navigation/stack";
type RootStackParamList = {
HomeStack: NavigatorScreenParams<HomeStackParamList>;
Settings: undefined;
};
type HomeStackParamList = {
Home: undefined;
Profile: {
id: string;
age?: number;
};
};
const prefix = Linking.createURL("/");
const linking: LinkingOptions<RootStackParamList> = {
prefixes: [prefix],
config: {
screens: {
HomeStack: {
path: "stack",
initialRouteName: "Home",
screens: {
Home: "home",
Profile: {
path: "user/:id/:age",
parse: {
id: (id) => `there, ${id}`,
age: Number,
},
stringify: {
id: (id) => id.replace("there, ", ""),
},
},
},
},
Settings: "settings",
},
},
};
type HomeProps = StackScreenProps<HomeStackParamList, "Home">;
const Home: React.FC<HomeProps> = ({ navigation }) => {
const linkTo = useLinkTo();
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Button
title="Go to Wojciech's profile"
onPress={() => linkTo("/stack/user/Wojciech/22")}
/>
<Button
title="Go to unknown profile"
onPress={() => navigation.navigate("Profile")}
/>
</View>
);
};
type ProfileProps = StackScreenProps<HomeStackParamList, "Profile">;
const Profile: React.FC<ProfileProps> = ({ route }) => {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Hello {route.params?.id || "Unknown"}!</Text>
<Text>
Type of age parameter is{" "}
{route.params?.age ? typeof route.params.age : "undefined"}
</Text>
</View>
);
};
type SettingsProps = StackScreenProps<RootStackParamList, "Settings">;
const Settings: React.FC<SettingsProps> = () => {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>This is the Settings Page.</Text>
</View>
);
};
type HomeStackProps = StackScreenProps<RootStackParamList, "HomeStack">;
const MyStack = createStackNavigator<HomeStackParamList>();
const HomeStack: React.FC<HomeStackProps> = () => {
return (
<MyStack.Navigator>
<MyStack.Screen name="Home" component={Home} />
<MyStack.Screen name="Profile" component={Profile} />
</MyStack.Navigator>
);
};
const MyTabs = createBottomTabNavigator<RootStackParamList>();
export default function App() {
const screenOptions = useMemo(
() => ({
headerShown: false,
tabBarIcon: () => null,
}),
[]
);
return (
<NavigationContainer linking={linking}>
<MyTabs.Navigator screenOptions={screenOptions}>
<MyTabs.Screen name="HomeStack" component={HomeStack} />
<MyTabs.Screen name="Settings" component={Settings} />
</MyTabs.Navigator>
</NavigationContainer>
);
}