uiwjs / react-native-alipay

基于 React Native 的宝支付包,已更新到最新的支付宝 SDK 版本,支持Android/iOS。
https://uiwjs.github.io/react-native-alipay/
MIT License
208 stars 49 forks source link

使用AppState.addEventListener时Android端会不正常的触发active状态 #43

Open NapChen opened 2 years ago

NapChen commented 2 years ago
componentDidMount() {
    Alipay.setAlipayScheme('uiwjspay');
    AppState.addEventListener('change', this._handleAppStateChange);
  }
  componentWillUnmount(){
    AppState.removeEventListener('change', this._handleAppStateChange)
  }
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'inactive'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'background'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:', 'active'
  // [info][tid:com.facebook.react.JavaScript] 'nextAppState:res:', null
  _handleAppStateChange = (nextAppState) => {
    console.log('nextAppState:', nextAppState)
    if(nextAppState==='active'){
      Linking.getInitialURL().then(res => {
        console.log('nextAppState:res:', res)
      })
    }
  }
  aliPay = () => {
    // return_url=
    const payInfo = `...`;
    Alipay.alipay(payInfo, (resule) => {
      console.log('resule-->>>', resule)
    });
  }

代码逻辑与这个一致,但是Android端在调起支付宝支付时,我的应用首先会进入background,在弹出支付宝支付界面时,会触发一次active状态(正常情况下不应该有),然后再次进入background,这会导致触发在_handleAppStateChange中的逻辑。我在接入微信支付时调起微信支付不存在这样的问题。另外此插件在iOS端也是正常的 image