App.tsx 1.25 KB
/**
 * 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} from 'native-base';
import React, {useLayoutEffect} from 'react';
import {SafeAreaView} 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>
      <SafeAreaView>
        {device && <Camera isActive device={device} />}
      </SafeAreaView>
    </NativeBaseProvider>
  );
};

export default App;