Skip to content

Commit f4db38e

Browse files
feat: remove Api screen and implement lazy loading for demo navigators with loading fallback
1 parent e9f0065 commit f4db38e

3 files changed

Lines changed: 37 additions & 73 deletions

File tree

example/src/navigation/MainTabNavigator.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import React from 'react';
44
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
55
import ProfileScreen from '../screens/hooks/Profile';
6-
import ApiScreen from '../screens/hooks/Api';
76
import MoreScreen from '../screens/hooks/More';
87
import CredentialsScreen from '../screens/hooks/CredentialsScreen';
98

@@ -34,7 +33,6 @@ const MainTabNavigator = () => {
3433
// You can add icons here if desired
3534
/>
3635
<Tab.Screen name="Credentials" component={CredentialsScreen} />
37-
<Tab.Screen name="Api" component={ApiScreen} />
3836
<Tab.Screen name="More" component={MoreScreen} />
3937
</Tab.Navigator>
4038
);

example/src/navigation/RootNavigator.tsx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
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';
45
import { createStackNavigator } from '@react-navigation/stack';
56
import 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
1014
export type RootStackParamList = {
@@ -15,6 +19,13 @@ export type RootStackParamList = {
1519

1620
const 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+
4878
export default RootNavigator;

example/src/screens/hooks/Api.tsx

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)