Last active
July 14, 2020 19:15
-
-
Save simistern/ec000a33e7f4e9a72f9397dac6bb501b to your computer and use it in GitHub Desktop.
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
'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') | |
let cameraRef = useRef(null) | |
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 (cameraRef) { | |
const options = { quality: 0.5, base64: true }; | |
const data = await cameraRef.current.takePictureAsync(soptions); | |
console.log(data.uri); | |
} | |
}; | |
return ( | |
<View style={styles.container}> | |
<RNCamera | |
ref={cameraRef} | |
style={styles.preview} | |
type={type} | |
flashMode={flash} | |
/> | |
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}> | |
<TouchableOpacity onPress={takePicture} 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