Browse Source

Add React Navigation 5 example

Janic Duplessis 4 years ago
parent
commit
0ccc32c5dc
5 changed files with 142 additions and 2 deletions
  1. 3
    0
      example/package.json
  2. 6
    0
      example/src/App.tsx
  3. 76
    0
      example/src/ReactNavigation5Example.tsx
  4. 3
    0
      package.json
  5. 54
    2
      yarn.lock

+ 3
- 0
example/package.json View File

@@ -3,6 +3,9 @@
3 3
   "dependencies": {
4 4
     "@react-native-community/async-storage": "^1.10.1",
5 5
     "@react-native-community/masked-view": "^0.1.10",
6
+    "@react-navigation/native": "^5.3.2",
7
+    "@react-navigation/stack": "^5.3.6",
8
+    "@react-navigation/bottom-tabs": "^5.4.4",
6 9
     "expo": "^37.0.8",
7 10
     "react": "^16.13.1",
8 11
     "react-dom": "^16.13.1",

+ 6
- 0
example/src/App.tsx View File

@@ -3,6 +3,7 @@ import * as React from 'react';
3 3
 import { DevSettings } from 'react-native';
4 4
 import AsyncStorage from '@react-native-community/async-storage';
5 5
 import ReactNavigation4Example from './ReactNavigation4Example';
6
+import ReactNavigation5Example from './ReactNavigation5Example';
6 7
 import SimpleExample from './SimpleExample';
7 8
 
8 9
 const STORAGE_KEY = 'rnsac-current-example';
@@ -36,6 +37,9 @@ export default function App() {
36 37
     DevSettings.addMenuItem('Show React Navigation 4 Example', () => {
37 38
       setCurrentExample('react-navigation-4');
38 39
     });
40
+    DevSettings.addMenuItem('Show React Navigation 5 Example', () => {
41
+      setCurrentExample('react-navigation-5');
42
+    });
39 43
   }, []);
40 44
 
