import React, { useCallback, useRef, useState } from 'react' import { Button, StyleSheet, Text, View } from 'react-native' import { Camera, useCameraPermission, useCameraDevice, useCameraFormat, PhotoFile, VideoFile, CameraRuntimeError, Orientation } from 'react-native-vision-camera' import { RecordingButton } from './capture-button' import { useIsForeground } from './is-foreground' export default function CameraScreen(): React.ReactElement { const camera = useRef(null) const { hasPermission, requestPermission } = useCameraPermission() const [isCameraInitialized, setIsCameraInitialized] = useState(false) const isForeground = useIsForeground() const isActive = isForeground const onError = useCallback((error: CameraRuntimeError) => { console.error(error) }, []) const onInitialized = useCallback(() => { console.log('Camera initialized!') setIsCameraInitialized(true) }, []) const onMediaCaptured = useCallback( (media: PhotoFile | VideoFile) => { console.log(`Media captured! ${JSON.stringify(media)}`) }, [], ) if (!hasPermission) { requestPermission() // Error handling in case they refuse to give permission } const device = useCameraDevice('back') const format = useCameraFormat(device, [ { videoResolution: { width: 3048, height: 2160 } }, { fps: 60 } ]) //Orientation detection const [orientation, setOrientation] = useState('portrait'); const toggleOrientation = () => { setOrientation(currentOrientation => currentOrientation === 'landscape-left' ? 'portrait' : 'landscape-left' // Can adjust this and the type to match what we want ); }; if (device === null) { return Camera not available. Does user have permissions: {hasPermission} } return ( hasPermission && (