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

🐛 onInitialized seems to be called too early on Android

Open gary-cohen opened this issue 2 years ago • 4 comments

What were you trying to do?

On some Android devices (Google Pixel 2) the camera returns from onInitialized yet doesn't seem ready to capture. If I put a setTimeout of 500ms before allowing takePhoto to be called it helps on the faster devices but not on the Pixel 2. I can continue to tweak the timeout, but I'm hoping you see what the issue could be.

Reproduceable Code

No response

What happened instead?

The camera doesn't take a photo, or when running in Waldo, the screen stays black (see below, the upper row is using react-native-camera and the second row is react-native-vision-camera). Screen Shot 2022-05-19 at 13 40 05

Relevant log output

No response

Device

Pixel 2, Galaxy S10

VisionCamera Version

2.13.3

Additional information

gary-cohen avatar May 19 '22 11:05 gary-cohen

Huh that's interesting, I'm not sure if there is a native event that we need to wait for here: https://github.com/mrousavy/react-native-vision-camera/blob/83943da112fdbaf284dc2f925283754223eda9cf/android/src/main/java/com/mrousavy/camera/CameraView.kt#L499-L508

mrousavy avatar May 24 '22 11:05 mrousavy

@mrousavy I'm not sure exactly (your code seems to look ok). I did see this which could be useful to know when the preview is streaming (which might be the event we could key off of). https://stackoverflow.com/questions/69401931/android-how-to-get-a-callback-in-camerax-when-the-camera-device-has-finished-op

gary-cohen avatar May 24 '22 11:05 gary-cohen

@mrousavy just checking up with this... do you think we could get an event with the preview is streaming? I think that will do what I'm looking for.

gary-cohen avatar Aug 06 '22 17:08 gary-cohen

I think that's implied with a Frame Processor, I'll have a look if that also works if the FP use case is not attached...

mrousavy avatar Aug 07 '22 23:08 mrousavy

Hey! I've rewritten the entire Android codebase of VisionCamera from CameraX to Camera2 in the efforts of ✨ VisionCamera V3.

I just now completed the Camera2 rewrite and I believe the core structure is running, but there might be some edge cases to iron out. Can you try and test the PR #1674 for me to see if you can still reproduce this issue here?

Here's an instruction on how you can test that: https://github.com/mrousavy/react-native-vision-camera/pull/1674#issuecomment-1684104217

If the issue cannot be reproduced with that version/PR anymore, then hoorayy, I fixed it! 🎉 Otherwise please let me know and I'll keep this issue open to keep track of it.

Thank you!

mrousavy avatar Aug 18 '23 16:08 mrousavy

Thanks @mrousavy. I'll try to find some time to integrate the new code in the coming days/weeks. Thanks again for all of your work on this. 🙏

gary-cohen avatar Aug 18 '23 17:08 gary-cohen