Last active
April 23, 2019 13:22
-
-
Save leleofg/05a94ac6788dea888e22099a9b3f8e21 to your computer and use it in GitHub Desktop.
camera.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import { StyleSheet, TouchableOpacity, Text } from "react-native"; | |
import { RNCamera } from "react-native-camera"; | |
export default Camera = () => { | |
const [imageUri, setImageUri] = useState(null); | |
takePicture = async () => { | |
try { | |
if (this.camera) { | |
const options = { | |
quality: 0.5, | |
base64: true, | |
forceUpOrientation: true, | |
fixOrientation: true | |
}; | |
const { uri } = await this.camera.takePictureAsync(options); | |
setImageUri(uri); | |
alert("ok"); | |
} | |
} catch (err) { | |
alert(err.message); | |
} | |
} | |
return ( | |
<RNCamera | |
ref={camera => { this.camera = camera; }} | |
style={styles.camera} | |
type={RNCamera.Constants.Type.front} | |
autoFocus={RNCamera.Constants.AutoFocus.on} | |
flashMode={RNCamera.Constants.FlashMode.off} | |
permissionDialogTitle={"Permission to use camera"} | |
permissionDialogMessage={"We need your permission to use your camera phone"} | |
> | |
<TouchableOpacity onPress={takePicture} style={styles.button}> | |
<Text>PICTURE</Text> | |
</TouchableOpacity> | |
</RNCamera> | |
) | |
} | |
const styles = StyleSheet.create({ | |
camera: { | |
flex: 1 | |
}, | |
button: { | |
alignSelf: "center", | |
backgroundColor: "blue", | |
color: "#fff" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment