react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 Tap to Focus Doesn't work on Android

Open NuraQ opened this issue 1 year ago • 4 comments

What's happening?

Whenever I try to call focus function I get the following error message in the catch statement "session/camera-not-ready: [session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback!]" . Although Camera is ready onInitialized is actually triggered

Reproduceable Code

const device = useCameraDevice('back');
....
    const touchToFocus = async (event) => {
        if (!device.supportsFocus || !isCameraFocusReady.current) return;
        let point = {
            x: Math.round(event.pageX - camLocation.x),
            y: Math.round(event.pageY - camLocation.y)
        };
        try {
            isCameraFocusReady.current = false;
            await cameraRef?.current?.focus(point);
            setTimeout(() => {
                isCameraFocusReady.current = true;
            }, 200);
        } catch (error) {
            console.log(error)
        }
    };
.....
    <Camera
      format={format}
      isActive={!paused}
      photo={true}
      orientation={'portrait'}
      focusable={true}
      ref={cameraRef}
      enableHighQualityPhotos={true}
      fps={fps}
      preset='photo'
      enableZoomGesture={true}
      onLayout={handleCameraLayout}
      device={device}
      zoom={device.neutralZoom}
      style={{ flex: 1 }}
       onTouchEnd={(x) => touchToFocus(x.nativeEvent)}
     />

Relevant log output

session/camera-not-ready: [session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback!]

Camera Device

{"sensorOrientation":
"landscape-right",
"hardwareLevel": "full",
"maxZoom": 8,
"minZoom":1,
"supportsLowLightBoost":false,
"neutralZoom":1,
"physicalDevices":["wide-angle-camera"],
"supportsFocus":true,
"supportsRawCapture" true,
"isMultiCam":false,
"name":"BACK(0)",
"hasFlash" true,
"has Torch" true,
"position":"back",
"id":"0"}

Device

OnePlus 5T, Android version 10

VisionCamera Version

3.6.11

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

NuraQ avatar Nov 30 '23 08:11 NuraQ

I am having the same issue, not using expo btw.

nemmtor avatar Nov 30 '23 18:11 nemmtor

Same issue, works fine on ios

karel-suchomel-ed avatar Dec 06 '23 16:12 karel-suchomel-ed

Has someone found any solution for this?

M4Tdev avatar Dec 15 '23 10:12 M4Tdev

Here is the the answer from @mrousavy in another issue: #2003

M4Tdev avatar Dec 15 '23 11:12 M4Tdev

Yea - duplicate of https://github.com/mrousavy/react-native-vision-camera/issues/2003.

mrousavy avatar Jan 30 '24 16:01 mrousavy