Forked from simistern/gist:0c160061bcd216cb5b86033af5a6f860
Created
September 20, 2019 17:34
-
-
Save umayr/781ccbaa3fad90908e25de5b9176c510 to your computer and use it in GitHub Desktop.
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
'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