capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 169 forks source link

Cannot go back #164

Closed fabiokounang closed 1 year ago

fabiokounang commented 1 year ago

Hello, all is good except when i open the camera and then instantly go back, it wont go back, it kept still being in the camera. Please help

my script is

async onPermissionCamera () {
    const status = await BarcodeScanner.checkPermission({ force: true });
    return status;
  }

  async onOpenCamera () {
    const ionApp = document.querySelector('ion-app');
    try {
      if (await this.onPermissionCamera()) {
        ionApp.classList.add('scanner-ui');
        BarcodeScanner.hideBackground();
        const result = await BarcodeScanner.startScan();
        console.log(result, 'result')
        if (result && result.hasContent) {
          this.router.navigate(['/event', result.content]);
          ionApp.classList.remove('scanner-ui');
          ionApp.style.display = 'block';
        } else {
          console.log('masuk else');
          BarcodeScanner.showBackground();
          BarcodeScanner.stopScan();
          ionApp.classList.remove('scanner-ui');
          ionApp.style.display = 'block';
        }
      }
    } catch (error) {
      console.log(error, 'error');
      BarcodeScanner.showBackground();
      BarcodeScanner.stopScan();
      ionApp.classList.remove('scanner-ui');
      ionApp.style.display = 'block';
    }
  }

the scanner-ui class is .scanner-ui { display: none; }

fabiokounang commented 1 year ago

I think i am mistaken. This is not a bug, but I have to handle back button from android myself https://ionicframework.com/docs/developing/hardware-back-button