Skip to content

Instantly share code, notes, and snippets.

@simistern
Last active July 14, 2020 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simistern/0c160061bcd216cb5b86033af5a6f860 to your computer and use it in GitHub Desktop.
Save simistern/0c160061bcd216cb5b86033af5a6f860 to your computer and use it in GitHub Desktop.
'use strict';
import React, { PureComponent, useState, useEffect } from 'react';
import { AppRegistry, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { RNCamera } from 'react-native-camera';
import Permissions from 'react-native-permissions';
const CameraApp = () => {
let [flash, setFlash] = useState('off')
let [zoom, setZoom] = useState(0)
let [autoFocus, setAutoFocus] = useState('on')
let [depth, setDepth] = useState(0)
let [type, setType] = useState('back')
let [permission, setPermission] = useState('undetermined')
useEffect(() => {
Permissions.check('photo').then(response => {
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
setPermission(response);
});
}, []);
toggleFlash() {
setFlash(flashModeOrder[flash])
}
zoomOut() {
setZoom(zoom - 0.1 < 0 ? 0 : zoom - 0.1)
}
zoomIn() {
setZoom(zoom + 0.1 > 1 ? 1 : zoom + 0.1);
}
takePicture = async() => {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePicture(options);
console.log(data.uri);
}
};
render() {
return (
<View style={styles.container}>
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={type}
flashMode={flash}
/>
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}>
<TouchableOpacity onPress={this.takePicture.bind(this)} style={styles.capture}>
<Text style={{ fontSize: 14 }}> SNAP </Text>
</TouchableOpacity>
</View>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment