ionic-team / ionic-team/capacitor-barcode-scanner
Feature request: Add stopScan() method
- Dominant language
- TypeScript
- Stars
- 64
- Forks
- 47
- Avg merge
- 1h 55m
- Merged PRs (30d)
- 1
Description
### Summary
Please add a public `stopScan()` method to allow stopping an active barcode scan programmatically.
Example API:
```ts
await CapacitorBarcodeScanner.stopScan();
```
### Motivation
The current API allows starting a scan with `scanBarcode(...)`, but there does not appear to be a documented way to stop an active scan from application code.
This would be useful in Ionic/Capacitor apps where the scanning flow is controlled by the app UI and lifecycle.
Common use cases:
* The user navigates away from the scan page.
* The app wants to apply a scan timeout.
* The app needs to stop scanning after a specific business condition changes.
### Proposed API
```ts
await CapacitorBarcodeScanner.stopScan();
```
### Expected behavior
When `stopScan()` is called:
* The active barcode scanning session should stop.
* The camera resource should be released.
* The scanner UI should be closed or dismissed if applicable.
* The pending `scanBarcode(...)` call should finish in a predictable way.
### Example usage
```ts
let scanActive = false;
async function startScan() {
scanActive = true;
try {
const result = await CapacitorBarcodeScanner.scanBarcode({
hint: CapacitorBarcodeScannerTypeHint.ALL,
});
// Handle scanned barcode result
} catch (error) {
// Handle scanner error or stopped scan
} finally {
scanActive = false;
}
}
async function stopScan() {
if (scanActive) {
await CapacitorBarcodeScanner.stopScan();
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the public TypeScript scanBarcode API and the scanner lifecycle in the Capacitor plugin; the issue names no files or tests. Determine how an active session, camera resource, scanner UI, and pending scanBarcode call are represented. Done means stopScan() provides the specified predictable behavior across supported platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100