如何在本机中使用App.js中的navigation.js

时间:2019-02-27 16:43:57

标签: javascript react-native react-navigation

我按照https://reactnavigation.org/docs/en/tab-based-navigation.html的说明在应用中创建导航。

这是我的Navigation.js文件代码

import React from 'react';
import { Text, View } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Home!</Text>
      </View>
    );
  }
}
class SettingsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Settings!</Text>
      </View>
    );
  }
}
const TabNavigator = createBottomTabNavigator({
  Home: { screen: HomeScreen },
  Settings: { screen: SettingsScreen },
});

const TabNav = createAppContainer(TabNavigator);
export default TabNav;

我想将其导入到我的App.js文件中,并将其用作导航。这是我的App.js文件

import React from 'react';
import {Text,View,Button} from 'react-native';

import TabNav from './components/CustomerDashboard/Navigation';

export default class App extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
        };
    }


    render() {
        return (
            <View>
                <TabNav></TabNav>
            </View>

        );
    }
}

但这给了我一个空白的空白屏幕。我该如何解决?

1 个答案:

答案 0 :(得分:1)

您需要在View内的App.js中添加样式,如果将其弹性值设置为1,它将扩展以覆盖可用空间。

您还可以通过以下方式关闭TabNav组件:

<TabNav />而不是使用<TabNav></TabNav>

这是我更新您的App.js

的方式
export default class App extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
        };
    }


    render() {
        return (
            <View style={{flex: 1}}>
                <TabNav />
            </View>

        );
    }
}