/** * PayNow支付页面 * @邠心vbe on 2021/05/12 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, ScrollView } from 'react-native'; import {CameraRoll} from "@react-native-camera-roll/camera-roll"; import ViewShot from "react-native-view-shot"; import Button from '../../components/Button'; import Dialog from '../../components/Dialog'; import { Balance } from '../wallet/Payment'; import {check, request, openSettings, PERMISSIONS, RESULTS} from 'react-native-permissions'; import TextView from '../../components/TextView'; import utils from '../../utils/utils'; export default class PayNow extends Component { constructor(props) { super(props); this.state = { amount: 0, base64: '', qrInfo: { merchantUEN: "", merchantName: "", paymentAmount: "", expirationTime: "", imageBase64Code: "" }, isNewVersion: false }; this.denied = true; this.viewShot = React.createRef(); } componentDidMount() { if (this.props.route.params.info) { this.setState({ qrInfo: this.props.route.params.info, isNewVersion: true }) console.log("新版ANZ支付"); } else if (this.props.route.params.amount) { this.setState({ isNewVersion: false, amount: this.props.route.params?.amount, base64: 'data:image/png;base64,' + this.props.route.params.base64 }); } } savePhoto() { Dialog.showProgressDialog(); this.viewShot.current.capture().then(uri => { Dialog.dismissLoading(); CameraRoll.save(uri, { type: 'photo' }); console.log("Save Photo with ", uri); toastShort($t('payment.successSave2gallery')); }).catch(errs => { toastShort(errs) Dialog.dismissLoading(); }); } getPermission() { request( isIOS ? PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY : utils.getFilePermissionString()) .then(res => { console.log('getPermission', res) this.checkPermission(); }).catch(errs => { console.info('getPermission', errs) }); } checkPermission() { check( isIOS ? PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY : utils.getFilePermissionString()) .then(res => { switch (res) { case RESULTS.UNAVAILABLE: console.log('此功能不可用(在此设备上/在此上下文中)'); if (isIOS) { this.savePhoto(); } else { toastShort($t('payment.errSave2gallery')); } break; case RESULTS.DENIED: console.log('权限未被请求/被拒绝,但可以请求'); if (this.denied) { this.denied = false; this.getPermission(); } else { this.denied = true; toastShort($t('payment.errSave2gallery')); } break; case RESULTS.LIMITED: console.log('权限是有限的:有些操作是可能的'); this.savePhoto(); break; case RESULTS.GRANTED: console.log('许可被授予'); this.savePhoto(); break; case RESULTS.BLOCKED: console.log('权限被拒绝,不再可请求'); Dialog.showDialog({ title: $t('common.error'), message: $t('payment.errSave2galleryPermission'), ok: $t('payment.btnSetting'), callback: btn => { if (btn == Dialog.BUTTON_OK) { console.log('ok'); openSettings().catch(() => console.warn('cannot open settings')); } } }); //toastShort('Save to gallery failed'); break; } }).catch(err1 => { }) } render() { if (this.state.isNewVersion) { return ( {/* PAYMENT TO: {this.state.qrInfo.merchantName} ({this.state.qrInfo.merchantUEN}) */} { this.state.qrInfo.imageBase64Code ? : } PAYMENT AMOUNT: {this.state.qrInfo.paymentAmount} EXPIRATION TIME: {this.state.qrInfo.expirationTime}