-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
102 lines (86 loc) · 2.15 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import type {Node} from 'react';
import React, {useCallback, useEffect} from 'react';
import {
Button,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import {
Camera,
useCameraDevices,
useFrameProcessor,
} from 'react-native-vision-camera';
import RNRestart from 'react-native-restart'; // Import package from node modules
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const Section = ({children, title}): Node => {
const isDarkMode = useColorScheme() === 'dark';
const devices = useCameraDevices();
const device = devices.back;
const frameProcessor = useFrameProcessor(frame => {
'worklet';
console.log('Hello from frame processor');
}, []);
useEffect(() => {
(async () => {
const cameraPermission = await Camera.getCameraPermissionStatus();
if (cameraPermission !== 'authorized') {
const newCameraPermission = await Camera.requestCameraPermission();
console.log({newCameraPermission});
}
})();
});
return (
<View style={{flex:1}}>
{device ? (
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
frameProcessor={frameProcessor}
frameProcessorFps={1}
/>
) : (
<Text>No device yet!</Text>
)}
</View>
);
};
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
flex: 1,
};
const handleRestart = useCallback(() => {
RNRestart.Restart();
}, []);
return (
<SafeAreaView style={backgroundStyle}>
<Button title="RESTART" onPress={handleRestart} />
<Section />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
});
export default App;