EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 441 forks source link

Back navigation error MLKitBarcodeScanner #1766

Open vallemar opened 3 years ago

vallemar commented 3 years ago

When performing a scan and navigating to another activity, if back is pressed the camera does not initialize again, the camera appears black. This behavior only happens in android, in ios it works correctly I am using it over vue and the following configuration:

nativescript: 7.1.2
@nativescript/android: 7.0.1
@nativescript/core: 7.1.3
@nativescript/ios: 7.1.0.
@nativescript/firebase": "^11.1.3"
vallemar commented 3 years ago

Any ideas on this @EddyVerbruggen ? Now I have changed the design of my application, I have put MLKitBarcodeScanner in a BottomNavigation and every time the user clicks on the scanner I have to do Frame.reloadPage() and return to the TabContentItem of the scanner since it returns to 0. With these traps the application it gets quite slow

vallemar commented 3 years ago

I have created a very basic project with the firebase configuration already added. If you download it you can see the error in question: https://github.com/vallemar/firebase-mlkitcamera

Error reproduction instructions Enter the scan tab, go back to home and go back to the scan, it will no longer work

vallemar commented 3 years ago

I have found the solution to this problem, it is not the best solution but it works. I have implemented it in vue:

  1. Force pause.
  2. Force the view with clearViewML. (the v-show is necessary because if not the camera is cut)

Important: with v-if this doesn't work, it has to be v-show

<template>
             <MLKitBarcodeScanner
                        v-show="!clearViewML"
                        @loaded="loadedMLKitBarcodeScanner"
                        :pause="pause"
                          .
                          .
                          .
              >
              </MLKitBarcodeScanner>
</template>
<script>
export default {
    data() {
        return {
            ml: null,
            pause: false,
            clearViewML: false,
        };
    },

    methods: {
        loadedMLKitBarcodeScanner(args) {
            if (isAndroid) {
                if (this.ml == null) {
                    this.ml = args.object;
                } else {
                    this.pause = true;
                    this.clearViewML = true;
                    setTimeout(() => {
                        this.clearViewML = false;
                        this.pause = false;
                    }, 50);
                }
            }
        }
    }
};
</script>