[英]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.