我是本机新手。我正在尝试创建一个导航选项卡,该选项卡可以通过点击路线或水平滑动来在不同路线之间切换。
我正在使用反应导航link
的createMaterialTopTabNavigator我按照文档进行了操作,但滑动不起作用。
我的导航文件:
import { createAppContainer } from 'react-navigation';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';
import HomeScreen from '../screens/home/HomeView';
import SettingsScreen from '../screens/settings/SettingsView';
const TabScreen = createMaterialTopTabNavigator(
{
Home: { screen: HomeScreen },
Settings: { screen: SettingsScreen },
},
{
initialRouteName: 'Home',
tabBarPosition: 'top',
swipeEnabled: true,
lazy: true,
animationEnabled: true,
tabBarOptions: {
activeTintColor: '#FFFFFF',
inactiveTintColor: '#F8F8F8',
style: {
backgroundColor: '#633689',
},
labelStyle: {
textAlign: 'center',
},
indicatorStyle: {
borderBottomColor: '#87B56A',
borderBottomWidth: 2,
},
},
}
);
const AppNavigator = createStackNavigator({
TabScreen: {
screen: TabScreen,
navigationOptions: {
headerStyle: {
backgroundColor: '#633689',
},
headerTintColor: '#FFFFFF',
title: 'TabExample',
},
},
});
export default createAppContainer(AppNavigator);
我的主屏幕和设置屏幕:
import React, { Component } from 'react';
import { View, Text } from 'react-native';
class SettingScreen extends Component {
render() {
return (
<View>
<Text>
Setting
</Text>
</View>
);
}
}
export default SettingScreen;
我正在使用以下软件包:
"react": "16.8.6",
"react-native": "0.60.5",
"react-native-gesture-handler": "^1.4.1",
"react-native-reanimated": "^1.2.0",
"react-navigation": "^4.0.2",
"react-navigation-stack": "^1.5.4",
"react-navigation-tabs": "^2.4.1",
答案 0 :(得分:1)
我阅读了文档,意识到我错过了添加Andriod实现,甚至忘记了修改MainActivity.java。
只需阅读https://reactnavigation.org/docs/en/material-top-tab-navigator.html,https://reactnavigation.org/docs/en/getting-started.html页并按照指南对Andriod和IOS文件进行更改即可。