App.tsx
1.31 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import {NativeBaseProvider, Text} from 'native-base';
import React, {useLayoutEffect} from 'react';
import {StyleSheet} from 'react-native';
import {Camera, useCameraDevices} from 'react-native-vision-camera';
const App = () => {
const devices = useCameraDevices();
const device = devices.front;
useLayoutEffect(() => {
(async () => {
const [cameraPermission, micPermission] = await Promise.all([
Camera.getCameraPermissionStatus(),
Camera.getMicrophonePermissionStatus(),
]);
const requests: (() => Promise<unknown>)[] = [];
if (cameraPermission !== 'authorized') {
requests.push(Camera.requestCameraPermission);
}
if (micPermission !== 'authorized') {
requests.push(Camera.requestMicrophonePermission);
}
await Promise.all(requests.map(request => request()));
})();
}, []);
return (
<NativeBaseProvider>
{device ? (
<Camera isActive device={device} style={StyleSheet.absoluteFill} />
) : (
<Text>Loading camera..</Text>
)}
</NativeBaseProvider>
);
};
export default App;