2021-10-05 04:22:14 -06:00
|
|
|
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
|
2021-02-19 10:33:35 -07:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
2021-06-07 05:08:40 -06:00
|
|
|
import { ImageRequireSource, Linking } from 'react-native';
|
2021-02-19 10:12:07 -07:00
|
|
|
|
2021-02-20 09:07:10 -07:00
|
|
|
import { StyleSheet, View, Text, Image } from 'react-native';
|
2021-02-19 10:12:07 -07:00
|
|
|
import { Camera, CameraPermissionStatus } from 'react-native-vision-camera';
|
2021-02-19 10:33:35 -07:00
|
|
|
import { CONTENT_SPACING, SAFE_AREA_PADDING } from './Constants';
|
2021-10-05 04:22:14 -06:00
|
|
|
import type { Routes } from './Routes';
|
2021-02-19 10:12:07 -07:00
|
|
|
|
2021-02-23 03:57:43 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-03-03 10:56:06 -07:00
|
|
|
const BANNER_IMAGE = require('../../docs/static/img/11.png') as ImageRequireSource;
|
2021-02-23 03:57:43 -07:00
|
|
|
|
2021-10-05 04:22:14 -06:00
|
|
|
type Props = NativeStackScreenProps<Routes, 'PermissionsPage'>;
|
|
|
|
export function PermissionsPage({ navigation }: Props): React.ReactElement {
|
2021-02-20 09:07:10 -07:00
|
|
|
const [cameraPermissionStatus, setCameraPermissionStatus] = useState<CameraPermissionStatus>('not-determined');
|
|
|
|
const [microphonePermissionStatus, setMicrophonePermissionStatus] = useState<CameraPermissionStatus>('not-determined');
|
2021-02-19 10:12:07 -07:00
|
|
|
|
2021-02-19 10:33:35 -07:00
|
|
|
const requestMicrophonePermission = useCallback(async () => {
|
|
|
|
console.log('Requesting microphone permission...');
|
|
|
|
const permission = await Camera.requestMicrophonePermission();
|
|
|
|
console.log(`Microphone permission status: ${permission}`);
|
2021-06-07 05:08:40 -06:00
|
|
|
|
2021-10-05 04:22:14 -06:00
|
|
|
if (permission === 'denied') await Linking.openSettings();
|
2021-02-19 10:33:35 -07:00
|
|
|
setMicrophonePermissionStatus(permission);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const requestCameraPermission = useCallback(async () => {
|
|
|
|
console.log('Requesting camera permission...');
|
|
|
|
const permission = await Camera.requestCameraPermission();
|
|
|
|
console.log(`Camera permission status: ${permission}`);
|
2021-06-07 05:08:40 -06:00
|
|
|
|
2021-10-05 04:22:14 -06:00
|
|
|
if (permission === 'denied') await Linking.openSettings();
|
2021-02-19 10:33:35 -07:00
|
|
|
setCameraPermissionStatus(permission);
|
|
|
|
}, []);
|
|
|
|
|
2021-02-19 10:12:07 -07:00
|
|
|
useEffect(() => {
|
2021-10-05 04:22:14 -06:00
|
|
|
if (cameraPermissionStatus === 'authorized' && microphonePermissionStatus === 'authorized') navigation.replace('CameraPage');
|
|
|
|
}, [cameraPermissionStatus, microphonePermissionStatus, navigation]);
|
2021-02-19 10:33:35 -07:00
|
|
|
|
2021-02-19 10:12:07 -07:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2021-02-23 03:57:43 -07:00
|
|
|
<Image source={BANNER_IMAGE} style={styles.banner} />
|
2021-02-19 10:17:37 -07:00
|
|
|
<Text style={styles.welcome}>Welcome to{'\n'}Vision Camera.</Text>
|
2021-02-19 10:33:35 -07:00
|
|
|
<View style={styles.permissionsContainer}>
|
|
|
|
{cameraPermissionStatus !== 'authorized' && (
|
2021-02-20 09:07:10 -07:00
|
|
|
<Text style={styles.permissionText}>
|
2022-07-18 02:40:56 -06:00
|
|
|
Vision Camera needs <Text style={styles.bold}>Camera permission</Text>.{' '}
|
2021-02-20 09:07:10 -07:00
|
|
|
<Text style={styles.hyperlink} onPress={requestCameraPermission}>
|
|
|
|
Grant
|
|
|
|
</Text>
|
|
|
|
</Text>
|
2021-02-19 10:33:35 -07:00
|
|
|
)}
|
2021-09-11 11:55:25 -06:00
|
|
|
{microphonePermissionStatus !== 'authorized' && (
|
2021-02-20 09:07:10 -07:00
|
|
|
<Text style={styles.permissionText}>
|
2022-07-18 02:40:56 -06:00
|
|
|
Vision Camera needs <Text style={styles.bold}>Microphone permission</Text>.{' '}
|
2021-02-20 09:07:10 -07:00
|
|
|
<Text style={styles.hyperlink} onPress={requestMicrophonePermission}>
|
|
|
|
Grant
|
|
|
|
</Text>
|
|
|
|
</Text>
|
2021-02-19 10:33:35 -07:00
|
|
|
)}
|
|
|
|
</View>
|
2021-02-19 10:12:07 -07:00
|
|
|
</View>
|
|
|
|
);
|
2021-10-05 04:22:14 -06:00
|
|
|
}
|
2021-02-19 10:12:07 -07:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2021-02-19 10:17:37 -07:00
|
|
|
welcome: {
|
|
|
|
fontSize: 38,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
maxWidth: '80%',
|
|
|
|
},
|
|
|
|
banner: {
|
|
|
|
position: 'absolute',
|
|
|
|
opacity: 0.4,
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
},
|
2021-02-19 10:12:07 -07:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: 'white',
|
2021-02-20 09:07:10 -07:00
|
|
|
...SAFE_AREA_PADDING,
|
2021-02-19 10:12:07 -07:00
|
|
|
},
|
2021-02-19 10:33:35 -07:00
|
|
|
permissionsContainer: {
|
2021-02-20 09:07:10 -07:00
|
|
|
marginTop: CONTENT_SPACING * 2,
|
2021-02-19 10:33:35 -07:00
|
|
|
},
|
|
|
|
permissionText: {
|
|
|
|
fontSize: 17,
|
|
|
|
},
|
|
|
|
hyperlink: {
|
|
|
|
color: '#007aff',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
},
|
|
|
|
bold: {
|
|
|
|
fontWeight: 'bold',
|
2021-02-19 10:12:07 -07:00
|
|
|
},
|
|
|
|
});
|