skywrace

feat: Install react-native-vision-camera module and handle media permissions

......@@ -9,110 +9,39 @@
*/
import {NativeBaseProvider} from 'native-base';
import React from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
const Section: React.FC<{
title: string;
}> = ({children, title}) => {
const isDarkMode = useColorScheme() === 'dark';
return (
<View style={styles.sectionContainer}>
<Text
style={[
styles.sectionTitle,
{
color: isDarkMode ? Colors.white : Colors.black,
},
]}>
{title}
</Text>
<Text
style={[
styles.sectionDescription,
{
color: isDarkMode ? Colors.light : Colors.dark,
},
]}>
{children}
</Text>
</View>
);
};
import React, {useLayoutEffect} from 'react';
import {SafeAreaView} from 'react-native';
import {Camera, useCameraDevices} from 'react-native-vision-camera';
const App = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
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>
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Section title="Step One">
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
screen and then come back to see your edits.
</Section>
<Section title="See Your Changes">
<ReloadInstructions />
</Section>
<Section title="Debug">
<DebugInstructions />
</Section>
<Section title="Learn More">
Read the docs to discover what to do next:
</Section>
<LearnMoreLinks />
</View>
</ScrollView>
<SafeAreaView>
{device && <Camera isActive device={device} />}
</SafeAreaView>
</NativeBaseProvider>
);
};
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
},
highlight: {
fontWeight: '700',
},
});
export default App;
......
......@@ -2,6 +2,8 @@
package="com.detectapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:name=".MainApplication"
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
......@@ -37,6 +37,10 @@
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your Camera.</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your Microphone.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
......
......@@ -356,6 +356,10 @@ PODS:
- RNSVG (12.3.0):
- React-Core
- SocketRocket (0.6.0)
- VisionCamera (2.13.3):
- React
- React-callinvoker
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
......@@ -417,6 +421,7 @@ DEPENDENCIES:
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNSVG (from `../node_modules/react-native-svg`)
- VisionCamera (from `../node_modules/react-native-vision-camera`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
SPEC REPOS:
......@@ -502,6 +507,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
RNSVG:
:path: "../node_modules/react-native-svg"
VisionCamera:
:path: "../node_modules/react-native-vision-camera"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"
......@@ -552,6 +559,7 @@ SPEC CHECKSUMS:
ReactCommon: bf2888a826ceedf54b99ad1b6182d1bc4a8a3984
RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
VisionCamera: c1c171fcdbf18c438987847f785829c5638f3a4c
Yoga: 17cd9a50243093b547c1e539c749928dd68152da
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
......
......@@ -14,7 +14,8 @@
"react": "17.0.2",
"react-native": "0.68.1",
"react-native-safe-area-context": "^4.2.5",
"react-native-svg": "^12.3.0"
"react-native-svg": "^12.3.0",
"react-native-vision-camera": "^2.13.3"
},
"devDependencies": {
"@babel/core": "^7.12.9",
......
......@@ -6706,6 +6706,11 @@ react-native-svg@^12.3.0:
css-select "^4.2.1"
css-tree "^1.0.0-alpha.39"
react-native-vision-camera@^2.13.3:
version "2.13.3"
resolved "https://registry.yarnpkg.com/react-native-vision-camera/-/react-native-vision-camera-2.13.3.tgz#cacd20b7f3fd777691496f007a47a34c02be93be"
integrity sha512-aikp6kNmb9b8lsVFKEKCBgch5h93Cs8Qqw/bSZsn/dO+Qa4uktpe89WIO1VTs88d40vJiLeYFlbyWe589E/UuA==
react-native@0.68.1:
version "0.68.1"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.68.1.tgz#c3d92f89028cdc2453fe7cd2d532b3f68d1c27c8"
......