capawesome-team / capacitor-mlkit

⚡️ ML Kit plugins for Capacitor. Supports Android and iOS.
https://capawesome.io/plugins/mlkit/
Apache License 2.0
129 stars 35 forks source link

feat: New Observable for when Camera has been initalized #158

Open derekdavieUH opened 3 weeks ago

derekdavieUH commented 3 weeks ago

Plugin(s)

Current problem

I am trying to save the state of the torch so that when a user re-opens the camera the torch is set to the same state as when they last closed the camera. However, if I enable to torch right after opening the camera, the torch flashes but does not stay on. If I add a 200ms delay the torch stays on as expected. I suspect this is because the torch is being turned on before the camera is finished being initialized/open and when it is open it defaults the torch to be off.

Preferred solution

An observable for the camera being initalized and/or opened would be a more elegant and reliable solution. I worry that with older and slower deviced the 200ms delay won't be enough, but I don't want to increase that delay to the point it's noticable by users.

Alternative options

The torch not being reset by the camera opening would be great, but I assume that is being set at the OS level.

Additional context

I only selected bardcode scanning as that is the only part of the library I have used, but I suspect the same issue woudl happen for all of the features.

Before submitting

robingenz commented 3 weeks ago

Is this an issue on Android or iOS or both?

derekdavieUH commented 3 weeks ago

@robingenz Both, I've observed the issue on an Android phone and a iPad mini. I was going back and forth but now I'm feeling like this is more of a bug? I have some free time later today, I'll fork the demo project and see if I can reproduce it there.

LMK if you want me to close and resubmit as a bug

derekdavieUH commented 2 weeks ago

I was mistaken, this only occurs in iOS (testing on iPad mini), and only occurs on the second time the scanner is open. I modifed the demo code to add a initialTorchState parameter to the Barcode Reader component. For this demo I set initialTorchState to always be True.

https://github.com/derekdavieUH/capacitor-mlkit-plugin-demo-persistent-torch

Commit with changes: https://github.com/derekdavieUH/capacitor-mlkit-plugin-demo-persistent-torch/commit/f7a8d18ded51bdefe72999ffb9e7411c588317a8

robingenz commented 2 weeks ago

Thanks, i will take a look as soon as i have some time.