@capgo/camera-preview 8.3.8 → 8.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -29
- package/android/build.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +337 -9
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +280 -0
- package/dist/docs.json +310 -1
- package/dist/esm/definitions.d.ts +76 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +10 -1
- package/dist/esm/web.js +126 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +126 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +126 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +167 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +72 -3
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -175,6 +175,30 @@ Example app (Ionic):
|
|
|
175
175
|
- EV controls (+/−) are placed in a top‑right floating action bar, outside the preview area.
|
|
176
176
|
|
|
177
177
|
|
|
178
|
+
## Barcode scanning
|
|
179
|
+
|
|
180
|
+
Barcode scanning reuses the active camera preview, so the preview can still sit behind the WebView while your HTML overlay stays interactive.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { CameraPreview } from '@capgo/camera-preview';
|
|
184
|
+
|
|
185
|
+
await CameraPreview.addListener('barcodeScanned', ({ barcodes }) => {
|
|
186
|
+
console.log('Barcodes:', barcodes);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await CameraPreview.start({
|
|
190
|
+
position: 'rear',
|
|
191
|
+
toBack: true,
|
|
192
|
+
barcodeScanner: {
|
|
193
|
+
formats: ['qr_code'],
|
|
194
|
+
detectionInterval: 500,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Use `barcodeScanner: true` to scan all supported formats. You can also call `startBarcodeScanner()` and `stopBarcodeScanner()` after the preview is running to scan only during a specific flow.
|
|
200
|
+
|
|
201
|
+
|
|
178
202
|
## Documentation
|
|
179
203
|
|
|
180
204
|
The most complete doc is available here: https://capgo.app/docs/plugins/camera-preview/
|
|
@@ -322,6 +346,8 @@ Documentation for the [uploader](https://github.com/Cap-go/capacitor-uploader)
|
|
|
322
346
|
* [`stop(...)`](#stop)
|
|
323
347
|
* [`capture(...)`](#capture)
|
|
324
348
|
* [`captureSample(...)`](#capturesample)
|
|
349
|
+
* [`startBarcodeScanner(...)`](#startbarcodescanner)
|
|
350
|
+
* [`stopBarcodeScanner()`](#stopbarcodescanner)
|
|
325
351
|
* [`getSupportedFlashModes()`](#getsupportedflashmodes)
|
|
326
352
|
* [`setAspectRatio(...)`](#setaspectratio)
|
|
327
353
|
* [`getAspectRatio()`](#getaspectratio)
|
|
@@ -350,6 +376,8 @@ Documentation for the [uploader](https://github.com/Cap-go/capacitor-uploader)
|
|
|
350
376
|
* [`setFocus(...)`](#setfocus)
|
|
351
377
|
* [`addListener('screenResize', ...)`](#addlistenerscreenresize-)
|
|
352
378
|
* [`addListener('orientationChange', ...)`](#addlistenerorientationchange-)
|
|
379
|
+
* [`addListener('barcodeScanned', ...)`](#addlistenerbarcodescanned-)
|
|
380
|
+
* [`addListener('barcodeScanError', ...)`](#addlistenerbarcodescanerror-)
|
|
353
381
|
* [`deleteFile(...)`](#deletefile)
|
|
354
382
|
* [`getSafeAreaInsets()`](#getsafeareainsets)
|
|
355
383
|
* [`getOrientation()`](#getorientation)
|
|
@@ -448,6 +476,42 @@ Captures a single frame from the camera preview stream.
|
|
|
448
476
|
--------------------
|
|
449
477
|
|
|
450
478
|
|
|
479
|
+
### startBarcodeScanner(...)
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
startBarcodeScanner(options?: BarcodeScannerOptions | undefined) => Promise<void>
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Starts barcode scanning on the active camera preview.
|
|
486
|
+
|
|
487
|
+
The scanner reuses the current camera session and emits `barcodeScanned` events.
|
|
488
|
+
Call `stopBarcodeScanner()` when scanning is no longer needed.
|
|
489
|
+
|
|
490
|
+
Android uses the lightweight Google Play Services ML Kit model. If the model is not installed yet,
|
|
491
|
+
first scans may return no result until Google Play Services finishes downloading it.
|
|
492
|
+
|
|
493
|
+
| Param | Type |
|
|
494
|
+
| ------------- | ----------------------------------------------------------------------- |
|
|
495
|
+
| **`options`** | <code><a href="#barcodescanneroptions">BarcodeScannerOptions</a></code> |
|
|
496
|
+
|
|
497
|
+
**Since:** 8.8.0
|
|
498
|
+
|
|
499
|
+
--------------------
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
### stopBarcodeScanner()
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
stopBarcodeScanner() => Promise<void>
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
Stops barcode scanning while keeping the camera preview running.
|
|
509
|
+
|
|
510
|
+
**Since:** 8.8.0
|
|
511
|
+
|
|
512
|
+
--------------------
|
|
513
|
+
|
|
514
|
+
|
|
451
515
|
### getSupportedFlashModes()
|
|
452
516
|
|
|
453
517
|
```typescript
|
|
@@ -913,6 +977,46 @@ Adds a listener for orientation change events.
|
|
|
913
977
|
--------------------
|
|
914
978
|
|
|
915
979
|
|
|
980
|
+
### addListener('barcodeScanned', ...)
|
|
981
|
+
|
|
982
|
+
```typescript
|
|
983
|
+
addListener(eventName: 'barcodeScanned', listenerFunc: (data: BarcodeScannedEvent) => void) => Promise<PluginListenerHandle>
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Adds a listener for barcode scan results.
|
|
987
|
+
|
|
988
|
+
| Param | Type |
|
|
989
|
+
| ------------------ | -------------------------------------------------------------------------------------- |
|
|
990
|
+
| **`eventName`** | <code>'barcodeScanned'</code> |
|
|
991
|
+
| **`listenerFunc`** | <code>(data: <a href="#barcodescannedevent">BarcodeScannedEvent</a>) => void</code> |
|
|
992
|
+
|
|
993
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
994
|
+
|
|
995
|
+
**Since:** 8.8.0
|
|
996
|
+
|
|
997
|
+
--------------------
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
### addListener('barcodeScanError', ...)
|
|
1001
|
+
|
|
1002
|
+
```typescript
|
|
1003
|
+
addListener(eventName: 'barcodeScanError', listenerFunc: (data: BarcodeScanErrorEvent) => void) => Promise<PluginListenerHandle>
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
Adds a listener for non-fatal barcode scanner errors.
|
|
1007
|
+
|
|
1008
|
+
| Param | Type |
|
|
1009
|
+
| ------------------ | ------------------------------------------------------------------------------------------ |
|
|
1010
|
+
| **`eventName`** | <code>'barcodeScanError'</code> |
|
|
1011
|
+
| **`listenerFunc`** | <code>(data: <a href="#barcodescanerrorevent">BarcodeScanErrorEvent</a>) => void</code> |
|
|
1012
|
+
|
|
1013
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
1014
|
+
|
|
1015
|
+
**Since:** 8.8.0
|
|
1016
|
+
|
|
1017
|
+
--------------------
|
|
1018
|
+
|
|
1019
|
+
|
|
916
1020
|
### deleteFile(...)
|
|
917
1021
|
|
|
918
1022
|
```typescript
|
|
@@ -1072,35 +1176,44 @@ Get the native Capacitor plugin version
|
|
|
1072
1176
|
|
|
1073
1177
|
Defines the configuration options for starting the camera preview.
|
|
1074
1178
|
|
|
1075
|
-
| Prop | Type
|
|
1076
|
-
| ----------------------------------- |
|
|
1077
|
-
| **`parent`** | <code>string</code>
|
|
1078
|
-
| **`className`** | <code>string</code>
|
|
1079
|
-
| **`width`** | <code>number</code>
|
|
1080
|
-
| **`height`** | <code>number</code>
|
|
1081
|
-
| **`x`** | <code>number</code>
|
|
1082
|
-
| **`y`** | <code>number</code>
|
|
1083
|
-
| **`aspectRatio`** | <code><a href="#camerapreviewaspectratio">CameraPreviewAspectRatio</a></code>
|
|
1084
|
-
| **`aspectMode`** | <code>'cover' \| 'contain'</code>
|
|
1085
|
-
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code>
|
|
1086
|
-
| **`includeSafeAreaInsets`** | <code>boolean</code>
|
|
1087
|
-
| **`toBack`** | <code>boolean</code>
|
|
1088
|
-
| **`paddingBottom`** | <code>number</code>
|
|
1089
|
-
| **`rotateWhenOrientationChanged`** | <code>boolean</code>
|
|
1090
|
-
| **`position`** | <code>string</code>
|
|
1091
|
-
| **`storeToFile`** | <code>boolean</code>
|
|
1092
|
-
| **`disableExifHeaderStripping`** | <code>boolean</code>
|
|
1093
|
-
| **`disableAudio`** | <code>boolean</code>
|
|
1094
|
-
| **`lockAndroidOrientation`** | <code>boolean</code>
|
|
1095
|
-
| **`enableOpacity`** | <code>boolean</code>
|
|
1096
|
-
| **`disableFocusIndicator`** | <code>boolean</code>
|
|
1097
|
-
| **`deviceId`** | <code>string</code>
|
|
1098
|
-
| **`enablePhysicalDeviceSelection`** | <code>boolean</code>
|
|
1099
|
-
| **`initialZoomLevel`** | <code>number</code>
|
|
1100
|
-
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code>
|
|
1101
|
-
| **`enableVideoMode`** | <code>boolean</code>
|
|
1102
|
-
| **`force`** | <code>boolean</code>
|
|
1103
|
-
| **`videoQuality`** | <code>'low' \| 'medium' \| 'high'</code>
|
|
1179
|
+
| Prop | Type | Description | Default | Since |
|
|
1180
|
+
| ----------------------------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------ |
|
|
1181
|
+
| **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
|
|
1182
|
+
| **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
|
|
1183
|
+
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
|
|
1184
|
+
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
|
|
1185
|
+
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
|
|
1186
|
+
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
|
|
1187
|
+
| **`aspectRatio`** | <code><a href="#camerapreviewaspectratio">CameraPreviewAspectRatio</a></code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting. | | 2.0.0 |
|
|
1188
|
+
| **`aspectMode`** | <code>'cover' \| 'contain'</code> | Controls how the camera preview fills the available space. - 'contain': Fits the entire preview within the space, may show letterboxing (default). - 'cover': Fills the entire space, may crop edges of the preview. | <code>"contain"</code> | |
|
|
1189
|
+
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
|
|
1190
|
+
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
|
|
1191
|
+
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
|
|
1192
|
+
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
|
|
1193
|
+
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
|
|
1194
|
+
| **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
|
|
1195
|
+
| **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string. | <code>false</code> | |
|
|
1196
|
+
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
|
|
1197
|
+
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
|
|
1198
|
+
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
|
|
1199
|
+
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
|
|
1200
|
+
| **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
|
|
1201
|
+
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
|
|
1202
|
+
| **`enablePhysicalDeviceSelection`** | <code>boolean</code> | On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens. Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior. | <code>false</code> | |
|
|
1203
|
+
| **`initialZoomLevel`** | <code>number</code> | The initial zoom level when starting the camera preview. If the requested zoom level is not available, the native plugin will reject. | <code>1.0</code> | 2.2.0 |
|
|
1204
|
+
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview. | <code>"center"</code> | 2.3.0 |
|
|
1205
|
+
| **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts. | <code>false</code> | 7.11.0 |
|
|
1206
|
+
| **`force`** | <code>boolean</code> | If true, forces the camera to start/restart even if it's already running or busy. This will kill the current camera session and start a new one, ignoring all state checks. | <code>false</code> | |
|
|
1207
|
+
| **`videoQuality`** | <code>'low' \| 'medium' \| 'high'</code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high' | <code>"high"</code> | |
|
|
1208
|
+
| **`barcodeScanner`** | <code>boolean \| <a href="#barcodescanneroptions">BarcodeScannerOptions</a></code> | Starts barcode scanning together with the camera preview. Set to `true` or pass options to scan all supported formats. Omit this option to keep barcode scanning disabled at startup. | | 8.8.0 |
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
#### BarcodeScannerOptions
|
|
1212
|
+
|
|
1213
|
+
| Prop | Type | Description | Default |
|
|
1214
|
+
| ----------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
|
|
1215
|
+
| **`formats`** | <code>BarcodeScannerFormat[]</code> | Restricts detection to the given formats. Leaving this empty scans all supported formats. Restricting formats can improve scanning speed. | |
|
|
1216
|
+
| **`detectionInterval`** | <code>number</code> | Minimum delay between native scan attempts in milliseconds. Lower values scan more often but use more CPU. | <code>500</code> |
|
|
1104
1217
|
|
|
1105
1218
|
|
|
1106
1219
|
#### ExifData
|
|
@@ -1231,6 +1344,30 @@ Represents the detailed information of the currently active lens.
|
|
|
1231
1344
|
| **`remove`** | <code>() => Promise<void></code> |
|
|
1232
1345
|
|
|
1233
1346
|
|
|
1347
|
+
#### BarcodeScannedEvent
|
|
1348
|
+
|
|
1349
|
+
| Prop | Type | Description |
|
|
1350
|
+
| -------------- | -------------------------------- | ---------------------------------------- |
|
|
1351
|
+
| **`barcodes`** | <code>BarcodeScanResult[]</code> | Barcodes decoded from the current frame. |
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
#### BarcodeScanResult
|
|
1355
|
+
|
|
1356
|
+
| Prop | Type | Description |
|
|
1357
|
+
| ------------------ | ------------------------------------------------------- | -------------------------------------------------------- |
|
|
1358
|
+
| **`value`** | <code>string</code> | Decoded barcode value. |
|
|
1359
|
+
| **`format`** | <code><a href="#barcodeformat">BarcodeFormat</a></code> | Barcode format. |
|
|
1360
|
+
| **`displayValue`** | <code>string</code> | Human-readable value when the platform exposes one. |
|
|
1361
|
+
| **`rawBytes`** | <code>string</code> | Base64-encoded raw bytes when the platform exposes them. |
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
#### BarcodeScanErrorEvent
|
|
1365
|
+
|
|
1366
|
+
| Prop | Type | Description |
|
|
1367
|
+
| ------------- | ------------------- | ----------------------------- |
|
|
1368
|
+
| **`message`** | <code>string</code> | Native scanner error message. |
|
|
1369
|
+
|
|
1370
|
+
|
|
1234
1371
|
#### SafeAreaInsets
|
|
1235
1372
|
|
|
1236
1373
|
Represents safe area insets for devices.
|
|
@@ -1266,6 +1403,11 @@ iOS: Values are expressed in physical pixels and exclude status bar.
|
|
|
1266
1403
|
<code>'center' | 'top' | 'bottom'</code>
|
|
1267
1404
|
|
|
1268
1405
|
|
|
1406
|
+
#### BarcodeScannerFormat
|
|
1407
|
+
|
|
1408
|
+
<code>'aztec' | 'codabar' | 'code_39' | 'code_93' | 'code_128' | 'data_matrix' | 'ean_8' | 'ean_13' | 'itf' | 'pdf417' | 'qr_code' | 'upc_a' | 'upc_e'</code>
|
|
1409
|
+
|
|
1410
|
+
|
|
1269
1411
|
#### PictureFormat
|
|
1270
1412
|
|
|
1271
1413
|
<code>'jpeg' | 'png'</code>
|
|
@@ -1303,6 +1445,11 @@ Canonical device orientation values across platforms.
|
|
|
1303
1445
|
<code>'portrait' | 'landscape-left' | 'landscape-right' | 'portrait-upside-down' | 'unknown'</code>
|
|
1304
1446
|
|
|
1305
1447
|
|
|
1448
|
+
#### BarcodeFormat
|
|
1449
|
+
|
|
1450
|
+
<code><a href="#barcodescannerformat">BarcodeScannerFormat</a> | 'unknown'</code>
|
|
1451
|
+
|
|
1452
|
+
|
|
1306
1453
|
#### ExposureMode
|
|
1307
1454
|
|
|
1308
1455
|
Reusable exposure mode type for cross-platform support.
|
package/android/build.gradle
CHANGED
|
@@ -66,6 +66,7 @@ dependencies {
|
|
|
66
66
|
implementation "androidx.camera:camera-view:${camerax_version}"
|
|
67
67
|
implementation "androidx.camera:camera-extensions:${camerax_version}"
|
|
68
68
|
implementation 'com.google.guava:guava:33.6.0-android'
|
|
69
|
+
implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1'
|
|
69
70
|
|
|
70
71
|
testImplementation "junit:junit:$junitVersion"
|
|
71
72
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
@@ -4,4 +4,9 @@
|
|
|
4
4
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
5
5
|
<uses-feature android:name="android.hardware.camera" />
|
|
6
6
|
<uses-feature android:required="false" android:name="android.hardware.camera.autofocus" />
|
|
7
|
+
<application>
|
|
8
|
+
<meta-data
|
|
9
|
+
android:name="com.google.mlkit.vision.DEPENDENCIES"
|
|
10
|
+
android:value="barcode" />
|
|
11
|
+
</application>
|
|
7
12
|
</manifest>
|