ACINQ / phoenix

Phoenix is a self-custodial Bitcoin wallet using Lightning to send/receive payments.
https://phoenix.acinq.co
Apache License 2.0
624 stars 93 forks source link

(android) Fix camera keeps running after leaving scanner view (#442) #460

Closed kotasjan closed 8 months ago

kotasjan commented 8 months ago

Please test the changes. I am quite confident these changes will work, but I didn't have a chance to build and run it due to hurdles with the project build setup. 😕

dpad85 commented 8 months ago

Thanks, I will look into that ASAP.

kotasjan commented 8 months ago

I was able to reproduce issue #442 on a Pixel device with Android 14 (though on a Pixel device with Android 12, the camera does not stay active all the time).

I also tested your changes, and pausing the scanner does fix the issue - however it needs to be applied on other cases (e.g. when copy-pasting). A better solution is to simply use a DisposableEffect in the CameraPermissionsView.onPermissionGranted callback, instead of a LaunchedEffect:

DisposableEffect(key1 = model) {
    if (model is Scan.Model.Ready && initialInput.isNullOrBlank()) scanView?.resume()
    onDispose {
        scanView?.pause()
    }
}

If you give me push authorisation on your branch, I can update your PR with that change.

Thank you for the feedback. You are right with DisposableEffect - it is a much cleaner solution. 👍 I have added you to contributors, so you should be able to push your changes now.