gpt4 book ai didi

javascript - 如何在 createBottomTabNavigator 中实现 createMaterialTopTabNavigator

转载 作者:行者123 更新时间:2023-12-03 01:19:12 30 4
gpt4 key购买 nike

我正在尝试在其中一个选项卡上创建一个带有 createMaterialTopTabNavigatorcreateBottomTabNavigator 。它告诉我路由“TopTabs”的组件必须是一个 react 组件。我的根导航器中已经有一个嵌套选项卡导航器,并且它没有抛出任何错误,所以我不明白为什么它会在这里抛出错误。如有任何提示,我们将不胜感激。

import React, { Component } from 'react';
import { Dimensions, Platform } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import { createBottomTabNavigator, createMaterialTopTabNavigator } from 'react-navigation';
import { Icon } from 'react-native-elements';
import Apps from './screens/Apps';
import Garage from './screens/Garage';
import News from './screens/News';
import Chatbot from './screens/Chatbot';
import ViewApp from './screens/ViewApp';
import Login from './components/Login';
import AppItem from './components/AppItem';
import NewApps from './screens/NewApps';
import OtherApps from './screens/OtherApps';


let screen = Dimensions.get('window');

export const Tabs = createBottomTabNavigator(
{
'TopTabs': {
screen: TopTabs,
},

'Apps': {
screen: Apps,
navigationOptions: {
tabBarLabel: 'Apps',
tabBarIcon: ({ tintColor }) => <Icon name="apps" type="material-community" size={32} color={tintColor} />,
tabBarOptions: {
activeTintColor: '#2896d3',
labelStyle: {
fontSize: 14,
},
},
},
},

'News': {
screen: News,
navigationOptions: {
tabBarLabel: 'News',
tabBarIcon: ({ tintColor }) => <Icon name="newspaper-o" type="font-awesome" size={26} color={tintColor} />,
tabBarOptions: {
activeTintColor: '#2896d3',
labelStyle: {
fontSize: 14,
},
},
},
},
'Garage': {
screen: Garage,
navigationOptions: {
tabBarLabel: 'Garage',
tabBarIcon: ({ tintColor }) => <Icon name="garage" type="material-community" size={34} color={tintColor} />,
tabBarOptions: {
activeTintColor: '#2896d3',
labelStyle: {
fontSize: 14,
},
},
},
},
'Chatbot': {
screen: Chatbot,
navigationOptions: {
tabBarLabel: 'Support',
tabBarIcon: ({ tintColor }) => <Icon name="ios-person-outline" type="ionicon" size={34} color={tintColor} />,
tabBarOptions: {
activeTintColor: '#2896d3',
labelStyle: {
fontSize: 14,
},
},
},
},
},
{
initialRouteName: 'News',
}
);

const AppTabs = createMaterialTopTabNavigator({
Tab1: NewApps,
Tab2: OtherApps,
}, {
tabBarOptions: {
scrollEnabled: true,
labelStyle: {
fontSize: 12,
},
tabStyle: {
width: Dimensions.get('window').width / 2,
},
style: {
backgroundColor: 'tomato',
},
indicatorStyle: {
backgroundColor: '#fff'
}
},
});

export const createRootNavigator = () => {
return createStackNavigator(
{
Home: {
screen: Login,
navigationOptions: {
header: null,
gesturesEnabled: false
}
},
Tabs: {
screen: Tabs,
navigationOptions: {
header: null,
gesturesEnabled: false
}
},
ViewApp: {
screen: ViewApp,
navigationOptions: {
header: null,
},
},
},
{
headerMode: "none",
mode: "modal"
}
);
};

export const TopTabs = createMaterialTopTabNavigator(
{
'TopTab1': TopTab1,
'TopTab2': TopTab2,
},
{
initialRouteName: 'TopTab2',
tabBarPosition: 'top',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
style: {
paddingTop: Constants.statusBarHeight,
}
}
}
);

class TabScreen extends Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}><Text>{this.props.title}</Text></View>
);
}
}

class TopTab1 extends Component {
render() {
return (<TabScreen title="Top tab1" />);
}
}

class TopTab2 extends Component {
render() {
return (<TabScreen title="Top tab2" />);
}
}

最佳答案

要在 createBottomTabNavigator 中实现 createMaterialTopTabNavigator,您可以执行以下操作,我用一个简单的默认示例进行解释:

这是我的createBottomTabNavigator:

export const FooterStack = createBottomTabNavigator(
{
First: {
screen: FirstScreen
},
Second: {
screen: SecondScreen
},
Third: {
screen: BottomStack // Here I Have my createMaterialTopTabNavigator
}
}
)

然后我就有了 createMaterialTopTabNavigator:

export const BottomStack = createMaterialTopTabNavigator(
{
FirstInTopStack: {
screen: FirstInTopStackScreen
},
SecondInTopStack: {
screen: SecondInTopStackScreen
}
}
);

关于javascript - 如何在 createBottomTabNavigator 中实现 createMaterialTopTabNavigator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51837501/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com