-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
111 lines (88 loc) · 2.18 KB
/
App.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
'use strict';
import React, { Component } from 'react';
import { Platform, View, Text, StyleSheet } from 'react-native';
import Permissions from 'react-native-permissions'
import Camera from './Camera';
const RNFS = require('react-native-fs');
export default class App extends Component {
constructor() {
super()
this.state = {
WRITE_EXTERNAL_STORAGE: "",
CAMERA: "",
RECORD_AUDIO: ""
}
}
async requestPermission() {
this.requestPermissionCamera();
}
async requestPermissionCamera() {
Permissions.request('camera').then(response => {
console.log("camera.response", response)
this.setState({
CAMERA: response,
})
if (response === 'authorized') {
this.requestPermissionStorage();
} else {
this.requestPermissionCamera();
}
})
}
async requestPermissionStorage() {
Permissions.request('storage').then(response => {
console.log("storage.response", response)
this.setState({
WRITE_EXTERNAL_STORAGE: response,
})
if (response === 'authorized') {
this.requestPermissionMicrophone();
} else {
this.requestPermissionStorage();
}
})
}
async requestPermissionMicrophone() {
Permissions.request('microphone').then(response => {
console.log("microphone.response", response)
this.setState({
RECORD_AUDIO: response,
})
if (response === 'authorized') {
} else {
this.requestPermissionMicrophone();
}
})
}
componentDidMount() {
this.requestPermission();
}
render() {
if (this.state.WRITE_EXTERNAL_STORAGE === 'authorized' && this.state.CAMERA === 'authorized' && this.state.RECORD_AUDIO === 'authorized') {
return <Camera />
} else {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Permissions Required</Text>
</View>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});