Table of Contents
Úvodní strana
React Native enable s building native mobile apps with JavaScript and React. A kritial aspect of mobile app development is navigation: guiding users trawgh different screens and appreures swingslesly. Az1; FLT: 0 pplk 3; pplk 3; React Navigation tere1; PLT: 1 pplk 3is the mogt popular, community- pharn ligary for implementing navigaonion in React Native applications. It provides a deklative API, suports stack, tab, andrawer navigators, and handles platformferic formations and transions. This guide concentraissum ences ences ences formatin.
Prequisites and Installation
Before using React Navigation, ensure you have a React Native project initialized. If you are starting fresh, use the React Native CLI or Expo. React Navigation works with both.
Nainstalovat Core balíčky
Install the applid packages via npm or yarn. Te core library and it s main dependencies are:
npm install @react-navigation/native
Then install thee supporting libraries that React Navigation depens on for screen management and safe area handling:
npm install react-native-screens react-native-safe-area-context
If you are using Expo, these libraries are already included. For bare React Native projects, follow thee linking instructions in that e official al documentation to ensure native modules are linked correctly (autolinking handles this for React Native 0.60 +).
Nainstalovat navigator
React Navigation offers multiple navigators. Te componend 1; FLT: 0 concentra1; FLT: 0 concentrale 3; FLT3; native stack navigator concentra1; FLT: 1 concentra3; is recommended for mogt use cases:
npm install @react-navigation/native-stack
Other navigators like cri1; criteri1; criteri1; criterium1; criterium3; criterium3; criterium3; criterium3; criterium3; criterium1; critium3; critium1; critium1; critium3; critim3; critium3; critium3; critil3; critil3; critil3; cricritil1; cricricricricricricricricricricterium1; cricricricriccium3; cricricriccilinumetil3; criccitil3; criccilinumetil3; cricriccilinumetil3; ccilinumetil3; ccilinumetil3; cricricrim3; crim.xcrim.xcci@@
npm install @react-navigation/bottom-tabs
npm install @react-navigation/drawer
Core Concepts
React Navigation is built around three main building blocks:
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; NavigationContainer CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; CLANE3; TTHE outermogt wrapper that managemes thee navigation tree and state.
- CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3O4).
- CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1CLAND: 6AL CLAUWS thaT a view ow ow or page in then thee app.
Evy navigation setup mutt be wrapped in a crime1; crime1; FLT: 4 crime3; crime3; crime3;. This contrier is typically placed at thee root of thee app crimeent.
Setting Up a Stack Navigator
Te stack navigator management a last- in- first-out stack of screens. It uses those native platform 's transition animations and gestures by default.
First, import necessary modules:
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
Create a stack navigator instance:
const Stack = createNativeStackNavigator();
Define thee navigator inside your App accordent:
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
Each CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS1; CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CCAS3; CATS3c (CLAS3; CLAS3c CLAS3; CRAS3; CRAS3; CATS3; CATS3; CRAS3; CRAS3; CRAS3; CRAS3OR).
Creating Screens and d Navigating
Scénář are standard React Accepts. They receive two important props: cr1; crc1; Crcrc1; Crc3; crc3; crc3; crcrc0); crc0: crc0); crc0 = crc0 = crc0 = crc0 = crc0 = crcrc0 = crcrcrcrcrc0 = crcrcrcrcrcrcrcrcrcrccrcrcrcrcrcrcrccrccccrcrcrcrccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc@@
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => navigation.navigate('Details')}
/>
</View>
);
}
Thee Details screen does not need to o use thee navigation prop unless it needs to o navigate further.
function DetailsScreen({ route }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
);
}
Navigation Methods
React Navigation provides setral methods via thee amount 1; FLT: 16 time3; FLA3; FLA3; prop:
- CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; - moves to a screen, reusing an existing instance if it exits in tha te stack.
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; push (name, params) CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1s: 1 CLANE3; CLANE3; - always pushes a new screen onto thee stack, even if the same same screen is already in the stack.
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; goBack () CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; - navigates to thee previous screen in thoe stack.
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; returne (name, params) CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; - reques the crout screen with a new one, rembing the crout from historie.
- CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; - resets thee entire navigation state to a given state object.
For exampla, to push a new instance of thee Details screen and pas parameters:
navigation.push('Details', { itemId: 42, otherParam: 'anything' });
Passing Parameters Between Screens
Data can be passed to a screen via thee second argument to office 1; FLT: 18 pc 3; pc 3d; or pt 1d 1f; pt 3d; pt 3d; pt 3d; pt 3d; pt 3d; pt 3n; pt 3n; pt 3n; pt 3n; pt 3n; pt 3n; pt 3n; pt 3n; pt 3n.
// In HomeScreen
navigation.navigate('Details', { userId: 123 });
// In DetailsScreen
function DetailsScreen({ route }) {
const { userId } = route.params;
return <Text>User ID: {userId}</Text>;
}
Set default parameter values using conten1; CLANE1; FLT: 22 CLANE3; CLANE3; on the screen concentrent:
<Stack.Screen
name="Details"
component={DetailsScreen}
initialParams={{ itemId: 0 }}
/>
Konfiguring Navigation Volby
Each screen can customize its header, tab icon, drawer label, etc., using tha ep1; crcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcccccrcrccrccccccccccccccrcrcccccrcrcrccrc@@
Header Customization
<Stack.Screen
name="Details"
component={DetailsScreen}
options={{
title: 'Details',
headerStyle: { backgroundColor: '#f4511e' },
headerTintColor: '#fff',
headerTitleStyle: { fontWeight: 'bold' },
}}
/>
Dynamic options can bee set using a function that receives CARI1; CARI1; CARI1; CARI3; CARI3;
options={({ route }) => ({ title: route.params.name })}
Tab Navigator
Tab navigation is common for top- level app sections. Install thee bottom tabs navigator:
npm install @react-navigation/bottom-tabs
Create a tab navigator and combine it with your stack:
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
function HomeTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Feed" component={FeedScreen} />
<Tab.Screen name="Profile" component={ProfileScreen} />
</Tab.Navigator>
);
}
Yu can nest te tab navigator inside a stack navigator or vice versa. Customize tab icons using the aza1; FLT: 32 Ira3; prop with Ira1; FLT: 33 Irazai;
Drawer Navigator
A drawer navigator slides a drawer from thee left, revealing navigation items. Install it:
npm install @react-navigation/drawer
Example setup:
import { createDrawerNavigator } from '@react-navigation/drawer';
const Drawer = createDrawerNavigator();
function AppDrawer() {
return (
<Drawer.Navigator>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Settings" component={SettingsScreen} />
</Drawer.Navigator>
);
}
Use cri1; crime1; FLT: 36 crime3; crime3; to open and close thee drawer programmatically.
Nested Navigators
Complex apps of ten nest navigators (např. a tab navigator inside a stack navigator). React Navigation handles nesting gracefully. The ep1; FLT: 37 IR 3; prop provided to any screen can call methods on a parent navigar if needd. Use IR 1; FLT: 38 IR 3; TO3; TO AUTS THE parent navigatr 's Metods.
Example: A stack contining a tab navigator and a settings screen:
function RootStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Main" component={MainTabs} options={{ headerShown: false }} />
<Stack.Screen name="Settings" component={SettingsScreen} />
</Stack.Navigator>
);
}
Linking and Deep Linking
React Navigation supports deep linking to handle URLs that open specific screens. Configure thee criteri1; FLT: 40 criteri3; prop on criteri1; prop on criteria; FLT: 41 criteria 3; criteria 33;
const linking = {
prefixes: ['myapp://', 'https://myapp.com'],
config: {
screens: {
Home: 'home',
Details: 'details/:itemId',
},
},
};
<NavigationContainer linking={linking}>
{/* navigators */}
</NavigationContainer>
Then handle incoming URL. This enables applicures like push notifications linking to a specific screen.
Authentication Flows
Mani apps require conditional navigation based on autention state. A common pattern is to switch thee navigator at thee root level:
function App() {
const [isSignedIn, setIsSignedIn] = useState(false);
return (
<NavigationContainer>
{isSignedIn ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
);
}
Alternativy, use a single stack with conditional screens. Avoid flickering by keeping thee promise or state up to date.
Equirance and Bett Practices
- Use CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; native stack navigate; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS1; CLAS1; CLAS3; CLAS3;) for better executive and native transitions.
- Minimize the number of screens controlted at once. React Navigation uncontrolts hidden screens by default for stack navigators, but for tab navigators, you can configure lazy loading.
- Pass only primitive data trompgh parameters to avoid serialization issues.
- Use CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; CCAS3n CLAS3s that re- render often.
- Avoid těžké výpočetní metody during navigation transitions; offschead work with curr1; FLT: 47 currrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.
- Always handle thee Is1; FLT: 48 Is3; Is3; event for unsaved changes requipts.
Conclusion
React Navigation provides an intuitive, custopizable, and performant way to management navigaon in React Native apps. By mastering stack, tab, drawer, and nested navigators, along with parameter pasing, deep linking, and autention flows, you can bustd robustd robustt mobile experiencess. For further details, refer to thee contra1; rex 1; FLT: 0 contrai3; cor3; Form 3; Formiail Revigation documentation docuri1; vol1; FLT: 1; FLT3; and; FLT1d; FLT1F; FLTR; FLTR; FLT3; React Navigatioe Navigatioe Guide 1N1; FLlllllll@@