ionic-team / ionic-team/capacitor-barcode-scanner

[Feature]: Add support for programmatically closing the scanner or configuring a timeout

Open
#133 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
64
Forks
47
Avg merge
1h 55m
Merged PRs (30d)
1

Description

### Feature Description

Currently, once `scanBarcode()` is called, the application completely loses control over the scanner until the user scans a barcode or manually dismisses the view (if the platform allows it).

This is problematic in several real-world scenarios:
- The user accidentally opens the scanner.
- The application needs to navigate away from the current page.
- A network request or another event requires cancelling the scan.
- The app wants to automatically stop scanning after a period of inactivity.

At the moment there is no API to cancel or close an active scanning session

### Potential Implementation

It would be great to support one (or both) of the following approaches:

#### Option 1: Timeout

Allow configuring a timeout when starting the scanner.

Example:

```ts
await BarcodeScanner.scanBarcode({
hint: CapacitorBarcodeScannerTypeHint.ALL,
timeout: 30000 // Automatically closes after 30 seconds
});
```

#### Option 2: Cancel Scanning

Expose a new method that allows the application to close or cancel the currently active scanner.
For example:

`await BarcodeScanner.cancelScan();`

Alternatively, the method could be named:

`await BarcodeScanner.closeScanner();`

or:

`await BarcodeScanner.stopScan();`

cancelScan() may be the clearest name because it indicates that the current scanning operation is being cancelled rather than permanently closing or disabling the scanner plugin.

### Supported Platforms

- [x] iOS
- [x] Android
- [ ] Web

### Alternatives

_No response_

### Notes / Comments

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the existing scanBarcode API and how scanning is handled on the supported iOS and Android platforms. Compare the timeout and cancellation proposals, decide the intended API and behavior, and consider the platform-specific completion and dismissal cases; done means the chosen behavior is consistently available on both platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.