我使用了react-native-tarbar-bottom和react-navigation Drawer,但是当我单击左侧菜单上的抽屉项时,需要选择选项卡。
为此,我想使用Stack或Stack.AppTabs.Screen.props,但如何使用?
import { AppRegistry } from 'react-native';
import { StackNavigator, DrawerNavigator } from 'react-navigation';
import React from 'react';
import App from './src/app';
import AppTabs from './src/components/appTabs/appTabs';
import Drawer from './src/drawer';
console.disableYellowBox = true;
const eventHandler = (event) => {
Stack.AppTabs.screen.props.navigation.onGetTabHandler()(event);
};
const Stack = {
App: { screen: App },
AppTabs: { screen: AppTabs },
};
const DrawerRoutes = {
StartingScreenStack: {
screen: StackNavigator(Stack, { initialRouteName: 'App' })
}
};
const RootNavigator =
StackNavigator({
Drawer: {
name: 'Drawer',
screen: DrawerNavigator(
DrawerRoutes, {
drawerWidth: 240,
contentComponent: props => <Drawer {...props} eventHandler={eventHandler} />
}
),
},
以上是我尝试过的代码,但是我无法为AppTab设置道具, 任何人请帮助我。 谢谢
答案 0 :(得分:0)
最后我发现了我的错误,并像这样解决了它,
var tabHandler = (that, index) => {}
var currentTab;
const setHandler = (that, func) => {
tabHandler = func;
currentTab = that;
}
const drawerSelectHandler = (drawer, index) => {
drawer.props.navigation.navigate("DrawerClose");
tabHandler(currentTab, index);
};
const Stack = {
App: { screen: App },
AppTabs: { screen: props => <AppTabs {...props} setTabHandler={setHandler} /> }
};