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

fix: properly close Camera session

Open xseignard opened this issue 7 months ago • 2 comments

What

This PR properly closes the Camera session when the Camera view is unmounted

Changes

I rely on the local boolean isMounted and when false then close the Camera session.

I tried the same with View inherited isAttachedToWindow but somehow it is not up to date when update is called.

Tested on

Pixel 5, API 33: navigating between screens (one using front camera, the other using back camera)

Related issues

Fixes: #1958 Maybe: #2149 Maybe: #2152

xseignard avatar Nov 14 '23 07:11 xseignard

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 Nov 14, 2023 7:31am

vercel[bot] avatar Nov 14 '23 07:11 vercel[bot]

I have few questions:

override fun onAttachedToWindow() {
  if (!isMounted) {
    isMounted = true
    invokeOnViewReady()
  }
  update()
  super.onAttachedToWindow()
}

On this code, it seems you use the isMounted flag to ensure calling invokeOnViewReady only once.

But that would mean that onAttachedToWindow can be called more than once then, right? In that case, should we re-configre (with the update call) the Camera session?

xseignard avatar Nov 14 '23 09:11 xseignard