从抽屉项目中按下时,我必须导航至特定选项卡。我搜索了很多东西,但是找不到与我的问题有关的任何东西
我尝试遵循此导航操作链接,但无法找到实现方法 Navigate to specific tab from Drawer Navigator。
const TabNavigator = createMaterialTopTabNavigator(
{
Upcoming: { screen: UpcomingScreen },
Accepted: { screen: AcceptedScreen },
Ongoing: { screen: OngoingScreen },
Completed: { screen: CompletedScreen },
},
);
const Screen1_StackNavigator = createStackNavigator({
First: {
screen: TabNavigator,
},
});
const DrawerNavigatorExample = createDrawerNavigator({
Screen1: {
//Title
screen: Screen1_StackNavigator,
navigationOptions: {
drawerLabel: 'Upcoming Trips',
labelStyle: {
fontFamily: Fonts.LatoLight,
fontWeight: '200',
},
drawerIcon: () => (
// <Icon name="align-center" size={20} color="#365888" />
<Image style={{height: 20, width: 21}} source={require('./images/calendar.png')} />
)
},
},
Screen2: {
//Title
screen: Screen2_StackNavigator,
navigationOptions: {
drawerLabel: () => null,
},
},
Screen3: {
//Title
screen: Screen1_StackNavigator,
navigationOptions: {
drawerLabel: 'Accepted Trips',
labelStyle: {
fontFamily: Fonts.LatoLight,
fontWeight: '200',
},
drawerIcon: () => (
// <Icon name="align-center" size={20} color="#365888" />
<Image style={{height: 22, width: 22}} source={require('./images/sticker.png')} />
)
},
},
Screen4: {
//Title
screen: Screen1_StackNavigator,
navigationOptions: {
drawerLabel: 'Ongoing Trips',
labelStyle: {
fontFamily: Fonts.LatoLight,
fontWeight: 'normal'
},
drawerIcon: () => (
// <Icon name="align-center" size={20} color="#365888" />
<Image style={{height: 22, width: 22}} source={require('./images/navigator.png')} />
)
},
},
Screen5: {
//Title
screen: Screen1_StackNavigator,
navigationOptions: {
drawerLabel: 'Completed Trips',
labelStyle: {
fontFamily: Fonts.LatoLight,
fontWeight: 'normal'
},
drawerIcon: () => (
// <Icon name="align-center" size={20} color="#365888" />
<Image style={{height: 24, width: 20}} source={require('./images/checklist.png')} />
)
},
},
})
当我在抽屉式菜单上按“ Screen3”时,应在标签导航器中导航至“已接受”屏幕。当我在抽屉菜单上按“ Screen4”时,应在选项卡导航器中导航至“进行中”屏幕。当我在抽屉式菜单上按“ Screen5”时,应在选项卡导航器中导航至“已完成”屏幕。有什么办法可以实现呢?谢谢
答案 0 :(得分:0)
您可以重载tabBarComponent。然后,您可以检查点击/单击了哪个选项卡,并为其分配一个navigate
-调用。
示例:
createAppContainer(createBottomTabNavigator({
TAB_NEWS: {
screen: NewsMenu,
navigationOptions: {
tabBarLabel: 'NEWS',
},
},
TAB_MORE: {
screen: MenuMenu,
navigationOptions: {
tabBarLabel: 'MEHR',
},
},
....
tabBarComponent: ({ jumpToIndex, ...props }) => (
<BottomTabBar
{...props}
jumpToIndex={(index) => {
if (index === 2) {
// This is the MORE-Tab-Button. Don't switch to tab, but open the Modal
props.navigation.navigate('Menu_Screen');
} else {
jumpToIndex(index);
}
}}
/>
),
答案 1 :(得分:0)
大家好,我工作了一段时间,发现了一个简单的解决方案,希望对将来的任何人有帮助。解决方案是通过“ 编写自定义抽屉组件并在contentComponent中提及”。
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>