/** * 网页支付页面 * @邠心vbe on 2022/01/10 */ import React, { Component } from 'react'; import { View, AppState, Linking } from 'react-native'; export default class PaymentWeb extends Component { constructor(props) { super(props); this.state = { isCallback: false, paymentInfo: { url: '', amount: 0, type: '' } }; this.canBack = false; this.stateListener; } componentDidMount() { const param = this.props.route.params console.log('PaymentWeb', param); if (param.url) { this.setState({ isCallback: true, paymentInfo: param }, () => Linking.openURL(param.url)); } this.stateListener = AppState.addEventListener("change", state => { if (state == 'active' && this.state.isCallback) { console.log(state); this.setState({ isCallback: false }, () => { setTimeout(() => { goBack(); }, 500); }); } }); /*this.props.navigation.addListener('beforeRemove', e => { if (!this.canBack) { if (this.state.isRepay) { this.onReset(); e.preventDefault(); } else if (this.state.isReturn) { this.canBack = true; goBack(); setTimeout(() => { goBack(); }, 100); } else { this.onClose(); e.preventDefault(); } } })*/ } componentWillUnmount() { if (this.stateListener) { this.stateListener.remove(); } } render() { return ( ); } }