### Run Example App Source: https://reactnavigation.org/docs/contributing Command to start the example application using Expo for manual integration testing. ```bash yarn example start ``` -------------------------------- ### Clone and Setup Repository Source: https://reactnavigation.org/docs/contributing Initial commands to clone the repository, set up the upstream remote, and install dependencies. ```bash git clone https://github.com//react-navigation.git cd react-navigation git remote add upstream https://github.com/react-navigation/react-navigation.git yarn ``` -------------------------------- ### Navigating to a New Screen (Dynamic Setup) Source: https://reactnavigation.org/docs/navigating This snippet demonstrates navigation in a dynamic setup. The `useNavigation` hook is used to get the navigation object, which then allows navigation to other screens by their route name. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { useNavigation, NavigationContainer, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; function HomeScreen() { const navigation = useNavigation(); return ( Home Screen ); } // ... other code from the previous section function DetailsScreen() { return ( Details Screen ); } const Stack = createNativeStackNavigator(); function RootStack() { return ( ); } export default function App() { return ( ); } ``` -------------------------------- ### Define Root Navigator Structure Source: https://reactnavigation.org/docs/configuring-links Example of a root stack navigator setup. ```js function App() { return ( ); } ``` -------------------------------- ### Navigate to a screen with params (Static) Source: https://reactnavigation.org/docs/navigation-object Demonstrates navigating to a 'Profile' screen and passing parameters. This example uses a static navigator setup. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; import { useNavigation, createStaticNavigation, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; function HomeScreen() { const navigation = useNavigation(); return ( This is the home screen of the app ); } // codeblock-focus-start function ProfileScreen({ route }) { const navigation = useNavigation(); return ( Profile Screen Friends: {route.params.names[0]} {route.params.names[1]} {route.params.names[2]} // highlight-next-line ); } // codeblock-focus-end const Stack = createNativeStackNavigator({ initialRouteName: 'Home', screens: { Home: HomeScreen, Profile: ProfileScreen, }, }); const Navigation = createStaticNavigation(Stack); function App() { return ; } export default App; ``` -------------------------------- ### Dynamic Navigator Lifecycle Example Source: https://reactnavigation.org/docs/navigation-lifecycle Illustrates screen lifecycle with dynamic navigators. This setup is common for more flexible navigation flows. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { Button } from '@react-navigation/elements'; function SettingsScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('SettingsScreen mounted'); return () => console.log('SettingsScreen unmounted'); }, []); return ( Settings Screen ); } function ProfileScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('ProfileScreen mounted'); return () => console.log('ProfileScreen unmounted'); }, []); return ( Profile Screen ); } function ProfileScreen({ route }) { const navigation = useNavigation(); return ( Profile Screen Friends: {route.params.names[0]} {route.params.names[1]} {route.params.names[2]} ); } function SettingsScreen({ route }) { const navigation = useNavigation(); return ( Settings screen {route.params.someParam} ); } const Stack = createNativeStackNavigator(); function App() { return ( ); } export default App; ``` -------------------------------- ### Navigate to a screen with params (Dynamic) Source: https://reactnavigation.org/docs/navigation-object Demonstrates navigating to a 'Profile' screen and passing parameters. This example uses a dynamic navigator setup within NavigationContainer. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; function HomeScreen() { const navigation = useNavigation(); return ( This is the home screen of the app ); } // codeblock-focus-start function ProfileScreen({ route }) { const navigation = useNavigation(); return ( Profile Screen Friends: {route.params.names[0]} {route.params.names[1]} {route.params.names[2]} // highlight-next-line ); } // codeblock-focus-end const Stack = createNativeStackNavigator(); function App() { return ( ); } export default App; ``` -------------------------------- ### Example Deep Link Test with adb on Android Source: https://reactnavigation.org/docs/deep-linking An example of testing a deep link with `adb shell am start`, using `example://chat/jane` as the deep link and `com.simpleapp` as the package name. ```bash adb shell am start -W -a android.intent.action.VIEW -d "example://chat/jane" com.simpleapp ``` -------------------------------- ### Example Deep Link Test with adb for Expo Client Source: https://reactnavigation.org/docs/deep-linking This example shows how to test a deep link using `adb shell am start` specifically for the Expo client, using an `exp://` URI and the `host.exp.exponent` package name. ```bash adb shell am start -W -a android.intent.action.VIEW -d "exp://127.0.0.1:19000/--/chat/jane" host.exp.exponent ``` -------------------------------- ### Example Deep Link Test with xcrun on iOS Source: https://reactnavigation.org/docs/deep-linking An example demonstrating how to use `xcrun simctl openurl booted` to open a specific deep link, such as `example://chat/jane`, on the iOS simulator. ```bash xcrun simctl openurl booted "example://chat/jane" ``` -------------------------------- ### Install react-native-drawer-layout Source: https://reactnavigation.org/docs/drawer-layout Install the package using npm. ```bash npm install react-native-drawer-layout ``` -------------------------------- ### Install Screen and SafeAreaContext Dependencies (bun) Source: https://reactnavigation.org/docs/getting-started?config=static Install react-native-screens and react-native-safe-area-context using bun. ```bash bun add react-native-screens react-native-safe-area-context ``` -------------------------------- ### Install React Native Tab View Source: https://reactnavigation.org/docs/tab-view Install the core package using npm or yarn. ```bash npm install react-native-tab-view ``` -------------------------------- ### Install standard-navigation Source: https://reactnavigation.org/docs/standard-navigator Install the standard-navigation package as a dependency in your navigator library using npm or yarn. ```bash npm install standard-navigation ``` -------------------------------- ### Install Screen and SafeAreaContext Dependencies (npm) Source: https://reactnavigation.org/docs/getting-started?config=static Install react-native-screens and react-native-safe-area-context using npm. ```bash npm install react-native-screens react-native-safe-area-context ``` -------------------------------- ### Animate Element with Drawer Progress (Dynamic) Source: https://reactnavigation.org/docs/drawer-navigator Use `useDrawerProgress` to get the drawer's animation progress and animate elements. This example shows a dynamic setup. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { Button } from '@react-navigation/elements'; import { createDrawerNavigator, useDrawerProgress, } from '@react-navigation/drawer'; import Animated, { useAnimatedStyle } from 'react-native-reanimated'; function HomeScreen() { const progress = useDrawerProgress(); const animatedStyle = useAnimatedStyle(() => ({ transform: [{ translateX: progress.value * -100 }], })); return ( ); } const Drawer = createDrawerNavigator(); function MyDrawer() { return ( ); } export default function App() { return ( ); } ``` -------------------------------- ### Animate Element with Drawer Progress (Static) Source: https://reactnavigation.org/docs/drawer-navigator Use `useDrawerProgress` to get the drawer's animation progress and animate elements. This example shows a static setup. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { createStaticNavigation } from '@react-navigation/native'; import { Button } from '@react-navigation/elements'; import { createDrawerNavigator, useDrawerProgress, } from '@react-navigation/drawer'; import Animated, { useAnimatedStyle } from 'react-native-reanimated'; function HomeScreen() { const progress = useDrawerProgress(); const animatedStyle = useAnimatedStyle(() => ({ transform: [{ translateX: progress.value * -100 }], })); return ( ); } const MyDrawer = createDrawerNavigator({ screens: { Home: HomeScreen, }, }); const Navigation = createStaticNavigation(MyDrawer); export default function App() { return ; } ``` -------------------------------- ### Static Configuration API Example Source: https://reactnavigation.org/docs/upgrading-from-6.x Demonstrates the usage of the static configuration API for defining screens and their options. ```javascript import { createNativeStackNavigator } from '@react-navigation/native-stack'; const MyStack = createNativeStackNavigator({ screens: { Home: { screen: HomeScreen, options: { title: 'My App', }, }, Details: { screen: DetailsScreen, linking: 'details/:id', }, }, }); ``` -------------------------------- ### Dynamic Navigation Setup with goBack Source: https://reactnavigation.org/docs/navigation-actions Illustrates a dynamic navigation setup using `NavigationContainer`, `createStackNavigator`, and `useNavigation` hook, demonstrating the `goBack` action. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; import { useNavigation, CommonActions, NavigationContainer, } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; function HomeScreen() { const navigation = useNavigation(); return ( Home! ); } function ProfileScreen({ route }) { const navigation = useNavigation(); return ( Profile! {route.params.user}'s profile ); } const Stack = createStackNavigator(); function RootStack() { return ( ); } export default function App() { return ( ); } ``` -------------------------------- ### Static Navigation Setup with goBack Source: https://reactnavigation.org/docs/navigation-actions Demonstrates a static navigation setup using `createStaticNavigation` and `createStackNavigator` where the `goBack` action is dispatched from a screen. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; import { createStaticNavigation, useNavigation, CommonActions, } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; function HomeScreen() { const navigation = useNavigation(); return ( Home! ); } function ProfileScreen({ route }) { const navigation = useNavigation(); return ( Profile! {route.params.user}'s profile ); } const RootStack = createStackNavigator({ screens: { Home: HomeScreen, Profile: ProfileScreen, }, }); const Navigation = createStaticNavigation(RootStack); export default function App() { return ; } ``` -------------------------------- ### Static Navigator Lifecycle Example Source: https://reactnavigation.org/docs/navigation-lifecycle Demonstrates screen mounting and unmounting behavior with static navigators. Use this to observe lifecycle effects in a fixed navigation structure. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { createStaticNavigation, useNavigation, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { Button } from '@react-navigation/elements'; function SettingsScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('SettingsScreen mounted'); return () => console.log('SettingsScreen unmounted'); }, []); return ( Settings Screen ); } function ProfileScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('ProfileScreen mounted'); return () => console.log('ProfileScreen unmounted'); }, []); return ( Profile Screen ); } function HomeScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('HomeScreen mounted'); return () => console.log('HomeScreen unmounted'); }, []); return ( Home Screen ); } function DetailsScreen() { const navigation = useNavigation(); React.useEffect(() => { console.log('DetailsScreen mounted'); return () => console.log('DetailsScreen unmounted'); }, []); return ( Details Screen ); } // codeblock-focus-start const HomeStack = createNativeStackNavigator({ screens: { Home: HomeScreen, Details: DetailsScreen, }, }); const SettingsStack = createNativeStackNavigator({ screens: { Settings: SettingsScreen, Profile: ProfileScreen, }, }); const MyTabs = createBottomTabNavigator({ screenOptions: { headerShown: false, }, screens: { HomeStack: { screen: HomeStack, options: { tabBarLabel: 'Home' }, }, SettingsStack: { screen: SettingsStack, options: { tabBarLabel: 'Settings' }, }, }, }); // codeblock-focus-end const Navigation = createStaticNavigation(MyTabs); export default function App() { return ; } ``` -------------------------------- ### Static Navigation Setup for Shared Transitions Source: https://reactnavigation.org/docs/shared-element-transitions This snippet demonstrates a shared element transition using a static navigation setup. Ensure `react-native-reanimated` is installed and configured. The `sharedTransitionTag` prop must be identical for the animating elements across screens. ```javascript import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import { useNavigation, createStaticNavigation, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; import Animated from 'react-native-reanimated'; // codeblock-focus-start function HomeScreen() { const navigation = useNavigation(); return ( ); } function DetailsScreen() { const navigation = useNavigation(); return ( ); } // codeblock-focus-end const RootStack = createNativeStackNavigator({ screens: { Home: HomeScreen, Details: DetailsScreen, }, }); const Navigation = createStaticNavigation(RootStack); export default function App() { return ; } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', }, }); ``` -------------------------------- ### Install Native Stack Navigator with bun Source: https://reactnavigation.org/docs/hello-react-navigation?config=dynamic Use this command to install the native stack navigator library using bun. ```bash bun add @react-navigation/native-stack ``` -------------------------------- ### Static Navigator Setup Source: https://reactnavigation.org/docs/standard-navigator Demonstrates how consumers can set up a custom navigator using the static approach. This involves using `createStaticNavigation` with the custom navigator factory functions. ```tsx import { createStaticNavigation } from '@react-navigation/native'; import { createMyTabNavigator, createMyTabScreen, } from 'my-navigator/react-navigation'; const MyTabs = createMyTabNavigator({ screens: { Home: createMyTabScreen({ screen: HomeScreen, options: { title: 'Home' }, }), Feed: createMyTabScreen({ screen: FeedScreen, options: { title: 'Feed' }, }), }, }); const Navigation = createStaticNavigation(MyTabs); ``` -------------------------------- ### Dynamic Navigation Setup for Shared Transitions Source: https://reactnavigation.org/docs/shared-element-transitions This snippet illustrates a shared element transition using a dynamic navigation setup with `NavigationContainer`. Ensure `react-native-reanimated` is installed and configured. The `sharedTransitionTag` prop must be identical for the animating elements across screens. ```javascript import * as React from 'react'; import { View, StyleSheet } from 'react-native'; import { useNavigation, NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; import Animated from 'react-native-reanimated'; // codeblock-focus-start function HomeScreen() { const navigation = useNavigation(); return ( ); } function DetailsScreen() { const navigation = useNavigation(); return ( ); } // codeblock-focus-end const Stack = createNativeStackNavigator(); function RootStack() { return ( ); } export default function App() { return ( ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', }, }); ``` -------------------------------- ### Dynamic Multiple Drawer Navigators Example Source: https://reactnavigation.org/docs/multiple-drawers This example demonstrates how to set up and control multiple drawers (left and right) dynamically. It uses IDs to reference and open specific drawers from a screen. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { createDrawerNavigator } from '@react-navigation/drawer'; import { useNavigation, NavigationContainer } from '@react-navigation/native'; import { Button } from '@react-navigation/elements'; function HomeScreen() { const navigation = useNavigation(); return ( ); } function RightDrawerContent() { return ( This is the right drawer ); } const Drawer = createDrawerNavigator(); function LeftDrawerScreen() { return ( ); } const Drawer2 = createDrawerNavigator(); function RightDrawerScreen() { return ( } screenOptions={{ drawerPosition: 'right', headerShown: false, }} > ); } export default function App() { return ( ); } ``` -------------------------------- ### Install React Navigation Core Package (bun) Source: https://reactnavigation.org/docs/getting-started?config=static Install the core functionality of React Navigation using bun. ```bash bun add @react-navigation/native ``` -------------------------------- ### Navigate to a Tab using jumpTo (Dynamic) Source: https://reactnavigation.org/docs/bottom-tab-navigator Use `navigation.jumpTo` to navigate to an existing screen within the tab navigator. This example demonstrates dynamic navigation setup. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { useNavigation, NavigationContainer } from '@react-navigation/native'; import { Button } from '@react-navigation/elements'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; function HomeScreen() { const navigation = useNavigation(); return ( Home Screen ); } function ProfileScreen({ route }) { return ( Profile Screen {route.params?.owner && ( Owner: {route.params.owner} )} ); } const Tab = createBottomTabNavigator(); function MyTabs() { return ( ); } export default function App() { return ( ); } ``` -------------------------------- ### Dynamic Navigation with Navigate Function Source: https://reactnavigation.org/docs/navigating-without-navigation-prop Example of using a custom `navigate` function within a dynamic `NavigationContainer` setup. This enables navigation actions from any JavaScript module. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { NavigationContainer, createNavigationContainerRef, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; const navigationRef = createNavigationContainerRef(); function navigate(name, params) { if (navigationRef.isReady()) { navigationRef.navigate(name, params); } } // Example of usage in any of js modules //import * as RootNavigation from './path/to/RootNavigation.js'; // ... // RootNavigation.navigate('ChatScreen', { userName: 'Lucy' }); function Home() { return ( ); } function Settings({ route }) { return ( Hello {route.params.userName} ); } const RootStack = createNativeStackNavigator(); export default function App() { return ( ); } ``` -------------------------------- ### Static Navigation Setup Source: https://reactnavigation.org/docs/from-expo-router Creates a static navigation setup using the root stack navigator and defines the type for the root navigator. ```tsx import { createStaticNavigation } from '@react-navigation/native'; import { RootStack } from './RootStack'; const Navigation = createStaticNavigation(RootStack); export default function App() { return ; } type RootStackType = typeof RootStack; declare module '@react-navigation/native' { interface RootNavigator extends RootStackType {} } ``` -------------------------------- ### Update Params Dynamically Source: https://reactnavigation.org/docs/params Demonstrates updating screen parameters using `navigation.setParams` within a dynamically configured navigation setup. This example shows how to update an `itemId` parameter. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { useNavigation, NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; function HomeScreen({ route }) { const navigation = useNavigation(); const { itemId } = route.params; return ( Home Screen itemId: {JSON.stringify(itemId)} ); } const Stack = createNativeStackNavigator(); function RootStack() { return ( ); } export default function App() { return ( ); } ``` -------------------------------- ### Static Navigation with Navigate Function Source: https://reactnavigation.org/docs/navigating-without-navigation-prop Example of using a custom `navigate` function within a static navigation setup. This allows navigation actions to be triggered from any JavaScript module. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { createStaticNavigation, createNavigationContainerRef, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { Button } from '@react-navigation/elements'; const navigationRef = createNavigationContainerRef(); function navigate(name, params) { if (navigationRef.isReady()) { navigationRef.navigate(name, params); } } // Example of usage in any of js modules //import * as RootNavigation from './path/to/RootNavigation.js'; // ... // RootNavigation.navigate('ChatScreen', { userName: 'Lucy' }); function Home() { return ( ); } function Settings({ route }) { return ( Hello {route.params.userName} ); } const RootStack = createNativeStackNavigator({ screens: { Home: Home, Settings: Settings, }, }); const Navigation = createStaticNavigation(RootStack); export default function App() { return ; } ``` -------------------------------- ### React Navigation App Setup with Auth Flow Source: https://reactnavigation.org/docs/auth-flow?config=static This snippet demonstrates the main App component setup, including state management for authentication, token restoration using SecureStore, and providing authentication context to the navigation stack. It handles loading states and determines the initial screen based on the user's sign-in status. ```javascript import * as React from 'react'; import * as SecureStore from 'expo-secure-store'; export default function App() { const [state, dispatch] = React.useReducer( (prevState, action) => { switch (action.type) { case 'RESTORE_TOKEN': return { ...prevState, userToken: action.token, isLoading: false, }; case 'SIGN_IN': return { ...prevState, isSignout: false, userToken: action.token, }; case 'SIGN_OUT': return { ...prevState, isSignout: true, userToken: null, }; } }, { isLoading: true, isSignout: false, userToken: null, } ); React.useEffect(() => { const bootstrapAsync = async () => { let userToken; try { userToken = await SecureStore.getItemAsync('userToken'); } catch (e) { } dispatch({ type: 'RESTORE_TOKEN', token: userToken }); }; bootstrapAsync(); }, []); const authContext = React.useMemo( () => ({ signIn: async (data) => { dispatch({ type: 'SIGN_IN', token: 'dummy-auth-token' }); }, signOut: () => dispatch({ type: 'SIGN_OUT' }), signUp: async (data) => { dispatch({ type: 'SIGN_IN', token: 'dummy-auth-token' }); }, }), [] ); if (state.isLoading) { return ; } const isSignedIn = state.userToken != null; return ( ); } ``` -------------------------------- ### Listen to Focus and Blur Events (Static Navigation) Source: https://reactnavigation.org/docs/navigation-object Use `navigation.addListener` within a `useEffect` hook to subscribe to 'focus' and 'blur' events. This example demonstrates the setup for static navigation. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; import { useNavigation, createStaticNavigation, } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; function SettingsScreen() { const navigation = useNavigation(); return ( Settings Screen ); } // codeblock-focus-start function ProfileScreen() { const navigation = useNavigation(); React.useEffect( () => navigation.addListener('focus', () => alert('Screen was focused')), [navigation] ); React.useEffect( () => navigation.addListener('blur', () => alert('Screen was unfocused')), [navigation] ); return ( Profile Screen ); } // codeblock-focus-end const SettingsStack = createNativeStackNavigator({ screens: { Settings: SettingsScreen, Profile: ProfileScreen, }, }); const Navigation = createStaticNavigation(SettingsStack); export default function App() { return ; } ``` -------------------------------- ### Master-Detail Layout with Static Configuration Source: https://reactnavigation.org/docs/drawer-navigator This static configuration example sets up a master-detail layout by opening the drawer by default and styling it to take full width. ```javascript import { createDrawerNavigator } from '@react-navigation/drawer'; const MyDrawer = createDrawerNavigator({ defaultStatus: 'open', screenOptions: { drawerType: 'back', drawerStyle: { width: '100%' }, overlayColor: 'transparent', }, screens: { Home: HomeScreen, Profile: ProfileScreen, }, }); ``` -------------------------------- ### Static Stack Navigator Setup Source: https://reactnavigation.org/docs/stack-navigator Recommended for most use cases. This method uses `createStaticNavigation` for defining the navigator structure. ```javascript import * as React from 'react'; import { Text, View } from 'react-native'; import { createStaticNavigation, useNavigation } from '@react-navigation/native'; import { Button } from '@react-navigation/elements'; import { createStackNavigator } from '@react-navigation/stack'; function HomeScreen() { const navigation = useNavigation(); return ( Home Screen ); } function ProfileScreen() { return ( Profile Screen ); } const MyStack = createStackNavigator({ screens: { Home: HomeScreen, Profile: ProfileScreen, }, }); const Navigation = createStaticNavigation(MyStack); export default function App() { return ; } ``` -------------------------------- ### Preload Screen in Static Navigator Source: https://reactnavigation.org/docs/navigation-object Use `navigation.preload` to render a screen in the background before navigating to it. This example demonstrates preloading the 'Profile' screen with parameters in a static stack navigator setup. ```javascript import * as React from 'react'; import { View, Text } from 'react-native'; import { createStaticNavigation, useNavigation, CommonActions, } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import { Button } from '@react-navigation/elements'; // codeblock-focus-start function HomeScreen() { const navigation = useNavigation(); return ( Home! ); } // codeblock-focus-end function ProfileScreen({ route }) { const navigation = useNavigation(); const [startTime] = React.useState(Date.now()); const [endTime, setEndTime] = React.useState(null); React.useEffect(() => { const unsubscribe = navigation.addListener('focus', () => { setEndTime(Date.now()); }); return () => { unsubscribe(); }; }, [navigation]); return ( Profile! {route.params.user}'s profile Preloaded for: {endTime ? endTime - startTime : 'N/A'}ms ); } const Stack = createStackNavigator({ screens: { Home: HomeScreen, Profile: ProfileScreen, }, }); const Navigation = createStaticNavigation(Stack); export default function App() { return ; } ```