Skip to content

Instantly share code, notes, and snippets.

@fustkilas
Created April 23, 2019 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fustkilas/9b70e7111b3948515b897020e8659bbd to your computer and use it in GitHub Desktop.
Save fustkilas/9b70e7111b3948515b897020e8659bbd to your computer and use it in GitHub Desktop.
import React from "react";
import { Text, View, TouchableOpacity, Image } from "react-native";
import { Camera, Permissions } from "expo";
export default class CameraExample extends React.Component {
state = {
hasCameraPermission: null,
type: Camera.Constants.Type.back
};
async componentDidMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ hasCameraPermission: status === "granted" });
}
render() {
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View />;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (
<View style={{ flex: 1 }}>
<Camera
style={{ flex: 1 }}
type={this.state.type}
flashMode={Camera.Constants.FlashMode.on}
autoFocus={Camera.Constants.AutoFocus.off}
>
<View
style={{
flex: 1,
backgroundColor: "rgba(255, 0, 0, 0.4)",
flexDirection: "row"
}}
>
<TouchableOpacity
style={{
flex: 1,
alignSelf: "center",
alignItems: "center"
}}
onPress={() => {
this.setState({
type:
this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
});
}}
>
<Image
source={require("./crosshair.png")}
style={{ width: 200, height: 200 }}
/>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment