Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

feat: add configurability to just pause the scanner (while keeping the view open) on scan rather than destroying it. #33

Closed
milanharia opened this issue May 7, 2021 · 9 comments
Labels
enhancement New feature or request priority-2

Comments

@milanharia
Copy link

Right now the current implementation of the scanner is to automatically destroy it for battery and performance reasons. In the source code there is currently a destroy function which dismantles the camera and hides the viewfinder. It would be great if we could configure this functionality to just pause the scanner when a barcode is scanned, and to keep the camera viewfinder open, something like the function below.

private func destroy() {
self.shouldRunScan = false
}

@tafelnl
Copy link
Member

tafelnl commented May 7, 2021

I am planning on adding functionality that adds support for continuously scanning barcodes. So without even closing the camera view. It will then just return the values of barcodes it recognizes constantly. Is that something that works for you as well?

@tafelnl tafelnl added the enhancement New feature or request label May 7, 2021
@milanharia
Copy link
Author

I was hoping more for a "pause" in the scanner, i.e. the camera is still activated but not scanning, so I can show feedback that a barcode was scanned (a modal that pops up saying scanned over the camera viewfinder), and then after a set delay, the scanner will unpause and be able to scan barcodes again.

@tafelnl
Copy link
Member

tafelnl commented May 10, 2021

Fair enough. Will look into it while developing continuous scanning mode.

@hellokingdom
Copy link

hellokingdom commented May 10, 2021

@tafelnl continuously scanning barcodes would be great and to @milanharia point it would be useful to have the ability to set a cool down time between scans (i.e how long before the scanner becomes active).

Would also be useful to expose an event which can be used to distinguish between the scanning being 'active' or 'paused' to allow fine control over the UI overlay the user is shown between successful scans.

@tafelnl
Copy link
Member

tafelnl commented May 10, 2021

@hellokingdom active/pause event is indeed essential I think. However I do think a cool down timer would be a little out of scope for this project. It wouldn't be to difficult to implement such a thing in JS however, with a simple timeout for example.

@hellokingdom
Copy link

@tafelnl Yeah that makes sense. If we have events for pausing and activating the scanner we can keep the UI logic in the JS layer where it belongs.

@tafelnl tafelnl changed the title Configurability to just pause the scanner on scan rather than destroying it. feat: add configurability to just pause the scanner (while keeping the view open) on scan rather than destroying it. Jun 2, 2021
@m-bagnarelli
Copy link

Hi, any updates on this? :). I really need it.
@milanharia Could you make it somehow?

@rulaman123
Copy link

rulaman123 commented Nov 2, 2021

I have done that for Android. It is possible. Don't know if it's perfect but in my case it's working fine.
You have to edit the BarcodeScanner.java (capacitor-community\barcode-scanner\android\src\main\java\com\dutchconcepts\capacitor\barcodescanner\BarcodeScanner.java).

Go to the method "Override public void barcodeResult(BarcodeResult barcodeResult)" and delete
destroy();
Then the scanner view will not pause any more.

After that you can create a new method for scanning again.

private void scanAgain() {
    BarcodeCallback b = this;
    getActivity()
      .runOnUiThread(
        () -> {
            mBarcodeView.decodeSingle(b);
        }
      );
  }

After that create a new plugin method.

  @PluginMethod
  public void startScanAgain(PluginCall call) {
    saveCall(call);
    scanAgain();
  }

And the last step is to add the newly created method to the interface (capacitor-community\barcode-scanner\dist\esm\definitions.d.ts):
Go to the method "export interface BarcodeScannerPlugin" and add
startScanAgain(): Promise<ScanResult>;

And now you can start a new scan with "startScanAgain()".
I have done that by using a modal for my scan result and every time the modal will dismiss the next scan is starting.
Don't forget to close the scanner, e.g. when leaving the site.

@thegnuu
Copy link
Collaborator

thegnuu commented Feb 27, 2022

PR #93 which should resolve this by adding a continuous scanning feature is now merged to the main branch, I will make a few tests next week and release 2.1.0 if everything works as expected!

@thegnuu thegnuu closed this as completed Feb 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request priority-2
Projects
None yet
Development

No branches or pull requests

6 participants