如何使用React Native从多个类重用android设备后退按钮处理程序组件?

时间:2020-04-30 10:15:31

标签: android ios react-native

在我的场景中,我试图在单个文件中使用android back handler类。如何从多个类文件访问此文件,而不是复制它们。

我的下面的代码

export default class hardware extends Component {
  constructor(props) {
    super(props);
    this.BackButton = this.BackButton.bind(this);
  }

  componentWillMount() {
    BackHandler.addEventListener'BackPress',this.BackButton);
  }

  componentWillUnmount() {
    BackHandler.removeEventListener('BackPress',this.BackButton);
  }

  BackButton() {
    if(this.props.navigation){
        this.props.navigation.goBack(null);
        return true;
      }
    }
}

如何从其他多个班级文件屏幕访问?

export default class screenone extends Component {
   // how to access here?

}

0 个答案:

没有答案