gpt4 book ai didi

react-native - 如何在底部标签导航中添加顶部标签

转载 作者:行者123 更新时间:2023-12-05 04:19:33 27 4
gpt4 key购买 nike

您好,我想在底部标签页中添加顶部标签所以我想要屏幕,而不是底部标签标题,我想显示可以移动到另一个屏幕的顶部标签,

这是我的零食代码屏幕:https://snack.expo.dev/@aza1200/material-top-tabs-navigator-%7C-react-navigation

import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';

function FeedScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed!</Text>
</View>
);
}

function NotificationsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Notifications!</Text>
</View>
);
}


const TopTab = createMaterialTopTabNavigator();
const BottomTab = createBottomTabNavigator();

const TopTabNavigator = () => {
<TopTab.Navigator >
<TopTab.Screen name="Post Room" component={FeedScreen} />
<TopTab.Screen name="Rooms" component={NotificationsScreen} />
</TopTab.Navigator>
}

export const App = () => {
return (
<NavigationContainer>
<BottomTab.Navigator screenOptions={{headerShown: false}}>
<TopTab.Screen name="Top Tabs will" component={TopTabNavigator} />
<BottomTab.Screen name="Rooms" component={NotificationsScreen} />
</BottomTab.Navigator>
</NavigationContainer>
)
}


export default App;

这是我的代码和如果有人让我知道如何修复以下代码,那将非常有帮助。谢谢。

最佳答案

试试这个

    import * as React from 'react';
import {Text, View} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';

function FeedScreen() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Feed!</Text>
</View>
);
}

function NotificationsScreen() {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Notifications!</Text>
</View>
);
}

const TopTab = createMaterialTopTabNavigator();
const BottomTab = createBottomTabNavigator();

const TopTabNavigator = () => {
return (
<TopTab.Navigator>
<TopTab.Screen name="Post Room" component={FeedScreen} />
<TopTab.Screen name="Rooms" component={NotificationsScreen} />
</TopTab.Navigator>
);
};

export const App = () => {
return (
<NavigationContainer>
<BottomTab.Navigator screenOptions={{headerShown: false}}>
<TopTab.Screen name="Top Tabs will" component={TopTabNavigator} />
<BottomTab.Screen name="Rooms" component={NotificationsScreen} />
</BottomTab.Navigator>
</NavigationContainer>
);
};

export default App;

仅在 TopTabNavigator 中添加返回。

关于react-native - 如何在底部标签导航中添加顶部标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74780482/

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