1
+ import { enableScreens } from 'react-native-screens' ;
2
+ // run this before any screen render(usually in App.js)
3
+ enableScreens ( ) ;
4
+
1
5
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' ;
3
14
import { NavigationContainer , useNavigation } from '@react-navigation/native' ;
4
15
import { createStackNavigator } from '@react-navigation/stack' ;
5
16
import { BasicPagerViewExample } from './BasicPagerViewExample' ;
@@ -18,6 +29,8 @@ import CustomIndicatorExample from './tabView/CustomIndicatorExample';
18
29
import CustomTabBarExample from './tabView/CustomTabBarExample' ;
19
30
import CoverflowExample from './tabView/CoverflowExample' ;
20
31
import ReanimatedOnPageScrollExample from './ReanimatedOnPageScrollExample' ;
32
+ import NativeStackExample from './NativeStackExample' ;
33
+ import { createNativeStackNavigator } from '@react-navigation/native-stack' ;
21
34
22
35
const examples = [
23
36
{ component : BasicPagerViewExample , name : 'Basic Example' } ,
@@ -38,6 +51,10 @@ const examples = [
38
51
component : NestPagerView ,
39
52
name : 'Nest PagerView Example' ,
40
53
} ,
54
+ {
55
+ component : NativeStackExample ,
56
+ name : 'NativeStackExample' ,
57
+ } ,
41
58
{ component : ScrollableTabBarExample , name : 'ScrollableTabBarExample' } ,
42
59
{ component : AutoWidthTabBarExample , name : 'AutoWidthTabBarExample' } ,
43
60
{ component : TabBarIconExample , name : 'TabBarIconExample' } ,
@@ -72,19 +89,51 @@ function App() {
72
89
73
90
const Stack = createStackNavigator ( ) ;
74
91
92
+ const NativeStack = createNativeStackNavigator ( ) ;
93
+
75
94
export function Navigation ( ) {
95
+ const [ mode , setMode ] = React . useState < 'native' | 'js' > ( 'native' ) ;
96
+ const NavigationStack = mode === 'js' ? Stack : NativeStack ;
76
97
return (
77
98
< 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
+ />
80
129
{ examples . map ( ( example , index ) => (
81
- < Stack . Screen
130
+ < NavigationStack . Screen
82
131
key = { index }
83
132
name = { example . name }
84
133
component = { example . component }
85
134
/>
86
135
) ) }
87
- </ Stack . Navigator >
136
+ </ NavigationStack . Navigator >
88
137
</ NavigationContainer >
89
138
) ;
90
139
}
0 commit comments