如何在React Native Expo上下载和映像而不分离?

我正在尝试使用react-native-view-shot的组合下载qr代码的图像以捕获视图的图像,然后将其下载到相机胶卷中,因为expo似乎允许这种文件的捕获。最终,我只想将二维码下载到本地存储。似乎无法为此找到一个简单的解决方案(不分离)。以下是我到目前为止的尝试:

import React,{ Component } from 'react';
import {
    StyleSheet,Text,View,Image,TouchableOpacity,Modal,TouchableHighlight,Alert,Picker,Button,CameraRoll,PermissionsAndroid,Platform
} from 'react-native';
import ViewShot from "react-native-view-shot";
import { connect } from 'react-redux';
import QRCode from 'react-native-qrcode-svg';
import Share from './share';
import * as Permissions from 'expo-permissions';



    class Save extends Component {

        state={qr:null,hasCameraPermission:null}

        componentDidmount() {
          //this.checkAndroidPermission();
          this.checkMultiPermissions();
        }


        checkAndroidPermission = async () => {
            try {
              const permission = await Permissions.askAsync(Permissions.WRITE_EXTERNAL_STORAGE);
              await PermissionsAndroid.request(permission);
              Promise.resolve();
            } catch (error) {
              Promise.reject(error);
            }
        }

        checkMultiPermissions = async ()=> {
          const { status,expires,permissions } = await Permissions.askAsync(
            Permissions.CAMERA,Permissions.CAMERA_ROLL
          );

          if (status !== 'granted') {
            alert('Hey! You heve not enabled selected permissions');
          }
        }

        onCapture = uri => {
          console.log("do something with ",uri);
          this.setState({ qr: uri})
        }

        savePicture = async () => {
            console.log(this.state.qr);
            if (Platform.OS === 'android'){
              await checkAndroidPermission();
            }
           CameraRoll.saveToCameraRoll(this.state.qr,'phot');
        };

        donwloadFile = async () => {
            const fileUri = FileSystem.documentDirectory + fileName;
            FileSystem.downloadAsync(
                imageUrl,fileUri
            )
            .then(({ uri }) => {
                console.log('Finished downloading to ',uri);
            })
          }


        render() {

          const { hasCameraPermission } = this.state;

        if (hasCameraPermission === null) {
          console.log('Requesting for camera permission')
        }
        if (hasCameraPermission === false) {
          console.log('no access')
        }



          return (
              <View>
            <ViewShot onCapture={this.onCapture} captureMode="mount">
              <View style={{marginLeft: '30%',marginBottom: '10%'}}>
                <QRCode value={this.props.reducer.token}/>
              </View>
            </ViewShot>
            <Button title={'download image'} onPress={this.savePicture} />
            </View>
          );
        }
      }

      const mapstatetoProps = (state) => {

        const { reducer } = state
        return { reducer }
      };


      export default connect(mapstatetoProps
        )(Save)
jiba1023 回答:如何在React Native Expo上下载和映像而不分离?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2880736.html

大家都在问