Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions package-lock.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert those changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/barcode-scanning/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# node files
dist
node_modules

# iOS files
Expand Down
28 changes: 28 additions & 0 deletions packages/barcode-scanning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ If you can't see the camera view, make sure all elements in the DOM are not visi

* [`startScan(...)`](#startscan)
* [`stopScan()`](#stopscan)
* [`pauseScan()`](#pausescan)
* [`resumeScan()`](#resumescan)
* [`readBarcodesFromImage(...)`](#readbarcodesfromimage)
* [`scan(...)`](#scan)
* [`isSupported()`](#issupported)
Expand Down Expand Up @@ -368,6 +370,32 @@ Stop scanning for barcodes.
--------------------


### pauseScan()

```typescript
pauseScan() => Promise<void>
```

Pause scanning for barcodes.

**Since:** 8.1.0

--------------------


### resumeScan()

```typescript
resumeScan() => Promise<void>
```

Resume scanning for barcodes.

**Since:** 8.1.0

--------------------


### readBarcodesFromImage(...)

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class BarcodeScanner implements ImageAnalysis.Analyzer {

private boolean isTorchEnabled = false;

private boolean isPaused = false;

public BarcodeScanner(BarcodeScannerPlugin plugin) {
this.plugin = plugin;
}
Expand Down Expand Up @@ -177,9 +179,54 @@ public void stopScan() {
}
barcodeScannerInstance = null;
scanSettings = null;
isPaused = false;
barcodeRawValueVotes.clear();
}

/**
* Must run on UI thread.
*/
public void pauseScan() {
isPaused = true;
if (processCameraProvider != null) {
processCameraProvider.unbindAll();
}
}

/**
* Must run on UI thread.
*/
public void resumeScan() {
if (!isPaused || scanSettings == null || processCameraProvider == null) {
return;
}

isPaused = false;

try {
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.setTargetResolution(scanSettings.resolution)
.build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(plugin.getContext()), this);

CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(scanSettings.lensFacing).build();

Preview preview = new Preview.Builder().build();
if (previewView != null) {
preview.setSurfaceProvider(previewView.getSurfaceProvider());
}

camera = processCameraProvider.bindToLifecycle((LifecycleOwner) plugin.getContext(), cameraSelector, preview, imageAnalysis);

if (isTorchEnabled && camera != null) {
camera.getCameraControl().enableTorch(true);
}
} catch (Exception exception) {
handleScanError(exception);
}
}

public void readBarcodesFromImage(String path, ScanSettings scanSettings, ReadBarcodesFromImageResultCallback callback)
throws Exception {
InputImage inputImage;
Expand Down Expand Up @@ -354,6 +401,11 @@ public boolean isCameraActive() {

@Override
public void analyze(@NonNull ImageProxy imageProxy) {
if (isPaused) {
imageProxy.close();
return;
}

@SuppressLint("UnsafeOptInUsageError")
Image image = imageProxy.getImage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,34 @@ public void stopScan(PluginCall call) {
}
}

@PluginMethod
public void pauseScan(PluginCall call) {
try {
getActivity()
.runOnUiThread(() -> {
implementation.pauseScan();
call.resolve();
});
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
}

@PluginMethod
public void resumeScan(PluginCall call) {
try {
getActivity()
.runOnUiThread(() -> {
implementation.resumeScan();
call.resolve();
});
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
}

@PluginMethod
public void readBarcodesFromImage(PluginCall call) {
try {
Expand Down
Loading