import React, { useCallback, useRef, useState } from "react"; import { Button, StyleSheet, Text, View } from "react-native"; import { Camera, useCameraPermission, useCameraDevice, useCameraFormat, PhotoFile, VideoFile, CameraRuntimeError, Orientation, // @ts-ignore } from "react-native-vision-camera"; import { RecordingButton } from "./capture-button"; import { useIsForeground } from "./is-foreground"; import { useIsFocused } from "@react-navigation/native"; export default function CameraScreen({ route, navigation }): React.ReactElement { // TODO: #73 Does this need to be passed to Camera component? // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars const { gameType, tableSize, tags, location } = route.params // LOG for params -- Remove when no longer needed // Note: camelCased value being passed, change on record.tsx if you want a different value format console.log(gameType, tableSize, tags, location) const camera = useRef(null); const { hasPermission, requestPermission } = useCameraPermission(); const [isCameraInitialized, setIsCameraInitialized] = useState(false); const isForeground = useIsForeground(); const isFocused = useIsFocused(); const isActive = isForeground && isFocused; 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)}`); }, []); const onVideoChunkReady = useCallback((event) => { console.log(`Chunk ready in react-native`, event.nativeEvent); }, []); 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 }, ]); // this sets as a target //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 ); }; // Replace with error handling if (device === null) { console.log(device); return ( Camera not available. Does user have permissions: {hasPermission} ); } return ( hasPermission && (