React Navigation Drawer Navigator是否覆盖onBackdropPress或onClose侦听器?

时间:2018-12-12 21:34:18

标签: reactjs react-native react-navigation

我需要在抽屉显示自身时运行某个功能,然后在抽屉隐藏时运行另一个功能。

我可以做到,这样抽屉打开的唯一方法就是通过我调用this.props.navigation.openDrawer(),并且我几乎可以做同样的关闭操作,只不过当您按下抽屉,它关闭。我需要找到一种方法来覆盖/禁用在关闭抽屉的背景上按下的行为。或者,我需要一个监听器来监听抽屉关闭事件。

使用React Navigation v3。

我正在使用自己的contentComponent,并且已经在该组件上尝试过使用“ willFocus”和“ willBlur”事件,但它们似乎不起作用:

  componentDidMount() {
    this.willFocusListener = this.props.navigation.addListener(
      'willFocus',
      this.setStatusBarColorDrawerOpen
    );

    this.willBlurListener = this.props.navigation.addListener(
      'willBlur',
      this.setStatusBarColorDrawerClose
    );
  }

  setStatusBarColorDrawerOpen = () => {
    console.log(' setting StatusBar to GRAY! ');
    if (Platform.OS !== 'ios') StatusBar.setBackgroundColor('rgb(242,242,242)');
  };

  setStatusBarColorDrawerClose = () => {
    console.log(' setting StatusBar to WHITE! ');
    if (Platform.OS !== 'ios') StatusBar.setBackgroundColor('#FFF');
  };

  componentWillUnmount() {
    this.willFocusListener.remove();
    this.willBlurListener.remove();
  }

还有其他想法吗?

0 个答案:

没有答案