bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
575 stars 783 forks source link

Transparent Background not revert when scan is destroyed #234

Open basurahan opened 5 years ago

basurahan commented 5 years ago

Seems like the background stays transparent when the sacn is destroyed

sonicwong commented 5 years ago

YES, body tag still have style="background-color: transparent;"

sonicwong commented 5 years ago

Use this to fix the error temporary.

` import { Component, ChangeDetectorRef } from '@angular/core';

setTimeout(() => { window.document.body.style.backgroundColor = '#FFF'; this.ref.detectChanges(); }, 500); `

basurahan commented 5 years ago

Use this to fix the error temporary.

` import { Component, ChangeDetectorRef } from '@angular/core';

setTimeout(() => { window.document.body.style.backgroundColor = '#FFF'; this.ref.detectChanges(); }, 500); `

Thanks! Im using vanilla javascript. Can you provide more detail what does this.ref.detectChanges(); do and what is the equivalent code of it in vanilla javasript

mattmilan-dev commented 5 years ago

Having the same issue here too. Where about does the above code go? As the background is still remaining transparent for me. I understand that based off the angular docs (https://angular.io/api/core/ChangeDetectorRef) that the change detector checks for changes in the view, however don't fully understand where this needs to go to perform properly.

sonicwong commented 5 years ago

@devleaf-matt I found it work on my ionic3 project. But not work on ionic4 project.

basurahan commented 5 years ago

is there any turn around for this ? i really need the fix today

fabianriewe commented 5 years ago

I wrote a quick and dirty workaround like this:

scan() {
        document.body.style.backgroundColor = 'transparent';

        QRScanner.show();
        QRScanner.scan(displayContents);

        function displayContents(err, text) {
          if(err){
            console.log('error', err);
          } else {
            alert(text);
            if (text) {
              QRScanner.hide();
              QRScanner.cancelScan();
              document.body.style.backgroundColor = '#FFF';
            }
          }
        }
      }
p3v9d5ui commented 5 years ago

Any more info on this? I've found that both hide() and cancelScan() result in different body background colors. cancelScan() seems to revert it to transparent. Will this be fixed?

p3v9d5ui commented 5 years ago

I have created a pull request that fixes this:

https://github.com/bitpay/cordova-plugin-qrscanner/pull/279

This bug was created by this previous commit:

https://github.com/bitpay/cordova-plugin-qrscanner/commit/c9531b85e93d4cf5b844b83f265975c683cbee11

Or, if my PR is not accepted, you can use my clone:

https://github.com/p3v9d5ui/cordova-plugin-qrscanner

tset2411 commented 5 years ago

I have created a pull request that fixes this:

279

This bug was created by this previous commit:

c9531b8

Or, if my PR is not accepted, you can use my clone:

https://github.com/p3v9d5ui/cordova-plugin-qrscanner

We are facing the same issue, @p3v9d5ui PR should be approved.

cmohanraj10 commented 3 years ago

Below code works for me

$("html").hide();
QRScanner.scan(displayContents);

function displayContents(err,text){
  if(err){
    alert("Something went wrong. Please try after some time.");
  }
  else{
    $("html").show();
    QRScanner.hide();
    QRScanner.cancelScan();
    alert(text);
  }
}

QRScanner.show();

Hope it helps, Happy coding!