From 9d13c4df89304b66324cda84fbe84e31793093a8 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Mon, 25 Dec 2023 21:33:58 +0100 Subject: [PATCH] Rework fundamentals to accomodate static API (#1293) --- sidebars.js | 3 - static/examples/7.x/go-back.js | 10 +- static/examples/7.x/multiple-navigate.js | 10 +- static/examples/7.x/multiple-push.js | 10 +- static/examples/7.x/new-screen.js | 6 +- .../examples/7.x/params-nested-navigators.js | 14 +- static/examples/7.x/passing-params-back.js | 9 +- static/examples/7.x/passing-params.js | 10 +- static/examples/7.x/pop-to-top.js | 10 +- .../version-7.x/bottom-tab-navigator.md | 4 +- .../version-7.x/connecting-navigation-prop.md | 48 --- .../version-7.x/custom-navigators.md | 2 +- versioned_docs/version-7.x/custom-routers.md | 2 +- .../version-7.x/drawer-navigator.md | 4 +- versioned_docs/version-7.x/getting-started.md | 27 +- .../version-7.x/glossary-of-terms.md | 55 +-- versioned_docs/version-7.x/group.md | 2 +- versioned_docs/version-7.x/header-buttons.md | 90 ++++- versioned_docs/version-7.x/headers.md | 175 +++++++++- .../version-7.x/hello-react-navigation.md | 200 ++++++++++- .../version-7.x/material-top-tab-navigator.md | 4 +- .../version-7.x/multiple-drawers.md | 6 +- .../version-7.x/native-stack-navigator.md | 10 +- .../navigating-without-navigation-prop.md | 2 +- versioned_docs/version-7.x/navigating.md | 28 +- .../version-7.x/navigation-container.md | 2 +- .../version-7.x/navigation-context.md | 2 +- .../version-7.x/navigation-events.md | 6 +- .../version-7.x/navigation-lifecycle.md | 38 +- ...avigation-prop.md => navigation-object.md} | 24 +- .../version-7.x/nesting-navigators.md | 324 +++++++++++++++--- versioned_docs/version-7.x/params.md | 45 ++- .../{route-prop.md => route-object.md} | 8 +- versioned_docs/version-7.x/screen-options.md | 8 +- versioned_docs/version-7.x/screen.md | 4 +- versioned_docs/version-7.x/stack-navigator.md | 4 +- .../version-7.x/static-api-reference.md | 4 +- .../version-7.x/static-configuration.md | 181 ---------- versioned_docs/version-7.x/typescript.md | 14 +- .../version-7.x/use-link-builder.md | 2 +- versioned_docs/version-7.x/use-navigation.md | 8 +- versioned_docs/version-7.x/use-route.md | 6 +- versioned_sidebars/version-7.x-sidebars.json | 14 +- 43 files changed, 964 insertions(+), 471 deletions(-) delete mode 100755 sidebars.js delete mode 100755 versioned_docs/version-7.x/connecting-navigation-prop.md rename versioned_docs/version-7.x/{navigation-prop.md => navigation-object.md} (89%) rename versioned_docs/version-7.x/{route-prop.md => route-object.md} (76%) delete mode 100644 versioned_docs/version-7.x/static-configuration.md diff --git a/sidebars.js b/sidebars.js deleted file mode 100755 index 2c1f4c9e5de..00000000000 --- a/sidebars.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - docs: { } -}; diff --git a/static/examples/7.x/go-back.js b/static/examples/7.x/go-back.js index e2417a2cf9d..ed6b1dbbc07 100755 --- a/static/examples/7.x/go-back.js +++ b/static/examples/7.x/go-back.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/multiple-navigate.js b/static/examples/7.x/multiple-navigate.js index 8e4ecc94b25..ddb83a07768 100755 --- a/static/examples/7.x/multiple-navigate.js +++ b/static/examples/7.x/multiple-navigate.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/multiple-push.js b/static/examples/7.x/multiple-push.js index 32c8f1126a9..21f2213a1b1 100755 --- a/static/examples/7.x/multiple-push.js +++ b/static/examples/7.x/multiple-push.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/static/examples/7.x/new-screen.js b/static/examples/7.x/new-screen.js index 7d7e4991edb..21c7b472f92 100755 --- a/static/examples/7.x/new-screen.js +++ b/static/examples/7.x/new-screen.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen diff --git a/static/examples/7.x/params-nested-navigators.js b/static/examples/7.x/params-nested-navigators.js index dbb8959679b..d2a20a7cad8 100755 --- a/static/examples/7.x/params-nested-navigators.js +++ b/static/examples/7.x/params-nested-navigators.js @@ -1,10 +1,12 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createDrawerNavigator } from '@react-navigation/drawer'; -function SettingsScreen({ route, navigation }) { +function SettingsScreen({ route }) { + const navigation = useNavigation(); + const { user } = route.params; return ( @@ -18,7 +20,9 @@ function SettingsScreen({ route, navigation }) { ); } -function ProfileScreen({ navigation }) { +function ProfileScreen() { + const navigation = useNavigation(); + return ( Profile Screen @@ -26,7 +30,9 @@ function ProfileScreen({ navigation }) { ); } -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen diff --git a/static/examples/7.x/passing-params-back.js b/static/examples/7.x/passing-params-back.js index 5a2a6051c5d..3c392ef963e 100755 --- a/static/examples/7.x/passing-params-back.js +++ b/static/examples/7.x/passing-params-back.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Text, TextInput, View, Button } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation, route }) { +function HomeScreen({ route }) { + const navigation = useNavigation(); + React.useEffect(() => { if (route.params?.post) { // Post updated, do something with `route.params.post` @@ -22,7 +24,8 @@ function HomeScreen({ navigation, route }) { ); } -function CreatePostScreen({ navigation, route }) { +function CreatePostScreen({ route }) { + const navigation = useNavigation(); const [postText, setPostText] = React.useState(''); return ( diff --git a/static/examples/7.x/passing-params.js b/static/examples/7.x/passing-params.js index 5a43e8c6d51..78a3586dd0e 100755 --- a/static/examples/7.x/passing-params.js +++ b/static/examples/7.x/passing-params.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Text, View, Button } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -21,7 +23,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ route, navigation }) { +function DetailsScreen({ route }) { + const navigation = useNavigation(); + /* 2. Get the param */ const { itemId } = route.params; const { otherParam } = route.params; diff --git a/static/examples/7.x/pop-to-top.js b/static/examples/7.x/pop-to-top.js index 83dd5f08a7c..4d108ad612e 100755 --- a/static/examples/7.x/pop-to-top.js +++ b/static/examples/7.x/pop-to-top.js @@ -1,9 +1,11 @@ import * as React from 'react'; import { Button, View, Text } from 'react-native'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigation } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; -function HomeScreen({ navigation }) { +function HomeScreen() { + const navigation = useNavigation(); + return ( Home Screen @@ -15,7 +17,9 @@ function HomeScreen({ navigation }) { ); } -function DetailsScreen({ navigation }) { +function DetailsScreen() { + const navigation = useNavigation(); + return ( Details Screen diff --git a/versioned_docs/version-7.x/bottom-tab-navigator.md b/versioned_docs/version-7.x/bottom-tab-navigator.md index 35ac873c811..1582b919c58 100755 --- a/versioned_docs/version-7.x/bottom-tab-navigator.md +++ b/versioned_docs/version-7.x/bottom-tab-navigator.md @@ -53,7 +53,7 @@ The `Tab.Navigator` component accepts following props: #### `id` -Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-prop.md#getparent) to refer to this navigator in a child navigator. +Optional unique ID for the navigator. This can be used with [`navigation.getParent`](navigation-object.md#getparent) to refer to this navigator in a child navigator. #### `initialRouteName` @@ -442,7 +442,7 @@ React.useEffect(() => { ### Helpers -The tab navigator adds the following methods to the navigation prop: +The tab navigator adds the following methods to the navigation object: #### `jumpTo` diff --git a/versioned_docs/version-7.x/connecting-navigation-prop.md b/versioned_docs/version-7.x/connecting-navigation-prop.md deleted file mode 100755 index 628cedd792e..00000000000 --- a/versioned_docs/version-7.x/connecting-navigation-prop.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -id: connecting-navigation-prop -title: Access the navigation prop from any component -sidebar_label: Access the navigation prop from any component ---- - -[`useNavigation`](use-navigation.md) is a hook which gives access to the `navigation` object. It's useful when you cannot pass the `navigation` prop into the component directly, or don't want to pass it in case of a deeply nested child. - -An ordinary component that is not a screen component will not receive the navigation prop automatically. For example in this `GoToButton` component: - -```js -import * as React from 'react'; -import { Button } from 'react-native'; - -function GoToButton({ navigation, screenName }) { - return ( -