2021-10-05 04:22:14 -06:00
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
|
|
import { PermissionsPage } from './PermissionsPage';
|
|
|
|
import { MediaPage } from './MediaPage';
|
|
|
|
import { CameraPage } from './CameraPage';
|
|
|
|
import type { Routes } from './Routes';
|
|
|
|
import { Camera, CameraPermissionStatus } from 'react-native-vision-camera';
|
2023-02-13 07:22:45 -07:00
|
|
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
2021-10-05 04:22:14 -06:00
|
|
|
|
|
|
|
const Stack = createNativeStackNavigator<Routes>();
|
|
|
|
|
|
|
|
export function App(): React.ReactElement | null {
|
|
|
|
const [cameraPermission, setCameraPermission] = useState<CameraPermissionStatus>();
|
|
|
|
const [microphonePermission, setMicrophonePermission] = useState<CameraPermissionStatus>();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
Camera.getCameraPermissionStatus().then(setCameraPermission);
|
|
|
|
Camera.getMicrophonePermissionStatus().then(setMicrophonePermission);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
console.log(`Re-rendering Navigator. Camera: ${cameraPermission} | Microphone: ${microphonePermission}`);
|
|
|
|
|
|
|
|
if (cameraPermission == null || microphonePermission == null) {
|
|
|
|
// still loading
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const showPermissionsPage = cameraPermission !== 'authorized' || microphonePermission === 'not-determined';
|
|
|
|
return (
|
|
|
|
<NavigationContainer>
|
2023-02-13 07:22:45 -07:00
|
|
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
|
|
<Stack.Navigator
|
|
|
|
screenOptions={{
|
|
|
|
headerShown: false,
|
|
|
|
statusBarStyle: 'dark',
|
|
|
|
animationTypeForReplace: 'push',
|
2021-10-05 04:22:14 -06:00
|
|
|
}}
|
2023-02-13 07:22:45 -07:00
|
|
|
initialRouteName={showPermissionsPage ? 'PermissionsPage' : 'CameraPage'}>
|
|
|
|
<Stack.Screen name="PermissionsPage" component={PermissionsPage} />
|
|
|
|
<Stack.Screen name="CameraPage" component={CameraPage} />
|
|
|
|
<Stack.Screen
|
|
|
|
name="MediaPage"
|
|
|
|
component={MediaPage}
|
|
|
|
options={{
|
|
|
|
animation: 'none',
|
|
|
|
presentation: 'transparentModal',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Stack.Navigator>
|
|
|
|
</GestureHandlerRootView>
|
2021-10-05 04:22:14 -06:00
|
|
|
</NavigationContainer>
|
|
|
|
);
|
|
|
|
}
|