1+ import { enableScreens } from 'react-native-screens' ;
2+ // run this before any screen render(usually in App.js)
3+ enableScreens ( ) ;
4+
15import * 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' ;
314import { NavigationContainer , useNavigation } from '@react-navigation/native' ;
415import { createStackNavigator } from '@react-navigation/stack' ;
516import { BasicPagerViewExample } from './BasicPagerViewExample' ;
@@ -18,6 +29,8 @@ import CustomIndicatorExample from './tabView/CustomIndicatorExample';
1829import CustomTabBarExample from './tabView/CustomTabBarExample' ;
1930import CoverflowExample from './tabView/CoverflowExample' ;
2031import ReanimatedOnPageScrollExample from './ReanimatedOnPageScrollExample' ;
32+ import NativeStackExample from './NativeStackExample' ;
33+ import { createNativeStackNavigator } from '@react-navigation/native-stack' ;
2134
2235const 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
7390const Stack = createStackNavigator ( ) ;
7491
92+ const NativeStack = createNativeStackNavigator ( ) ;
93+
7594export 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}
0 commit comments