import { SafeAreaView, StyleSheet, Text, View } from "react-native"; import React, { useEffect, useState } from "react"; import { RootState, useAppDispatch } from "../../redux/store"; import { useSelector } from "react-redux"; import VisionCamera from "../camera/VisionCamera"; import DefaultCamera from "../camera/DefaultCamera"; import { Action } from "../../types/AOP"; import StepList from "../molecules/StepList"; import SlotList from "../molecules/SlotList"; import Button from "../atoms/Button"; import SlotListLandscape from "../molecules/SlotListLandscape"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { disableCaptureAction, setActiveScreen, setCameraSettingsToStore, setCaptureIconsActive, } from "../../redux/UtilSlice"; import { initializeRicoh, captureRicoh } from "../../redux/AppStateSlice"; import SettingsModalV2 from "../molecules/SettingsModalV2"; import { getCurrentSlot, setCurrentSlotItemAction } from "../../redux/AOPSlice"; import PreviewModal from "../molecules/PreviewModal"; import AnnotationScreen from "./AnnotationScreen"; import Grid from "../guides/Grid"; import Zoom from "../camera/Zoom"; import SlotItemActionSelector from "../molecules/SlotItemActionSelector"; import GuideManager from "../guides/GuideManager"; type CaptureStateInApp = { captureType: string; record: boolean; isRecording: boolean; photo: boolean; }; const Main = () => { const dispatch = useAppDispatch(); const [captureState, setCaptureState] = useState({ captureType: "", record: false, isRecording: false, photo: false, }); const [settingModalActive, setSettingModalActive] = useState(false); // const [widgetModalActive, setWidgetModalActive] = useState(false); const [widgetModalActive, setWidgetModalActive] = useState(false); const [currentAction, setCurrentAction] = useState(); const defaultCameraModuleRef = React.useRef>(null); const visionCameraModuleRef = React.useRef>(null); const AOPisLoaded = useSelector((state: RootState) => state.AOP.aopIsLoaded); const mainScreenBackButtonPress = useSelector( (state: RootState) => state.Util.mainScreenBackButtonPress ); const activeSlotIndex = useSelector((state: RootState) => state.AOP.activeSlotIndex); const activeStepIndex = useSelector((state: RootState) => state.AOP.activeStepIndex); const activeSlotItemIndex = useSelector((state: RootState) => state.AOP.activeSlotItemIndex); const activeSlotItemActionIndex = useSelector( (state: RootState) => state.AOP.activeSlotItemActionIndex ); const imperfectionScreen = useSelector((state: RootState) => state.AOP.imperfectionScreen); const sdkIsComponent = useSelector((state: RootState) => state.Util.sdkIsComponent); const steps = useSelector((state: RootState) => state.AOP.steps); const slotList = steps.length > 0 ? steps[activeStepIndex].slots : []; const activeSlot = useSelector(getCurrentSlot); const ricohState = useSelector((state: RootState) => state.AppState.ricohCaptureState); const captureIconsActive = useSelector((state: RootState) => state.Util.captureIconsActive); const cameraSettings = useSelector((state: RootState) => state.Util.captureSettings); const getCurrentAction = () => { if (slotList.length > 0) { const slot = slotList[activeSlotIndex]; if (slot.slotItems && slot.slotItems.length > 0) { if (activeSlotItemActionIndex >= 0) return slot.slotItems[activeSlotItemIndex].availableActions[activeSlotItemActionIndex]; else return undefined; } else { return slotList[activeSlotIndex].action; } } else return undefined; }; // const currentAction = getCurrentAction(); const { orientation, lockNavigation } = useSelector((appState: RootState) => appState.Util); useEffect(() => { if (currentAction) { setCaptureState({ captureType: (currentAction as Action).captureType, record: false, isRecording: false, photo: false, }); } }, [currentAction]); useEffect(() => { setCurrentAction(getCurrentAction()); }, [ AOPisLoaded, slotList, activeStepIndex, activeSlotIndex, activeSlotItemIndex, activeSlotItemActionIndex, ]); useEffect(() => { if ( slotList[activeSlotIndex] && slotList[activeSlotIndex].slotItems && slotList[activeSlotIndex].slotItems.length > 0 ) { if (slotList[activeSlotIndex].slotItems[activeSlotItemIndex].availableActions.length === 1) dispatch(setCurrentSlotItemAction(0)); else { dispatch(setCurrentSlotItemAction(1)); } } }, [slotList.length, activeSlotIndex, activeSlotItemIndex]); useEffect(() => { if (currentAction && currentAction.sourceType === "Ricoh" && ricohState === "NOT_CONNECTED") { dispatch(initializeRicoh()); // dispatch(loadRicohSettings()); } }, [currentAction?.sourceType, ricohState]); useEffect(() => { if (currentAction) { let ref = currentAction.vision ? visionCameraModuleRef : defaultCameraModuleRef; if (captureState?.captureType === "Image" && captureState.photo) { ref.current?.takePhoto(); dispatch(disableCaptureAction(true)); // do not allow capture action unless photo is saved on same slot item } else if ( captureState?.captureType === "Video" && captureState?.isRecording && captureState.record ) { ref.current?.startVideo(); } else if ( captureState?.captureType === "Video" && captureState?.isRecording && !captureState.record ) { ref.current?.stopVideo(); dispatch(disableCaptureAction(true)); // do not allow capture action unless photo is saved on same slot item } } }, [captureState]); const captureData = async () => { if (currentAction?.sourceType === "DeviceCamera") { if (captureState && captureState.captureType === "Image") { setCaptureState((c) => { return { ...c, photo: true, }; }); } else if (captureState && captureState.captureType === "Video") { setCaptureState((c) => { return { ...c, isRecording: true, record: !c?.record, }; }); } } else if (currentAction?.sourceType === "Ricoh") { dispatch(captureRicoh()); } }; useEffect(() => { if (!settingModalActive) { dispatch(setCameraSettingsToStore(cameraSettings)); } }, [settingModalActive]); const renderCamera = () => { return ( <> {cameraSettings.find(({ settingsKey }) => settingsKey === "grid")?.value && } {currentAction?.vision ? ( ) : ( // )} {/* */} ); }; return ( <> {(AOPisLoaded && ( {/* 0 } url={ currentAction && currentAction.guide && currentAction.guide.url ? currentAction.guide.url : "" } /> */} setWidgetModalActive((t) => !t)} forceClose={() => setWidgetModalActive(false)} /> {!widgetModalActive && ((captureIconsActive && orientation === "PORTRAIT" && ) || ( { setSettingModalActive((s) => !s); }} /> ))} {slotList.length > 0 && slotList[activeSlotIndex].slotType !== "DEFAULT" ? ( slotList[activeSlotIndex].locked ? ( The Given Slot Is Locked ) : imperfectionScreen === "annotation" ? ( setCaptureIconsActive(false)} hideBoundingBoxes={captureIconsActive} onBackgroundPressCallback={() => dispatch(setCaptureIconsActive(!captureIconsActive)) } onSubmitCallback={() => dispatch(setCaptureIconsActive(true))} hideBackButton openAsComponent /> ) : ( renderCamera() ) ) : currentAction?.sourceType === "Ricoh" ? ( Ricoh Capture State {ricohState} ) : ( renderCamera() )} {slotList.length > 0 && slotList[activeSlotIndex].slotType !== "DEFAULT" && imperfectionScreen === "annotation" && (