我按照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>
);
}
}
但这给了我一个空白的空白屏幕。我该如何解决?
答案 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>
);
}
}