PaymentWeb.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * 网页支付页面
  3. * @邠心vbe on 2022/01/10
  4. */
  5. import React, { Component } from 'react';
  6. import { View, AppState, Linking } from 'react-native';
  7. export default class PaymentWeb extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. isCallback: false,
  12. paymentInfo: {
  13. url: '',
  14. amount: 0,
  15. type: ''
  16. }
  17. };
  18. this.canBack = false;
  19. this.stateListener;
  20. }
  21. componentDidMount() {
  22. const param = this.props.route.params
  23. console.log('PaymentWeb', param);
  24. if (param.url) {
  25. this.setState({
  26. isCallback: true,
  27. paymentInfo: param
  28. }, () => Linking.openURL(param.url));
  29. }
  30. this.stateListener = AppState.addEventListener("change", state => {
  31. if (state == 'active' && this.state.isCallback) {
  32. console.log(state);
  33. this.setState({
  34. isCallback: false
  35. }, () => {
  36. setTimeout(() => {
  37. goBack();
  38. }, 500);
  39. });
  40. }
  41. });
  42. /*this.props.navigation.addListener('beforeRemove', e => {
  43. if (!this.canBack) {
  44. if (this.state.isRepay) {
  45. this.onReset();
  46. e.preventDefault();
  47. } else if (this.state.isReturn) {
  48. this.canBack = true;
  49. goBack();
  50. setTimeout(() => {
  51. goBack();
  52. }, 100);
  53. } else {
  54. this.onClose();
  55. e.preventDefault();
  56. }
  57. }
  58. })*/
  59. }
  60. componentWillUnmount() {
  61. if (this.stateListener) {
  62. this.stateListener.remove();
  63. }
  64. }
  65. render() {
  66. return (
  67. <View>
  68. </View>
  69. );
  70. }
  71. }