简体   繁体   English

React Native - 如何拍摄多个快照和 Select 它们

[英]React Native - How to Take Multiple Snaps and Select Them

I'm trying to take a snap using React Native.我正在尝试使用 React Native。 I have the code to snap the image.我有捕捉图像的代码。 Now I want to take multiple snap photos and select them exactly like in WhatsApp (the tick UI).现在我想拍摄多张快照和 select 它们,就像在 WhatsApp 中一样(勾选 UI)。

I'm new to React Native.我是 React Native 的新手。 It will be helpful if someone helps me do it.如果有人帮助我做到这一点,那将会很有帮助。

Here is the screenshot for reference that how I exactly want it to be.这是我想要的截图供参考。

camera.page.js camera.page.js

import React from 'react';
import { Camera } from 'expo-camera';
import { View, Text } from 'react-native';
import * as Permissions from 'expo-permissions';

import styles from './styles';
import Toolbar from './toolbar.component';
import Gallery from './gallery.component';

export default class CameraPage extends React.Component {
    camera = null;

    state = {
        captures: [],
        capturing: null,
        hasCameraPermission: null,
        cameraType: Camera.Constants.Type.back,
        flashMode: Camera.Constants.FlashMode.off,
    };

    setFlashMode = (flashMode) => this.setState({ flashMode });
    setCameraType = (cameraType) => this.setState({ cameraType });
    handleCaptureIn = () => this.setState({ capturing: true });

    handleCaptureOut = () => {
        if (this.state.capturing)
            this.camera.stopRecording();
    };

    handleShortCapture = async () => {
        const photoData = await this.camera.takePictureAsync();
        this.setState({ capturing: false, captures: [photoData, ...this.state.captures] })
    };

    handleLongCapture = async () => {
        const videoData = await this.camera.recordAsync();
        this.setState({ capturing: false, captures: [videoData, ...this.state.captures] });
    };

    async componentDidMount() {
        const camera = await Permissions.askAsync(Permissions.CAMERA);
        const audio = await Permissions.askAsync(Permissions.AUDIO_RECORDING);
        const hasCameraPermission = (camera.status === 'granted' && audio.status === 'granted');

        this.setState({ hasCameraPermission });
    };

    render() {
        const { hasCameraPermission, flashMode, cameraType, capturing, captures } = this.state;

        if (hasCameraPermission === null) {
            return <View />;
        } else if (hasCameraPermission === false) {
            return <Text>Access to camera has been denied.</Text>;
        }

        return (
            <React.Fragment>
                <View>
                    <Camera
                        type={cameraType}
                        flashMode={flashMode}
                        style={styles.preview}
                        ref={camera => this.camera = camera}
                    />
                </View>

                {captures.length > 0 && <Gallery captures={captures}/>}

                <Toolbar 
                    capturing={capturing}
                    flashMode={flashMode}
                    cameraType={cameraType}
                    setFlashMode={this.setFlashMode}
                    setCameraType={this.setCameraType}
                    onCaptureIn={this.handleCaptureIn}
                    onCaptureOut={this.handleCaptureOut}
                    onLongCapture={this.handleLongCapture}
                    onShortCapture={this.handleShortCapture}
                />
            </React.Fragment>
        );
    };
};

You can use react-native-camera and click multiple pictures in one go and add a button for done.您可以使用 react-native-camera 并单击一个 go 中的多张图片并添加一个完成按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 FlatList 中选择多个项目,突出显示它们并将它们保存在 React Native 中 - How to select multiple items in FlatList, highlight them and keep them saved in React Native React Native:如何将文件拆分成多个文件并导入它们? - React Native: How to split a file up into multiple files and import them? react-native-multiple-select如何使用存储的数据填充 - react-native-multiple-select how to populate with data stored 如何使用 react native 中 react native 元素库中的复选框从 flatlist 中选择多个项目? - How can select multiple items from flatlist with check box from react native elements library in react native? 如何在React Native中获取字符串的某些部分? - How to take certain parts of a string in React Native? 带有头像 React Native 的多选下拉菜单 - multiple select dropdown with avatar React Native 反应原生,select 列表中的多个项目 - React native, select multiple items from a list 如何保持 react-native-webview 的多个实例打开(并安装),同时能够在它们之间导航(使用 react-navigation) - How to keep multiple instances of react-native-webview open (and mounted) whilst being able to navigate between them (using react-navigation) 如何从输入中获取多个字符串并将它们放入同一数组中? - How to take multiple strings from inputs and place them into the same array? 如何从反应原生的数组中获取特定值 - how to take particular value from array in react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM