反应导航选项卡

时间:2018-08-29 17:11:51

标签: reactjs react-native react-navigation

我想在导航上添加事件并导航到屏幕,我有这段代码,但我不知道出了什么问题。

当我设置tabBarOnPress时,它不会导航,但会执行事件;如果未设置,我不知道如何触发事件。

import { createStackNavigator, createBottomTabNavigator } from 'react- 
navigation';

import HomeScreen from '../screens/HomeScreen';
import LinksScreen from '../screens/LinksScreen';
import {
  AdMobInterstitial,
} from 'react-native-admob';

AdMobInterstitial.setAdUnitID('ca-app-pub-2821491096541440/1777616101');

const HomeStack = createStackNavigator({
  Home: HomeScreen,
});

HomeStack.navigationOptions = {
  tabBarLabel: 'Apps recomendadas',
  tabBarOnPress: () => {
   this.somevent();
  },
};

const LinksStack = createStackNavigator({
  Links: LinksScreen,
});

LinksStack.navigationOptions = {
  tabBarLabel: 'FAQ',
  tabBarOnPress: () => {
     this.somevent();
  },
};

export default createBottomTabNavigator({
  HomeStack,
  LinksStack
},);

1 个答案:

答案 0 :(得分:0)

我和你有同样的问题,但是这段代码对我有用

tabBarOnPress: ({ navigation, defaultHandler }) => {
        console.log('onPress:', navigation.state.routeName);
        defaultHandler()
      },

如果我没有包含defaultHandler(),则屏幕不会导航以显示所选路线,而仅执行console.log语句