-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcamera.js
More file actions
90 lines (82 loc) · 2.36 KB
/
camera.js
File metadata and controls
90 lines (82 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React from 'react'
import { Text, View, TouchableOpacity, StyleSheet } from 'react-native'
import { Camera, Permissions } from 'expo'
import {inject} from 'mobx-react'
@inject('people')
export default class CameraExample extends React.Component {
state = {
hasCameraPermission: null,
type: Camera.Constants.Type.back,
}
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA)
this.setState({ hasCameraPermission: status === 'granted' })
}
flipCamera = () => {
this.setState({
type: this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back,
})
}
takePicture = async () => {
if (this.camera) {
let photo = await this.camera.takePictureAsync({base64: true})
await this.props.people.updateAvatar(photo.base64, this.props.uid)
this.props.goBack()
}
}
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={styles.camera} type={this.state.type} ref={ref => { this.camera = ref }}>
<View style={styles.textContainer}>
<TouchableOpacity style={styles.flip} onPress={this.flipCamera}>
<Text style={styles.flipText}>
{' '}Flip{' '}
</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this.takePicture} />
</View>
</Camera>
</View>
)
}
}
}
const styles = StyleSheet.create({
textContainer: {
backgroundColor: 'rgba(255, 255, 255, 0.3)',
flexDirection: 'row',
height: 100,
width: '100%',
justifyContent: 'space-around',
alignItems: 'center'
},
flip: {
flex: 0.1,
alignItems: 'center'
},
flipText: {
fontSize: 18,
marginBottom: 10,
color: 'white'
},
button: {
height: 60,
width: 60,
borderRadius: 100,
backgroundColor: 'red'
},
camera: {
flex: 1,
alignItems: 'flex-end',
justifyContent: 'flex-end'
}
})