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

Re-open camera device, if it has been closed by Android

Open jthure opened this issue 1 year ago • 3 comments

What

This PR adds a state variable to the CameraSession which keeps track of wether the camera device is opened or if has been closed/disconnected. It fixes the problem where if you minimize the camera app for a while, the camera gets disconnected and when entering the camera app again, it wouldn't be re-opened.

Changes

  • Adds a member isOpen to CameraSession
  • isOpen is set to true during CameraManager.open and to false in the onDisconnected callback

Tested on

Tested in the example app on a Samsung Galaxy S10

Related issues

Possible related issues: #2257, #2223

jthure avatar Dec 12 '23 11:12 jthure

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2023 11:31am

vercel[bot] avatar Dec 12 '23 11:12 vercel[bot]

Hey, thanks for your PR!

To be honest I'm a bit hesitant with introducing an additional state (here, the boolean isOpen) to the codebase.

I want it to be as atomic as possible, and I think too much state can go out of sync, which leads to messy and unmaintained projects.

I am thinking if we can use the isRunning prop here? Or wrap CameraDevice with isolated state and auto-reopen it if needed?

Let's leave this PR open for now, I'll take a look at Android this & next week to make sure we're as atomic as on iOS, then everything should be stable!

mrousavy avatar Dec 12 '23 18:12 mrousavy

Hey, thanks for your PR!

To be honest I'm a bit hesitant with introducing an additional state (here, the boolean isOpen) to the codebase.

I want it to be as atomic as possible, and I think too much state can go out of sync, which leads to messy and unmaintained projects.

I am thinking if we can use the isRunning prop here? Or wrap CameraDevice with isolated state and auto-reopen it if needed?

Let's leave this PR open for now, I'll take a look at Android this & next week to make sure we're as atomic as on iOS, then everything should be stable!

I totally agree, it's not pretty. I'll try to take another look at it with your suggestions in mind :)

jthure avatar Dec 12 '23 19:12 jthure

@mrousavy I think you fixed this issue in another PR right? I'll close this one

jthure avatar Jan 31 '24 07:01 jthure

Hey yea thanks I attempted to fix this in another PR, and I think I did, but I will rewrite some of that code now anyways. Thanks again for your PR and sorry it didn't land in main! :)

mrousavy avatar Jan 31 '24 09:01 mrousavy