Last active
June 5, 2020 21:54
-
-
Save singh100ful/d6b39f2275a3f18ca119fa0d07cd9efb to your computer and use it in GitHub Desktop.
React Native Camera
This file contains hidden or 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, {Component} from 'react'; | |
import {RNCamera} from 'react-native-camera'; | |
import {View, TouchableOpacity, Text} from 'react-native'; | |
export class App extends Component { | |
takePicture = async () => { | |
if (this.camera) { | |
const options = { width: 500, quality: 0.5 }; | |
const data = await this.camera.takePictureAsync(options); | |
console.log(data.uri); | |
} | |
}; | |
render(){ | |
return( | |
<View style={{flex: 1}}> | |
<View style={{flex: 6, backgroundColor: '#DB353A'}}> | |
<RNCamera | |
ref={ref => { | |
this.camera = ref; | |
}} | |
style={{flex: 1, alignItems: 'center'}} | |
androidCameraPermissionOptions={{ | |
title: 'Permission to use camera', | |
message: 'We need your permission to use your camera', | |
buttonPositive: 'Ok', | |
buttonNegative: 'Cancel', | |
}} | |
androidRecordAudioPermissionOptions={{ | |
title: 'Permission to use audio recording', | |
message: 'We need your permission to use your audio', | |
buttonPositive: 'Ok', | |
buttonNegative: 'Cancel', | |
}} | |
/> | |
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}> | |
<TouchableOpacity onPress={this.clickPicture}> | |
<Text style={{ fontSize: 14 }}> Click </Text> | |
</TouchableOpacity> | |
</View> | |
</View> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment