Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
434 stars 143 forks source link

Camera remains in use after navigating away #145

Open jdarwood007 opened 8 months ago

jdarwood007 commented 8 months ago

While using the barcode scanner, the device will indicate the camera is in use. On iOS that is a green light in the upper right corner.

However when I navigate away from the page, the green light remains, indicating the camera is still in use.

I created a sample app to test this: https://github.com/jdarwood007/ZXingTest I tried a few different ideas I had to stop the camera and no change. I confirmed that the methods are triggering.

I suspect that exposing the Dispose method may allow this to fix.

DetectorMetal commented 7 months ago

I found this same issue. Camera remains on and events keep triggering even after navigating away from the page. The green light remains on indicating the camera is still active. Setting IsEnabled = false after a successful scan does not fix this.

Adrianotiger commented 7 months ago

It seems that not everything is released once you navigate away. I have the opposite problem: Once I navigate away, the camera is turned off and the library is not able to acquire the camera again when I navigate on the same page.

My workaround: Open the scanning page as modal with Shell.Current.Navigation.PushModalAsync(new ScanPage()); So, the entire page is disposed once I leave it.

DetectorMetal commented 7 months ago

I tried your workaround and the camera still remains on after Pushing the scanning page as modal and then Popping the modal. The green light is still on, and it's still actively scanning. I added a haptic feedback upon scan, that is how i am sure it is triggering even after leaving the scanning page.

jdarwood007 commented 7 months ago

I had a little time so I downloaded the libraries and exposed the Dispose calls. I was able to get it to do that, but when returning to the page, it won't restart the camera, just a still of the last thing the camera saw before Dispose was called. I ran out of time to continue messing with this and had to move on to other things.

RobFrancisAu commented 3 months ago

Had the same issue. Add this to the constructor of the page that is using the barcode reader.

Unloaded += (sender, e) => { cameraBarcodeReaderView?.Handler?.DisconnectHandler(); };

Source /Credit : https://github.com/Redth/ZXing.Net.Maui/issues/118#issuecomment-1540628217