zoukankan      html  css  js  c++  java
  • RN—Android 物理返回键监听

    A → B

    使用 navigator 导航,用 goBack() 返回的时候传递参数

    A 页面

    this.props.navigation.navigate("B", {
                                callBack: (data) => {       //回调函数
                                    this.setState({
                                        studentCount: data
                                    })
                                }
                            });

    B 页面

      onPress()=>{
            this.props.navigation.state.params.callBack(data)
            this.props.navigation.goBack();
            }

    在使用 Android 机的时候,点击物理返回键的时候,并不会走 navigator ,所以需要加一个返回键的事件监听

    1.在生命周期中监听

    componentDidMount() {
            BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    
      componentWillUnmount() {
            BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    
        onBackAndroid = () => {
            this.props.navigation.goBack();
            this.props.navigation.state.params.callBack(data)
            return true
        }

    2.待测试

  • 相关阅读:
    String to Integer (atoi)
    Reverse Integer
    ZigZag Conversion
    01-GIT
    04-Eclipse操作SVN
    03-客户端访问SVN服务器
    02-Subversion安装与配置
    01-SVN概述
    09-Spring整合之SSH
    08-Spring的事务管理
  • 原文地址:https://www.cnblogs.com/gemeiyi/p/9988260.html
Copyright © 2011-2022 走看看