react-native-vision-camera
react-native-vision-camera copied to clipboard
Re-open camera device, if it has been closed by Android
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
toCameraSession
-
isOpen
is set totrue
duringCameraManager.open
and to false in theonDisconnected
callback
Tested on
Tested in the example app on a Samsung Galaxy S10
Related issues
Possible related issues: #2257, #2223
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 |
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!
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 wrapCameraDevice
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 :)
@mrousavy I think you fixed this issue in another PR right? I'll close this one
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! :)