ReactNative —Android 手机返回按钮点击事件

为 BackHandler 绑定 hardwareBackPress 事件监听;

返回true的时候,不做操作;

返回false,返回上一页;
class ScreenWithCustomBackBehavior extends React.Component { componentDidMount() { 
  BackHandler.addEventListener('hardwareBackPress', this.onBackButtonPressAndroid); 
} 
componentWillUnmount() {
  BackHandler.removeEventListener('hardwareBackPress', this.onBackButtonPressAndroid); 
} 
onBackButtonPressAndroid = () => { 
  if (this.isSelectionModeEnabled()) { 
    //有选中的模块,先取消选择,不做页面的返回跳转
    this.disableSelectionMode(); 
    return true; 
  } else { 
    return false; 
  } 
}; 
}

《ReactNative —Android 手机返回按钮点击事件》上有1条评论

  1. I’ve bewen surfing on-line greater than 3 hourss lately, butt I by nno means dixcovered anny attention-grabbing artiicle like yours.

    It iis pretfty worth sufficient for me. Personally, iif alll website owners and
    blogbgers made excellent content aas yyou probably did, thhe net cann bee a lot more helpful than ever before.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注