Skip to content

Commit 2b3df4b

Browse files
author
Piotr Trocki
committed
chore: add native stack navigator
1 parent aec8bb4 commit 2b3df4b

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PODS:
185185
- React-cxxreact (= 0.63.4)
186186
- React-jsi (= 0.63.4)
187187
- React-jsinspector (0.63.4)
188-
- react-native-pager-view (5.4.11):
188+
- react-native-pager-view (5.4.15):
189189
- React-Core
190190
- react-native-safe-area-context (3.2.0):
191191
- React-Core
@@ -393,11 +393,11 @@ EXTERNAL SOURCES:
393393

394394
SPEC CHECKSUMS:
395395
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
396-
DoubleConversion: cde416483dac037923206447da6e1454df403714
396+
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
397397
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
398398
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
399399
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
400-
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
400+
glog: 476ee3e89abb49e07f822b48323c51c57124b572
401401
RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
402402
RCTTypeSafety: 8c9c544ecbf20337d069e4ae7fd9a377aadf504b
403403
React: b0a957a2c44da4113b0c4c9853d8387f8e64e615
@@ -408,7 +408,7 @@ SPEC CHECKSUMS:
408408
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
409409
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
410410
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
411-
react-native-pager-view: 7f00d63688f7df9fad86dfb0154814419cc5eb8d
411+
react-native-pager-view: b1914469643f40042e65d78cbf3d3dfebd6fb0d9
412412
react-native-safe-area-context: f0906bf8bc9835ac9a9d3f97e8bde2a997d8da79
413413
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
414414
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@react-native-community/masked-view": "^0.1.10",
2020
"@react-navigation/native": "^5.8.10",
21+
"@react-navigation/native-stack": "5.0.4",
2122
"@react-navigation/stack": "^5.12.8",
2223
"react": "16.13.1",
2324
"react-native": "0.63.4",

example/src/App.tsx

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import { enableScreens } from 'react-native-screens';
2+
// run this before any screen render(usually in App.js)
3+
enableScreens();
4+
15
import * as React from 'react';
2-
import { StyleSheet, Text, ScrollView, TouchableOpacity } from 'react-native';
6+
import {
7+
StyleSheet,
8+
Text,
9+
ScrollView,
10+
TouchableOpacity,
11+
Button,
12+
Alert,
13+
} from 'react-native';
314
import { NavigationContainer, useNavigation } from '@react-navigation/native';
415
import { createStackNavigator } from '@react-navigation/stack';
516
import { BasicPagerViewExample } from './BasicPagerViewExample';
@@ -18,6 +29,8 @@ import CustomIndicatorExample from './tabView/CustomIndicatorExample';
1829
import CustomTabBarExample from './tabView/CustomTabBarExample';
1930
import CoverflowExample from './tabView/CoverflowExample';
2031
import ReanimatedOnPageScrollExample from './ReanimatedOnPageScrollExample';
32+
import NativeStackExample from './NativeStackExample';
33+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
2134

2235
const examples = [
2336
{ component: BasicPagerViewExample, name: 'Basic Example' },
@@ -38,6 +51,10 @@ const examples = [
3851
component: NestPagerView,
3952
name: 'Nest PagerView Example',
4053
},
54+
{
55+
component: NativeStackExample,
56+
name: 'NativeStackExample',
57+
},
4158
{ component: ScrollableTabBarExample, name: 'ScrollableTabBarExample' },
4259
{ component: AutoWidthTabBarExample, name: 'AutoWidthTabBarExample' },
4360
{ component: TabBarIconExample, name: 'TabBarIconExample' },
@@ -72,19 +89,51 @@ function App() {
7289

7390
const Stack = createStackNavigator();
7491

92+
const NativeStack = createNativeStackNavigator();
93+
7594
export function Navigation() {
95+
const [mode, setMode] = React.useState<'native' | 'js'>('native');
96+
const NavigationStack = mode === 'js' ? Stack : NativeStack;
7697
return (
7798
<NavigationContainer>
78-
<Stack.Navigator initialRouteName="PagerView Example">
79-
<Stack.Screen name="PagerView Example" component={App} />
99+
<NavigationStack.Navigator initialRouteName="PagerView Example">
100+
<NavigationStack.Screen
101+
name="PagerView Example"
102+
component={App}
103+
options={{
104+
headerRight: () => (
105+
<Button
106+
onPress={() =>
107+
Alert.alert(
108+
'Alert',
109+
`Do you want to change to the ${
110+
mode === 'js' ? 'native stack' : 'js stack'
111+
} ?`,
112+
[
113+
{ text: 'No', onPress: () => {} },
114+
{
115+
text: 'Yes',
116+
onPress: () => {
117+
setMode(mode === 'js' ? 'native' : 'js');
118+
},
119+
},
120+
]
121+
)
122+
}
123+
title={mode === 'js' ? 'JS' : 'NATIVE'}
124+
color="orange"
125+
/>
126+
),
127+
}}
128+
/>
80129
{examples.map((example, index) => (
81-
<Stack.Screen
130+
<NavigationStack.Screen
82131
key={index}
83132
name={example.name}
84133
component={example.component}
85134
/>
86135
))}
87-
</Stack.Navigator>
136+
</NavigationStack.Navigator>
88137
</NavigationContainer>
89138
);
90139
}

example/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@
11281128
query-string "^6.13.6"
11291129
react-is "^16.13.0"
11301130

1131+
"@react-navigation/[email protected]":
1132+
version "5.0.4"
1133+
resolved "https://registry.yarnpkg.com/@react-navigation/native-stack/-/native-stack-5.0.4.tgz#1bf82c529390e7203d65635fc68164b2cbc4093f"
1134+
integrity sha512-i+5o0v582ZxTDrEDJcud5XI4BmzR+RAYAt592dnFgduO0lwIjch+IY5t+8PGg8n9FEN7dj+ivj1V5kx8ZggFQg==
1135+
11311136
"@react-navigation/native@^5.8.10":
11321137
version "5.9.3"
11331138
resolved "https://registry.yarnpkg.com/@react-navigation/native/-/native-5.9.3.tgz#3859f439adc9a744b79a98fbc7606bdd459574d5"

0 commit comments

Comments
 (0)