Вы можете визуализировать камеру, но скрывая <View>
и <RNCamera>
.
Я сделал этот код для этого:
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { RNCamera } from 'react-native-camera';
export default class App extends Component {
takePicture = async () => {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
console.log(data.uri); // log picture encoded in base64 data format.
}
};
componentDidMount() {
setTimeout(() => this.takePicture(), 500); // delay while camera is loading, then take picture.
}
render() {
return (
<View style={styles.container}>
<RNCamera
style={styles.camera}
ref={ref => { this.camera = ref; }}
type={RNCamera.Constants.Type.front}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
height: 1,
width: 1,
opacity: 0,
},
camera: {
height: 1,
width: 1,
opacity: 0,
},
});