Rn筆記

創(chuàng)建項目: react-native init 項目名

運行項目:右擊項目,選擇在終端打開,輸入命令:npm start

路由導(dǎo)航:1 yarn add react-navigation

? ? ? ? ? ? ? ? ? ?2配置路表:不同的路由導(dǎo)不同的包

? ??????????????????StackNavigator: import { StackNavigator } from "react-navigation";

????????????????????TabNavigator? ? :import { TabNavigator } from "react-navigation";? ? ? createBottomTabNavigator:import { createBottomTabNavigator } from "react-navigation";

? ??????????????????createSwitchNavigator:import { createSwitchNavigator } from "react-navigation";

路由分類:?StackNavigator ? ? ? ?跳轉(zhuǎn)頁面(詳情頁面)傳值

? ?????????????????TabNavigator? ? ? ? ? ? ? 頂部導(dǎo)航欄? ? ? ? ??

? ? ? ? ? ? ? ? ? ?createBottomTabNavigator? 底部導(dǎo)航欄

? ? ? ? ? ? ? ? ? ?createSwitchNavigator? ? ?身份驗證

eg:路由表:import { createTabNavigator } from "react-navigation";

????????????????????import News1 from "./../js/News1";

????????????????????import News2 from "./../js/News2";

????????????????????import News3 from "./../js/News3";

const Ly2 = createTabNavigator({

? News1: {

? ? screen: News1,//

? ? navigationOptions: {

? ? ? title: "新聞1"

? ? }

? },

? News2: {

? ? screen: News2,

? ? navigationOptions: {

? ? ? title: "新聞2"

? ? }

? },

? News3: {

? ? screen: News3,

? ? navigationOptions: {

? ? ? title: "新聞3"

? ? }

? }

});

export default Ly2;


底部導(dǎo)航欄:

使用三方圖庫:

/**

* 圖標使用:

* yarn add react-native-vector-icons

* react-native link

*

* import Ionicons from "react-native-vector-icons/Ionicons";

*

* navigationOptions中配置

*/

import { createBottomTabNavigator } from "react-navigation";

import Ionicons from "react-native-vector-icons/Ionicons";

const Home = createBottomTabNavigator(

? {

? ? Topic: {

? ? ? screen: Topic,

? ? ? navigationOptions: {

? ? ? ? title: "帖子"

? ? ? }

? ? },

? ? Publish: {

? ? ? screen: Publish,

? ? ? navigationOptions: {

? ? ? ? title: "發(fā)布"

? ? ? }

? ? },

? ? My: {

? ? ? screen: My,

? ? ? navigationOptions: {

? ? ? ? title: "我的"

? ? ? }

? ? }

? },

? {

? ? //誰設(shè)置文本選中前后效果顏色

? ? tabBarOptions: {

? ? ? activeTintColor: "#FF0000", //激活文本圖片樣式

? ? ? inactiveTintColor: "#0000FF", //未激活文本圖片樣式

? ? ? activeBackgroundColor: "#2296F3", //激活背景樣式

? ? ? inactiveBackgroundColor: "#ffffff" //未激活背景樣式

? ? },

? ? navigationOptions: ({ navigation }) => ({

? ? ? tabBarIcon: ({ focused, tintColor }) => {

? ? ? ? const { routeName } = navigation.state;

? ? ? ? let iconName;

? ? ? ? if (routeName === "Topic") {

? ? ? ? ? //切換不同的圖標

? ? ? ? ? //iconName = `ios-document${focused ? "" : "-outline"}`;

? ? ? ? ? //iconName = `${focused ? "ios-document" : "ios-document-outline"}`;

? ? ? ? ? iconName = "ios-document";

? ? ? ? } else if (routeName === "Publish") {

? ? ? ? ? iconName = "ios-create";

? ? ? ? } else if (routeName === "My") {

? ? ? ? ? iconName = "ios-person";

? ? ? ? }

? ? ? ? return <Ionicons name={iconName} size={25} color={tintColor} />;

? ? ? }

? ? })

? }

);






跳轉(zhuǎn)頁面,傳值取值:

? ? //跳轉(zhuǎn)到D對應(yīng)的頁面,傳遞name,age參數(shù)

? ? this.props.navigation.navigate("D", { name: "張三", age: "123" });

? ? //在D頁面中取值

? ? {this.props.navigation.getParam("name", "AAA")}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 導(dǎo)航庫React Navigation 功能:1.跳轉(zhuǎn)頁面 2.底部導(dǎo)航欄 3.頂部導(dǎo)航欄...
    理想三旬_d066閱讀 433評論 0 0
  • 官方網(wǎng)站 Learn once, navigate anywhere. React Navigation的誕生,源...
    Android_馮星閱讀 8,952評論 2 2
  • react-native.jpeg 本文是基于最新的react-navigation^2.9.1來書寫的。 如果遇...
    掛著鈴鐺的兔閱讀 221,700評論 131 299
  • 1、有效解決用戶點擊過快效應(yīng)多次的控件 react-native-touch-once 2、彈出toast即彈出一...
    xhwASS閱讀 524評論 0 1
  • 郭相麟 同樣的青春,不一樣的心理路程,同樣的貌美如花,不一樣的人生體驗! 價格遮住了迷茫的雙眼,價值點亮了夢想的青...
    郭相麟閱讀 187評論 0 0

友情鏈接更多精彩內(nèi)容