反应本机底部导航栏

时间:2018-12-17 06:48:52

标签: react-native react-navigation

我正在尝试构建底部导航栏,所有内容都可以,但是导航栏没有显示。我也是新来的本地人。我觉得问题在于导出默认设置,因为它没有将对象作为App注册表。

其他文件也可以正常工作,例如没有错误,但导航栏没有显示

import React, { Component } from "react";
import { AppRegistry, Text, View, StyleSheet } from "react-native";
import Icon from "react-native-vector-icons/FontAwesome";
import { NavigationComponent } from "react-native-material-bottom- 
navigation";
import { TabNavigator } from "react-navigation";

import Home from "./app/components/home.js";
import BackgroundImage from "./app/components/BackgroundImage.js";
import FadeAnimation from 
"./app/components/animations/fadeAnimation.js";

class HomeScreen extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Home",
    tabBarIcon: () => <Icon size={24} color="white" name="home" />
  };

  render() {
    return (
      <BackgroundImage>
        <Home />
      </BackgroundImage>
    );
  }
}

class Announcements extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Announcements",
    tabBarIcon: () => <Icon size={24} color="white" name="bullhorn" />
  };

  render() {
    return (
      <View>
        <Text>This is announcement page</Text>
      </View>
    );
  }
}

class Calendar extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Calendar",
    tabBarIcon: () => <Icon size={24} color="white" name="calendar" />
  };

  render() {
     return (
       <View>
         <Text>This is announcement page</Text>
      </View>
    );
  }
}

class Contact extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Contact",
    tabBarIcon: () => <Icon size={24} color="white" name="comments" />
  };

  render() {
    return (
      <View>
        <Text>This is announcement page</Text>
      </View>
    );
  }
}

const MyApp = TabNavigator(
  {
    HomeScreen: { screen: HomeScreen },
    Announcements: { screen: Announcements },
    Calendar: { screen: Calendar },
    Contact: { screen: Contact }
  },

  {
    tabBarComponent: NavigationComponent,
    tabBarPosition: "bottom",
    tabBarOptions: {
     bottomNavigationOptions: {
        labelColor: "white",
        rippleColor: "white",
        tabs: {
          HomeScreen: {
            barBackgroundColor: "#3C2538"
          },
          Announcements: {
            barBackgroundColor: "#388E3C"
          },
          Calendar: {
                barBackgroundColor: "#E64A19",
                labelColor: "#434343",
                activeLabelColor: "#212121",
                activeIcon: <Icon size={24} color="#212121" name="calendar" />
          },
          Contact: {
            barBackgroundColor: "#a0c4ff"
          }
        }
      }
    }
  }
);
export default MyApp;
AppRegistry.registerComponent("MyApp", () => MyApp);

1 个答案:

答案 0 :(得分:1)

也许我的情况可能对您有所帮助,所以在App.js中创建底部标签导航器,只需导入createBottomTabNavigator,然后导入要放在底部标签导航中的某些屏幕,这是示例我的代码:

import { createBottomTabNavigator, createAppContainer } from 'react-navigation';

import Users from './Users';
import Vehicles from './Vehicles';
import Home from './Home';
import MyAccount from './MyAccount';

export default class Dashboard extends Component {
    static navigationOptions = {
        header: null,
    };
    render() {
      return (
        <AppContainer/>
      );
    }
  }

const TabScreens = createBottomTabNavigator({
    Home:{
        screen: Home
    },
    Users:{
        screen: Users,
    },
    Vehicles:{
        screen: Vehicles
    },
    MyAccount:{
        screen: MyAccount
    },
},{
    tabBarOptions:{
        labelStyle: {
            fontSize: 12,
            marginBottom:10,
        },
        style:{
            elevation:5
        }
    }
})

const AppContainer = createAppContainer(TabScreens);

希望对您有帮助