diff --git a/versioned_docs/version-7.x/drawer-based-navigation.md b/versioned_docs/version-7.x/drawer-based-navigation.md index 3673051ab0c..1f5202436ee 100755 --- a/versioned_docs/version-7.x/drawer-based-navigation.md +++ b/versioned_docs/version-7.x/drawer-based-navigation.md @@ -78,9 +78,11 @@ export default function App() { import * as React from 'react'; import { Button, View } from 'react-native'; import { createDrawerNavigator } from '@react-navigation/drawer'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; + +function HomeScreen() { + const navigation = useNavigation(); -function HomeScreen({ navigation }) { return ( diff --git a/versioned_docs/version-7.x/navigation-events.md b/versioned_docs/version-7.x/navigation-events.md index f442487b8e5..b23f364a10d 100644 --- a/versioned_docs/version-7.x/navigation-events.md +++ b/versioned_docs/version-7.x/navigation-events.md @@ -58,7 +58,9 @@ Normally, you'd add an event listener in `React.useEffect` for function componen ```js -function Profile({ navigation }) { +function Profile() { + const navigation = useNavigation(); + React.useEffect(() => { const unsubscribe = navigation.addListener('focus', () => { // do something diff --git a/versioned_docs/version-7.x/navigation-object.md b/versioned_docs/version-7.x/navigation-object.md index 48f2f00e0b9..72884c767e6 100755 --- a/versioned_docs/version-7.x/navigation-object.md +++ b/versioned_docs/version-7.x/navigation-object.md @@ -147,18 +147,22 @@ export default App; import * as React from 'react'; import { View, Text } from 'react-native'; import { Button } from '@react-navigation/elements'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; // codeblock-focus-start -function HomeScreen({ navigation: { navigate } }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( This is the home screen of the app diff --git a/versioned_docs/version-7.x/shared-element-transitions.md b/versioned_docs/version-7.x/shared-element-transitions.md index 6ddb7988371..718bc300a89 100644 --- a/versioned_docs/version-7.x/shared-element-transitions.md +++ b/versioned_docs/version-7.x/shared-element-transitions.md @@ -114,7 +114,7 @@ const styles = StyleSheet.create({ ```js name="Shared transition" import * as React from 'react'; import { View, Button, StyleSheet } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import Animated from 'react-native-reanimated'; @@ -122,7 +122,9 @@ import Animated from 'react-native-reanimated'; // highlight-next-line const Stack = createNativeStackNavigator(); -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( @@ -173,7 +175,9 @@ function B({ navigation }) { ); } -function C({ navigation }) { +function C() { + const navigation = useNavigation(); + return ( diff --git a/versioned_docs/version-7.x/status-bar.md b/versioned_docs/version-7.x/status-bar.md index c005f06aa32..847cd1ec95d 100755 --- a/versioned_docs/version-7.x/status-bar.md +++ b/versioned_docs/version-7.x/status-bar.md @@ -112,14 +112,15 @@ const styles = StyleSheet.create({ ```js name="Different status bar" snack version=7 import * as React from 'react'; import { View, Text, StatusBar, Button, StyleSheet } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { SafeAreaProvider, useSafeAreaInsets, } from 'react-native-safe-area-context'; -function Screen1({ navigation }) { +function Screen1() { + const navigation = useNavigation(); const insets = useSafeAreaInsets(); return ( @@ -147,7 +148,8 @@ function Screen1({ navigation }) { ); } -function Screen2({ navigation }) { +function Screen2() { + const navigation = useNavigation(); const insets = useSafeAreaInsets(); return ( @@ -334,7 +336,7 @@ const styles = StyleSheet.create({ import * as React from 'react'; import { View, Text, StatusBar, Button, StyleSheet } from 'react-native'; import { useIsFocused } from '@react-navigation/native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { SafeAreaProvider, @@ -348,7 +350,8 @@ function FocusAwareStatusBar(props) { } // codeblock-focus-start -function Screen1({ navigation }) { +function Screen1() { + const navigation = useNavigation(); const insets = useSafeAreaInsets(); return ( @@ -374,7 +377,8 @@ function Screen1({ navigation }) { ); } -function Screen2({ navigation }) { +function Screen2() { + const navigation = useNavigation(); const insets = useSafeAreaInsets(); return ( diff --git a/versioned_docs/version-7.x/tab-based-navigation.md b/versioned_docs/version-7.x/tab-based-navigation.md index 5cac7cba594..de788c54467 100755 --- a/versioned_docs/version-7.x/tab-based-navigation.md +++ b/versioned_docs/version-7.x/tab-based-navigation.md @@ -376,7 +376,9 @@ Switching from one tab to another has a familiar API — `navigation.navigat ```js -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home! @@ -388,7 +390,9 @@ function HomeScreen({ navigation }) { ); } -function SettingsScreen({ navigation }) { +function SettingsScreen() { + const navigation = useNavigation(); + return ( Settings! @@ -407,7 +411,7 @@ Usually tabs don't just display one screen — for example, on your Twitter ```js import * as React from 'react'; import { Button, Text, View } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; @@ -419,7 +423,9 @@ function DetailsScreen() { ); } -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home screen @@ -431,7 +437,9 @@ function HomeScreen({ navigation }) { ); } -function SettingsScreen({ navigation }) { +function SettingsScreen() { + const navigation = useNavigation(); + return ( Settings screen diff --git a/versioned_docs/version-7.x/themes.md b/versioned_docs/version-7.x/themes.md index cde26fcffc4..d1a153667e9 100755 --- a/versioned_docs/version-7.x/themes.md +++ b/versioned_docs/version-7.x/themes.md @@ -118,7 +118,7 @@ export default function App() { ```js name="Simple theme" snack version=7 // codeblock-focus-start import * as React from 'react'; -import { NavigationContainer, DefaultTheme } from '@react-navigation/native'; +import { NavigationContainer, DefaultTheme, useNavigation } from '@react-navigation/native'; // codeblock-focus-end import { Button, View, Text } from 'react-native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; @@ -136,8 +136,10 @@ const MyTheme = { }; // codeblock-focus-end -function SettingsScreen({ route, navigation }) { +function SettingsScreen({ route }) { + const navigation = useNavigation(); const { user } = route.params; + return ( Settings Screen @@ -150,7 +152,9 @@ function SettingsScreen({ route, navigation }) { ); } -function ProfileScreen({ navigation }) { +function ProfileScreen() { + const navigation = useNavigation(); + return ( Profile Screen @@ -158,7 +162,9 @@ function ProfileScreen({ navigation }) { ); } -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -491,7 +497,8 @@ function MyButton() { ); } -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); const { colors } = useTheme(); return ( @@ -671,6 +678,7 @@ import { DefaultTheme, DarkTheme, useTheme, + useNavigation, } from '@react-navigation/native'; // codeblock-focus-end import { createNativeStackNavigator } from '@react-navigation/native-stack'; @@ -718,7 +726,8 @@ function MyButton() { } // codeblock-focus-end -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); const { colors } = useTheme(); return (