EddyVerbruggen / nativescript-barcodescanner

🔎 NativeScript QR / barcode (bulk)scanner plugin
MIT License
293 stars 73 forks source link

Creating Dialog.alert inside .then((result) not working #264

Open Rdevc opened 3 years ago

Rdevc commented 3 years ago

Hi!

When I use the scanner and the code scanned did not match a param an alert is triggered to let the user know the scan is wrong. So in the result I have the following line to test:

.then((result) => {
      const alertOptions = {
        title: 'Warning',
        message: 'Something terrible has happened.',
        okButtonText: 'Okay',
        cancelable: false // [Android only] Gets or sets if the dialog can be canceled by taping outside of the dialog.
      }

      Dialogs.alert(alertOptions).then(() => {
        console.log('Ok chosen!')
      })
    });

This bit of code results in the next warning/error:

Warning: Attempt to present <UIAlertController: 0x10309c000> on <QRCodeReaderViewController: 0x102468590> whose view is not in the window hierarchy!

No alert is showing up which is obvious if you look at the warning/error.

I'm using: "@angular/core": "~11.2.5", "@nativescript/core": "8.0.2", "nativescript-barcodescanner": "^4.1.0",

Anyone a suggestion how to fix this? Is it a scanner issue or do I do something wrong?

Thanks in advance for any answer!!

EddyVerbruggen commented 3 years ago

I'm guessing wrapping that alert in a setTimeout should help.

Rdevc commented 3 years ago

Thanks for your answer!

I've tried that solution with a set timeout of 1000. The alert will work but when I hit te scan button again the alert appears again inside the scanner. After scanner two or three times ill get 3 alerts popping over each other.. It's like something is not closing and I'm still not sure if it is my code or something else.

As you can see I'm not using complex code or something.

EddyVerbruggen commented 3 years ago

Hmm, maybe you're showing the scanner inside a modal? Not that that's wrong, but it may be an edge case, combined with an alert. I don't really have time to look into it.. but maybe using a Toast or something else than an alert will get around it?

Rdevc commented 3 years ago

Got it, thank you!

presentInRootViewController: true

This was the issue.. I've copied the code from GitHub and your last message got me thinking about the modal..

it looks like

Fullscreen: true or Fullscreen: false

is not doing anything but deleting excluding the "presentInroot" showed me an alert without any warning or error.

Maybe I'll look into that in te future if I got some time and know how to debug the plugin but for now its ok for me.

It's up to you if you want this issue to be open to work on it later or close it.

Kind regards.

EddyVerbruggen commented 3 years ago

Oh that's nice! Glad you found a way to make it disappear.