{"id":525,"date":"2022-11-23T20:17:58","date_gmt":"2022-11-23T12:17:58","guid":{"rendered":"http:\/\/gjweb.top\/?p=525"},"modified":"2022-11-23T20:17:59","modified_gmt":"2022-11-23T12:17:59","slug":"rn-%e8%b7%af%e7%94%b1-react-navigation","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=525","title":{"rendered":"RN \u8def\u7531 react-navigation"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.npmjs.com\/package\/react-navigation\">react-navigation<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5b89\u88c5\">\u5b89\u88c5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community\/masked-view  @react-navigation\/stack @react-navigation\/native @react-navigation\/native-stack<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u8d77\u6b65\">\u8d77\u6b65<\/h2>\n\n\n\n<p>\u5728 app \u9875\u9762\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as React from 'react';<br>import { Button, View, Text } from 'react-native';<br>import { NavigationContainer } from '@react-navigation\/native';<br>import { createStackNavigator } from '@react-navigation\/stack';<br>\u200b<br>function HomeScreen({ navigation }) {<br> &nbsp;return (<br> &nbsp; &nbsp;&lt;View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Text&gt;Home Screen&lt;\/Text&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Button<br> &nbsp; &nbsp; &nbsp; &nbsp;title=\"Go to Details\"<br> &nbsp; &nbsp; &nbsp; &nbsp;onPress={() =&gt; navigation.navigate('Details')}<br> &nbsp; &nbsp; &nbsp;\/&gt;<br> &nbsp; &nbsp;&lt;\/View&gt;<br>  );<br>}<br>\u200b<br>function DetailsScreen() {<br> &nbsp;return (<br> &nbsp; &nbsp;&lt;View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Text&gt;Details Screen&lt;\/Text&gt;<br> &nbsp; &nbsp;&lt;\/View&gt;<br>  );<br>}<br>\u200b<br>const Stack = createStackNavigator();<br>\u200b<br>function App() {<br> &nbsp;return (<br> &nbsp; &nbsp;&lt;NavigationContainer&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Stack.Navigator initialRouteName=\"Home\"&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Stack.Screen name=\"Home\" component={HomeScreen} \/&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;Stack.Screen name=\"Details\" component={DetailsScreen} \/&gt;<br> &nbsp; &nbsp; &nbsp;&lt;\/Stack.Navigator&gt;<br> &nbsp; &nbsp;&lt;\/NavigationContainer&gt;<br>  );<br>}<br>\u200b<br>export default App;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u8def\u7531\u8df3\u8f6c\">\u8def\u7531\u8df3\u8f6c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import { NavigationContainer } from '@react-navigation\/native';<br>function HomeScreen({ navigation }) {<br> &nbsp;return (<br> &nbsp; &nbsp;&lt;View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Text&gt;Home Screen&lt;\/Text&gt;<br> &nbsp; &nbsp; &nbsp;&lt;Button<br> &nbsp; &nbsp; &nbsp; &nbsp;title=\"Go to Details\"<br> &nbsp; &nbsp; &nbsp; &nbsp;onPress={() =&gt; navigation.navigate('Details')}<br> &nbsp; &nbsp; &nbsp;\/&gt;<br> &nbsp; &nbsp;&lt;\/View&gt;<br>  );<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u9690\u85cf\u8def\u7531\u4e2d\u9ed8\u8ba4\u7684header\">\u9690\u85cf\u8def\u7531\u4e2d\u9ed8\u8ba4\u7684header<\/h2>\n\n\n\n<p>\u5728 \u65b0\u7248\u672c\u7684 react-navigation 6.0 \u7248\u672c\u4e2d\u914d\u7f6e\u9879\u6709\u6240\u53d8\u5316<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Stack.Navigator<br> &nbsp; &nbsp; &nbsp; &nbsp;screenOptions={{headerShown:false}} <br> &nbsp; &nbsp; &nbsp; &nbsp;initialRouteName='Login'&gt;<br>&lt;\/Stack.Navigator&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>react-navigation \u5b89\u88c5 \u8d77\u6b65 \u5728 app \u9875\u9762\u4e2d \u8def\u7531\u8df3\u8f6c \u9690\u85cf\u8def\u7531\u4e2d\u9ed8\u8ba4\u7684header \u5728  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-525","post","type-post","status-publish","format-standard","hentry","category-reactnative"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=525"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":526,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/525\/revisions\/526"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}