Skip to content

Instantly share code, notes, and snippets.

@singh100ful
Last active June 5, 2020 21:54
Show Gist options
  • Save singh100ful/d6b39f2275a3f18ca119fa0d07cd9efb to your computer and use it in GitHub Desktop.
Save singh100ful/d6b39f2275a3f18ca119fa0d07cd9efb to your computer and use it in GitHub Desktop.
React Native Camera
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