11// example/src/navigation/RootNavigator.tsx
22
3- import React from 'react' ;
3+ import React , { Suspense } from 'react' ;
4+ import { ActivityIndicator , View , StyleSheet } from 'react-native' ;
45import { createStackNavigator } from '@react-navigation/stack' ;
56import SelectionScreen from '../screens/SelectionScreen' ;
6- import HooksDemoNavigator from './HooksDemoNavigator' ;
7- import ClassDemoNavigator from './ClassDemoNavigator' ;
7+
8+ // Lazy load the demo navigators to prevent Auth0Provider from initializing
9+ // until the user actually navigates to those screens.
10+ const HooksDemoNavigator = React . lazy ( ( ) => import ( './HooksDemoNavigator' ) ) ;
11+ const ClassDemoNavigator = React . lazy ( ( ) => import ( './ClassDemoNavigator' ) ) ;
812
913// Define the parameter list for type safety
1014export type RootStackParamList = {
@@ -15,6 +19,13 @@ export type RootStackParamList = {
1519
1620const Stack = createStackNavigator < RootStackParamList > ( ) ;
1721
22+ // Loading fallback component
23+ const LoadingFallback = ( ) => (
24+ < View style = { styles . loadingContainer } >
25+ < ActivityIndicator size = "large" color = "#E53935" />
26+ </ View >
27+ ) ;
28+
1829/**
1930 * The top-level navigator that allows the user to select which
2031 * demo they want to see: the recommended Hooks-based approach or
@@ -33,16 +44,35 @@ const RootNavigator = () => {
3344 />
3445 < Stack . Screen
3546 name = "HooksDemo"
36- component = { HooksDemoNavigator }
3747 options = { { headerShown : false } } // The hooks demo will manage its own UI
38- />
48+ >
49+ { ( ) => (
50+ < Suspense fallback = { < LoadingFallback /> } >
51+ < HooksDemoNavigator />
52+ </ Suspense >
53+ ) }
54+ </ Stack . Screen >
3955 < Stack . Screen
4056 name = "ClassDemo"
41- component = { ClassDemoNavigator }
4257 options = { { headerShown : false } } // The class demo will manage its own UI
43- />
58+ >
59+ { ( ) => (
60+ < Suspense fallback = { < LoadingFallback /> } >
61+ < ClassDemoNavigator />
62+ </ Suspense >
63+ ) }
64+ </ Stack . Screen >
4465 </ Stack . Navigator >
4566 ) ;
4667} ;
4768
69+ const styles = StyleSheet . create ( {
70+ loadingContainer : {
71+ flex : 1 ,
72+ justifyContent : 'center' ,
73+ alignItems : 'center' ,
74+ backgroundColor : '#FFFFFF' ,
75+ } ,
76+ } ) ;
77+
4878export default RootNavigator ;
0 commit comments