41 45
   switch (currentExample) {
@@ -43,6 +47,8 @@ export default function App() {
43 47
       return <SimpleExample />;
44 48
     case 'react-navigation-4':
45 49
       return <ReactNavigation4Example />;
50
+    case 'react-navigation-5':
51
+      return <ReactNavigation5Example />;
46 52
     default:
47 53
       return null;
48 54
   }

+ 76
- 0
example/src/ReactNavigation5Example.tsx View File

@@ -0,0 +1,76 @@
1
+import * as React from 'react';
2
+import { Text, View, Button } from 'react-native';
3
+import { NavigationContainer } from '@react-navigation/native';
4
+import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
5
+import {
6
+  createStackNavigator,
7
+  StackScreenProps,
8
+} from '@react-navigation/stack';
9
+
10
+type Routes = {
11
+  Home: undefined;
12
+  Details: undefined;
13
+  Settings: undefined;
14
+};
15
+
16
+function HomeScreen({ navigation }: StackScreenProps<Routes, 'Home'>) {
17
+  return (
18
+    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
19
+      <Text>Home Screen</Text>
20
+      <Button
21
+        title="Go to Details"
22
+        onPress={() => navigation.navigate('Details')}
23
+      />
24
+    </View>
25
+  );
26
+}
27
+
28
+function SettingsScreen({ navigation }: StackScreenProps<Routes, 'Settings'>) {
29
+  return (
30
+    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
31
+      <Text>Settings Screen</Text>
32
+      <Button
33
+        title="Go to Details"
34
+        onPress={() => navigation.navigate('Details')}
35
+      />
36
+    </View>
37
+  );
38
+}
39
+
40
+const Tab = createBottomTabNavigator();
41
+
42
+function TabsScreen() {
43
+  return (
44
+    <Tab.Navigator>
45
+      <Tab.Screen name="Home" component={HomeScreen} />
46
+      <Tab.Screen name="Settings" component={SettingsScreen} />
47
+    </Tab.Navigator>
48
+  );
49
+}
50
+
51
+function DetailsScreen({ navigation }: StackScreenProps<Routes, 'Details'>) {
52
+  return (
53
+    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
54
+      <Text>Details Screen</Text>
55
+      <Button
56
+        title="Go to Details... again"
57
+        onPress={() => navigation.push('Details')}
58
+      />
59
+      <Button title="Go to Home" onPress={() => navigation.navigate('Home')} />
60
+      <Button title="Go back" onPress={() => navigation.goBack()} />
61
+    </View>
62
+  );
63
+}
64
+
65
+const Stack = createStackNavigator();
66
+
67
+export default function ReactNavigation5Example() {
68
+  return (
69
+    <NavigationContainer>
70
+      <Stack.Navigator>
71
+        <Stack.Screen name="Tabs" component={TabsScreen} />
72
+        <Stack.Screen name="Details" component={DetailsScreen} />
73
+      </Stack.Navigator>
74
+    </NavigationContainer>
75
+  );
76
+}

+ 3
- 0
package.json View File

@@ -50,6 +50,9 @@
50 50
     "@react-native-community/bob": "^0.10.1",
51 51
     "@react-native-community/eslint-config": "^1.1.0",
52 52
     "@react-native-community/masked-view": "^0.1.10",
53
+    "@react-navigation/native": "^5.3.2",
54
+    "@react-navigation/stack": "^5.3.6",
55
+    "@react-navigation/bottom-tabs": "^5.4.4",
53 56
     "@types/jest": "^25.2.1",
54 57
     "@types/react": "^16.9.34",
55 58
     "@types/react-native": "^0.62.5",

+ 54
- 2
yarn.lock View File

@@ -2321,6 +2321,14 @@
2321 2321
   resolved "https://registry.yarnpkg.com/@react-native-community/masked-view/-/masked-view-0.1.10.tgz#5dda643e19e587793bc2034dd9bf7398ad43d401"
2322 2322
   integrity sha512-rk4sWFsmtOw8oyx8SD3KSvawwaK7gRBSEIy2TAwURyGt+3TizssXP1r8nx3zY+R7v2vYYHXZ+k2/GULAT/bcaQ==
2323 2323
 
2324
+"@react-navigation/bottom-tabs@^5.4.4":
2325
+  version "5.4.4"
2326
+  resolved "https://registry.yarnpkg.com/@react-navigation/bottom-tabs/-/bottom-tabs-5.4.4.tgz#460680596701560eb1994ed3f97b5b887744a643"
2327
+  integrity sha512-U5VtzOWMMzrhNkoOlWDrWXA/N6YXaz1Diec2+sf9FP0tukUsnuMgj6rrheNqhJhc9Ntok3aZeIXbrzLmsv8NxA==
2328
+  dependencies:
2329
+    color "^3.1.2"
2330
+    react-native-iphone-x-helper "^1.2.1"
2331
+
2324 2332
 "@react-navigation/core@^3.7.6":
2325 2333
   version "3.7.6"
2326 2334
   resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-3.7.6.tgz#e0244fcdc22937825b252197f70308bbe5709c58"
@@ -2331,6 +2339,18 @@
2331 2339
     query-string "^6.11.1"
2332 2340
     react-is "^16.13.0"
2333 2341
 
2342
+"@react-navigation/core@^5.6.1":
2343
+  version "5.6.1"
2344
+  resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-5.6.1.tgz#c2951e56ef195027bfb4127d049aea5bd381fab1"
2345
+  integrity sha512-cnz3WMJd4Ou6TGLYmEfUijs0Wk+O0Vnlye29B2W2SJfTfqU1w4J8Kl0lzVkg8CZQruicQRzLU8ONVeDN4lj9tA==
2346
+  dependencies:
2347
+    "@react-navigation/routers" "^5.4.4"
2348
+    escape-string-regexp "^4.0.0"
2349
+    nanoid "^3.1.5"
2350
+    query-string "^6.12.1"
2351
+    react-is "^16.13.0"
2352
+    use-subscription "^1.4.0"
2353
+
2334 2354
 "@react-navigation/native@^3.7.13":
2335 2355
   version "3.7.13"
2336 2356
   resolved "https://registry.yarnpkg.com/@react-navigation/native/-/native-3.7.13.tgz#5fdf879d5af40fb5bf751b6d932dd30656c9991e"
@@ -2339,6 +2359,28 @@
2339 2359
     hoist-non-react-statics "^3.3.2"
2340 2360
     react-native-safe-area-view "^0.14.9"
2341 2361
 
2362
+"@react-navigation/native@^5.3.2":
2363
+  version "5.3.2"
2364
+  resolved "https://registry.yarnpkg.com/@react-navigation/native/-/native-5.3.2.tgz#31786ae160ab61ac609b2611306b728681016ada"
2365
+  integrity sha512-F9UzCHNjBQSQLv2RNc4q+Uo/3hRx00CIrP6CPBcrDxLe318frN/LHWqh7Dd6rRm7OAvDFYKsniEluLqTPK3Y0w==
2366
+  dependencies:
2367
+    "@react-navigation/core" "^5.6.1"
2368
+
2369
+"@react-navigation/routers@^5.4.4":
2370
+  version "5.4.4"
2371
+  resolved "https://registry.yarnpkg.com/@react-navigation/routers/-/routers-5.4.4.tgz#3b5e1a55edb73a506a82db59081ad434c0ce1aab"
2372
+  integrity sha512-Q8ZIubVYc1569JOs2oMWbhNXBNzZHvRfP5cEZ6/ksj9cPF7DkwOXsAdF0b+Oe0ei0f7OaK9LTRmfiNdtAPWVzw==
2373
+  dependencies:
2374
+    nanoid "^3.1.5"
2375
+
2376
+"@react-navigation/stack@^5.3.6":
2377
+  version "5.3.6"
2378
+  resolved "https://registry.yarnpkg.com/@react-navigation/stack/-/stack-5.3.6.tgz#7a1bf2f6b77dd92a0aa7befb4f3263215bed58f5"
2379
+  integrity sha512-6uE9pWMa9tdvDSbMV9o6/1cFrT60c2S3CTKIR5mZWJbyanIGFdu/ScbjIvplnG5kLG24rIpc3rtC0FgqTsBVXQ==
2380
+  dependencies:
2381
+    color "^3.1.2"
2382
+    react-native-iphone-x-helper "^1.2.1"
2383
+
2342 2384
 "@segment/loosely-validate-event@^2.0.0":
2343 2385
   version "2.0.0"
2344 2386
   resolved "https://registry.yarnpkg.com/@segment/loosely-validate-event/-/loosely-validate-event-2.0.0.tgz#87dfc979e5b4e7b82c5f1d8b722dfd5d77644681"
@@ -5908,6 +5950,11 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
5908 5950
   resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
5909 5951
   integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
5910 5952
 
5953
+escape-string-regexp@^4.0.0:
5954
+  version "4.0.0"
5955
+  resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
5956
+  integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
5957
+
5911 5958
 escodegen@^1.11.1:
5912 5959
   version "1.14.1"
5913 5960
   resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.1.tgz#ba01d0c8278b5e95a9a45350142026659027a457"
@@ -10487,6 +10534,11 @@ nan@^2.12.1, nan@^2.14.0:
10487 10534
   resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
10488 10535
   integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
10489 10536
 
10537
+nanoid@^3.1.5:
10538
+  version "3.1.7"
10539
+  resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.7.tgz#3705ccf590b6a51fbd1794fcf204ce7b5dc46c01"
10540
+  integrity sha512-ruOwuatdEf4BxQmZopZqhIMudQ9V83aKocr+q2Y7KasnDNvo2OgbgZBYago5hSD0tCmoSl4flIw9ytDLIVM2IQ==
10541
+
10490 10542
 nanomatch@^1.2.9:
10491 10543
   version "1.2.13"
10492 10544
   resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -12234,7 +12286,7 @@ query-string@^5.0.1:
12234 12286
     object-assign "^4.1.0"
12235 12287
     strict-uri-encode "^1.0.0"
12236 12288
 
12237
-query-string@^6.11.1:
12289
+query-string@^6.11.1, query-string@^6.12.1:
12238 12290
   version "6.12.1"
12239 12291
   resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.12.1.tgz#2ae4d272db4fba267141665374e49a1de09e8a7c"
12240 12292
   integrity sha512-OHj+zzfRMyj3rmo/6G8a5Ifvw3AleL/EbcHMD27YA31Q+cO5lfmQxECkImuNVjcskLcvBRVHNAB3w6udMs1eAA==
@@ -14823,7 +14875,7 @@ url@0.11.0, url@^0.11.0:
14823 14875
     punycode "1.3.2"
14824 14876
     querystring "0.2.0"
14825 14877
 
14826
-use-subscription@^1.0.0:
14878
+use-subscription@^1.0.0, use-subscription@^1.4.0:
14827 14879
   version "1.4.1"
14828 14880
   resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.4.1.tgz#edcbcc220f1adb2dd4fa0b2f61b6cc308e620069"
14829 14881
   integrity sha512-7+IIwDG/4JICrWHL/Q/ZPK5yozEnvRm6vHImu0LKwQlmWGKeiF7mbAenLlK/cTNXrTtXHU/SFASQHzB6+oSJMQ==