美文网首页
底部切换条导航栏BottomTabNav.js

底部切换条导航栏BottomTabNav.js

作者: __MX | 来源:发表于2018-10-21 21:28 被阅读0次

    //在com包下新建一个BottomTabNav.js

    //然后新建Publish,My文件用于底部切换

    import ToTabNav from "./ToTabNav";  //加入顶部切换的引用

    import Publish from "../util/Publish";

    import My from "../util/My";

    yarn add react-native-vector-icons//图片插件

    import Ionicons from "react-native-vector-icons/Ionicons";//图片引用

    const BottomTabNav = createBottomTabNavigator(

      {

        //ToTabNav是顶部的切换条的导航栏

        ToTabNav: {

          screen: ToTabNav,

          navigationOptions: {

            title: "帖子"

          }

        },

        //新建的底部切换条

        Publish: {

          screen: Publish,

          navigationOptions: {

            title: "发布"

          }

        },

    //新建的底部切换条

        My: {

          screen: My,

          navigationOptions: {

            title: "我的"

          }

        }

      },//底部图片

      {

        navigationOptions: ({ navigation }) => ({

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

            const { routeName } = navigation.state;

            let iconName;

            //这儿需要改名字

            if (routeName === "ToTabNav") {

              //切换不同的图标

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

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

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

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

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

            }

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

          }

        })

      }

    );

    export default BottomTabNav;

    相关文章

      网友评论

          本文标题:底部切换条导航栏BottomTabNav.js

          本文链接:https://www.haomeiwen.com/subject/ppvuzftx.html