EddyVerbruggen / nativescript-barcodescanner

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

Crash all Frames in application after a scan done! #281

Closed xeroxstar closed 2 years ago

xeroxstar commented 2 years ago

Hello, All my Frames are blank after the scan is done. I am getting no errors and not sure how to fix it. After the scan is done i tried to refresh the frame but it wont help.

Here is my code:

application.xml

<Page actionBarHidden="true"
      xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:map="@nativescript/google-maps"
      xmlns:picker="@nativescript/picker"
      navigatingTo="application">

    <Tabs selectedIndex="0">
        <TabContentItem>
            <Frame id="packages-frame" style="border-color:#222; border-width:5" defaultPage="components/packages/packages"/>
        </TabContentItem>
    </Tabs>
</Page>

application.ts

class App extends Observable{
  barcodeScanner: new BarcodeScanner ()
  constructor(page) {
    super();
    global.PAGE = page;
  }
}

packages.xml

<Page actionBarHidden="true"
      xmlns="http://schemas.nativescript.org/tns.xsd"
      navigatingTo="packages">

    <Button text="test"></Button>
    <ListView id             = "packages"
              items          = "{{ packages }}"
              separatorColor = "#cccccc"
              top            = "70"
              style          = "height:100%; width:100%">

    <ListView.itemTemplate>
        <Label text= "{{title}}"></Label>
    </ListView.itemTemplate>
    </ListView>
</Page>

packages.ts

import {EventData, Observable, Page, Dialogs, Frame} from "@nativescript/core";
import {BarcodeScanner} from "nativescript-barcodescanner";

class Packages extends Observable{
  page:Page
  barcodeScanner = new BarcodeScanner();
  constructor(page:Page) {
    super();
    this.page = page;
    this.scan()
  }

  packages = [{
    title:'package 1'
  }]

  scan(){
    this.barcodeScanner.requestCameraPermission().then(() => {
      this.barcodeScanner.scan({
        presentInRootViewController: true, // not needed here, but added it just for show
        cancelLabel: "EXIT. Also, try the volume buttons!", // iOS only, default 'Close'
        cancelLabelBackgroundColor: "#333333", // iOS only, default '#000000' (black)
        message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
        // preferFrontCamera: front,     // Android only, default false
        showFlipCameraButton: false,   // default false
        showTorchButton: false,       // iOS only, default false
        torchOn: false,               // launch with the flashlight on (default false)
        resultDisplayDuration: 500,   // Android only, default 1500 (ms), set to 0 to disable echoing the scanned text
        // orientation: orientation,     // Android only, default undefined (sensor-driven orientation), other options: portrait|landscape
        beepOnScan: true,             // Play or Suppress beep on scan (default true)
        fullScreen: false,             // iOS 13+ modal appearance changed so they can be swiped down when this is false (default false)
        openSettingsIfPermissionWasPreviouslyDenied: true
      }).then(() => {
        try{
          Frame.topmost().navigate({
          moduleName: "application", clearHistory: true
        })
      })
    })
  }
}

export function packages(args: EventData) {
  (<Page>args.object).bindingContext = new Packages(<Page>args.object)
}

I am using NS 8.2.2 and nativescript-barcodescanner 4.1.2.

xeroxstar commented 2 years ago

Fixed:

const getFrameById = require("tns-core-modules/ui/frame").getFrameById;
this.barcodeScanner.requestCameraPermission().then(() => {
      this.barcodeScanner.scan({
        presentInRootViewController: true, // not needed here, but added it just for show
        cancelLabel: "EXIT. Also, try the volume buttons!", // iOS only, default 'Close'
        cancelLabelBackgroundColor: "#333333", // iOS only, default '#000000' (black)
        message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
        // preferFrontCamera: front,     // Android only, default false
        showFlipCameraButton: false,   // default false
        showTorchButton: false,       // iOS only, default false
        torchOn: false,               // launch with the flashlight on (default false)
        resultDisplayDuration: 500,   // Android only, default 1500 (ms), set to 0 to disable echoing the scanned text
        // orientation: orientation,     // Android only, default undefined (sensor-driven orientation), other options: portrait|landscape
        beepOnScan: true,             // Play or Suppress beep on scan (default true)
        fullScreen: false,             // iOS 13+ modal appearance changed so they can be swiped down when this is false (default false)
        openSettingsIfPermissionWasPreviouslyDenied: true
      }).then(() => {
         setTimeout(() => {
          getFrameById('application').navigate({
            moduleName: "application", clearHistory: true
          })
        });
      })
    })