@capgo/camera-preview 8.12.4 → 8.13.0
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 +56 -51
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +13 -2
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +17 -4
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolver.java +28 -0
- package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolverTest.java +31 -0
- package/dist/docs.json +24 -4
- package/dist/esm/definitions.d.ts +28 -8
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +6 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/AspectRatioLayout.swift +40 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +246 -57
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureImageExifEncoder.swift +88 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureLifecycleCoordination.swift +37 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureOrientationResolver.swift +23 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CapturePhotoProcessingQueue.swift +20 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/CaptureResolutionSupport.swift +133 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/ImageIOJpegEncoding.swift +28 -0
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +74 -142
- package/ios/Tests/CameraPreviewPluginTests/CameraPreviewPluginTests.swift +26 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureImageExifEncoderTests.swift +141 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureLifecycleCoordinationTests.swift +73 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureOrientationResolverTests.swift +30 -0
- package/ios/Tests/CameraPreviewPluginTests/CaptureResolutionSupportTests.swift +133 -0
- package/ios/Tests/CameraPreviewPluginTests/ImageIOJpegEncodingTests.swift +42 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1114,7 +1114,11 @@ On Android, if a physical-lens request falls back to a logical camera, this retu
|
|
|
1114
1114
|
getPreviewSize() => Promise<{ x: number; y: number; width: number; height: number; }>
|
|
1115
1115
|
```
|
|
1116
1116
|
|
|
1117
|
-
Gets the current preview
|
|
1117
|
+
Gets the current visible camera preview bounds in web-view coordinates.
|
|
1118
|
+
|
|
1119
|
+
With `aspectMode: 'contain'`, this is the letterboxed camera image rect inside the
|
|
1120
|
+
preview container (not the full container when bars are shown). With `aspectMode: 'cover'`,
|
|
1121
|
+
this matches the preview container bounds on both platforms.
|
|
1118
1122
|
|
|
1119
1123
|
**Returns:** <code>Promise<{ x: number; y: number; width: number; height: number; }></code>
|
|
1120
1124
|
|
|
@@ -1559,44 +1563,44 @@ Get the native Capacitor plugin version
|
|
|
1559
1563
|
|
|
1560
1564
|
Defines the configuration options for starting the camera preview.
|
|
1561
1565
|
|
|
1562
|
-
| Prop | Type | Description
|
|
1563
|
-
| ------------------------------------------------ | ---------------------------------------------------------------------------------- |
|
|
1564
|
-
| **`parent`** | <code>string</code> | The parent element to attach the video preview to.
|
|
1565
|
-
| **`className`** | <code>string</code> | A CSS class name to add to the preview element.
|
|
1566
|
-
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width.
|
|
1567
|
-
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height.
|
|
1568
|
-
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels.
|
|
1569
|
-
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels.
|
|
1570
|
-
| **`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.
|
|
1571
|
-
| **`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.
|
|
1572
|
-
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview.
|
|
1573
|
-
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches).
|
|
1574
|
-
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview.
|
|
1575
|
-
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels.
|
|
1576
|
-
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes.
|
|
1577
|
-
| **`position`** | <code>string</code> | The camera to use.
|
|
1578
|
-
| **`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.
|
|
1579
|
-
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data.
|
|
1580
|
-
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests.
|
|
1581
|
-
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active.
|
|
1582
|
-
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed.
|
|
1583
|
-
| **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus.
|
|
1584
|
-
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored.
|
|
1585
|
-
| **`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.
|
|
1586
|
-
| **`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.
|
|
1587
|
-
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview.
|
|
1588
|
-
| **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts.
|
|
1589
|
-
| **`captureResolution`** | <code><a href="#cameracaptureresolution">CameraCaptureResolution</a></code> | Sets the
|
|
1590
|
-
| **`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.
|
|
1591
|
-
| **`videoQuality`** | <code><a href="#videoquality">VideoQuality</a></code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high', '2160p', '1080p', '720p', '480p', '4:3'
|
|
1592
|
-
| **`maxDuration`** | <code>number</code> | Maximum recording duration in seconds. Recording stops automatically when reached.
|
|
1593
|
-
| **`maxFileSize`** | <code>number</code> | Maximum recording file size in bytes. Recording stops automatically when reached.
|
|
1594
|
-
| **`videoCodec`** | <code><a href="#videocodec">VideoCodec</a></code> | Preferred video codec for recording.
|
|
1595
|
-
| **`frameRate`** | <code>number</code> | Target video frame rate in frames per second. Applied when recording starts. Use `getSupportedVideoFrameRates()` to list supported values.
|
|
1596
|
-
| **`videoStabilizationMode`** | <code><a href="#videostabilizationmode">VideoStabilizationMode</a></code> | Preferred video stabilization mode for recording.
|
|
1597
|
-
| **`allowHapticsAndSystemSoundsDuringRecording`** | <code>boolean</code> | When `true`, allows haptic feedback and system sounds while recording video with audio. iOS suppresses haptics during audio input recording unless this is enabled. Requires `disableAudio: false`.
|
|
1598
|
-
| **`mirrorFrontCamera`** | <code>boolean</code> | When `true` and the front camera is active, mirrors the recorded video file so it matches the selfie-style preview (text and gestures are not reversed). Does not affect the live preview. Defaults to `false` to preserve existing behavior.
|
|
1599
|
-
| **`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.
|
|
1566
|
+
| Prop | Type | Description | Default | Since |
|
|
1567
|
+
| ------------------------------------------------ | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | ------ |
|
|
1568
|
+
| **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
|
|
1569
|
+
| **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
|
|
1570
|
+
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
|
|
1571
|
+
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
|
|
1572
|
+
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
|
|
1573
|
+
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
|
|
1574
|
+
| **`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 |
|
|
1575
|
+
| **`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> | |
|
|
1576
|
+
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
|
|
1577
|
+
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
|
|
1578
|
+
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
|
|
1579
|
+
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
|
|
1580
|
+
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
|
|
1581
|
+
| **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
|
|
1582
|
+
| **`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> | |
|
|
1583
|
+
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
|
|
1584
|
+
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
|
|
1585
|
+
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
|
|
1586
|
+
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
|
|
1587
|
+
| **`disableFocusIndicator`** | <code>boolean</code> | If true, disables the visual focus indicator when tapping to focus. | <code>false</code> | |
|
|
1588
|
+
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
|
|
1589
|
+
| **`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> | |
|
|
1590
|
+
| **`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 |
|
|
1591
|
+
| **`positioning`** | <code><a href="#camerapositioning">CameraPositioning</a></code> | The vertical positioning of the camera preview. | <code>"center"</code> | 2.3.0 |
|
|
1592
|
+
| **`enableVideoMode`** | <code>boolean</code> | If true, enables video capture capabilities when the camera starts. | <code>false</code> | 7.11.0 |
|
|
1593
|
+
| **`captureResolution`** | <code><a href="#cameracaptureresolution">CameraCaptureResolution</a></code> | Sets the still-capture sensor resolution cap at session start. Preview resolution is unchanged. The shared ViewPort crop from the preview still applies to captures. On Android this binds the `ImageCapture` use case to the requested size. On iOS 16+ this sets `AVCapturePhotoSettings.maxPhotoDimensions` (and disables high-resolution photo capture when capped) so the sensor delivers fewer pixels instead of downscaling a full-sensor frame in software. On iOS 15, `start()` rejects this option. When omitted, capture uses the highest resolution supported by the active camera (same as versions before 8.11.10 on Android, and the format default on iOS). Set this to cap capture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }` or `{ width: 1600, height: 1200 }`. | | 8.12.0 |
|
|
1594
|
+
| **`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> | |
|
|
1595
|
+
| **`videoQuality`** | <code><a href="#videoquality">VideoQuality</a></code> | Sets the quality of video for recording. Options: 'low', 'medium', 'high', '2160p', '1080p', '720p', '480p', '4:3' | <code>"high"</code> | |
|
|
1596
|
+
| **`maxDuration`** | <code>number</code> | Maximum recording duration in seconds. Recording stops automatically when reached. | | |
|
|
1597
|
+
| **`maxFileSize`** | <code>number</code> | Maximum recording file size in bytes. Recording stops automatically when reached. | | |
|
|
1598
|
+
| **`videoCodec`** | <code><a href="#videocodec">VideoCodec</a></code> | Preferred video codec for recording. | <code>"avc1"</code> | |
|
|
1599
|
+
| **`frameRate`** | <code>number</code> | Target video frame rate in frames per second. Applied when recording starts. Use `getSupportedVideoFrameRates()` to list supported values. | | 8.6.0 |
|
|
1600
|
+
| **`videoStabilizationMode`** | <code><a href="#videostabilizationmode">VideoStabilizationMode</a></code> | Preferred video stabilization mode for recording. | <code>"off"</code> | |
|
|
1601
|
+
| **`allowHapticsAndSystemSoundsDuringRecording`** | <code>boolean</code> | When `true`, allows haptic feedback and system sounds while recording video with audio. iOS suppresses haptics during audio input recording unless this is enabled. Requires `disableAudio: false`. | <code>false</code> | 8.8.0 |
|
|
1602
|
+
| **`mirrorFrontCamera`** | <code>boolean</code> | When `true` and the front camera is active, mirrors the recorded video file so it matches the selfie-style preview (text and gestures are not reversed). Does not affect the live preview. Defaults to `false` to preserve existing behavior. | <code>false</code> | 8.10.0 |
|
|
1603
|
+
| **`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 |
|
|
1600
1604
|
|
|
1601
1605
|
|
|
1602
1606
|
#### CameraCaptureResolution
|
|
@@ -1629,18 +1633,19 @@ Represents EXIF data extracted from an image.
|
|
|
1629
1633
|
|
|
1630
1634
|
Defines the options for capturing a picture.
|
|
1631
1635
|
|
|
1632
|
-
| Prop | Type | Description | Default
|
|
1633
|
-
| -------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1634
|
-
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. |
|
|
1635
|
-
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. |
|
|
1636
|
-
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code>
|
|
1637
|
-
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code>
|
|
1638
|
-
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code>
|
|
1639
|
-
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code>
|
|
1640
|
-
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code>
|
|
1641
|
-
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code>
|
|
1642
|
-
| **`photoQualityPrioritization`** | <code>'speed' \| 'balanced' \| 'quality'</code> | Sets the priority for photo quality vs. capture speed. - "speed": Prioritizes faster capture times, may reduce image quality. - "balanced": Aims for a balance between quality and speed. - "quality": Prioritizes image quality, may reduce capture speed. See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details. | <code>"speed"</code>
|
|
1643
|
-
| **`mirrorFrontCamera`** | <code>boolean</code> | If true and the front camera is active, horizontally mirror the captured photo so it matches a selfie-style preview. Rear camera captures are never mirrored. Defaults to false to preserve the previous non-mirrored behavior. | <code>false</code>
|
|
1636
|
+
| Prop | Type | Description | Default | Since |
|
|
1637
|
+
| -------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------ |
|
|
1638
|
+
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1639
|
+
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1640
|
+
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
|
|
1641
|
+
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
|
|
1642
|
+
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
|
|
1643
|
+
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
|
|
1644
|
+
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code> | 7.17.0 |
|
|
1645
|
+
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code> | 7.18.0 |
|
|
1646
|
+
| **`photoQualityPrioritization`** | <code>'speed' \| 'balanced' \| 'quality'</code> | Sets the priority for photo quality vs. capture speed. - "speed": Prioritizes faster capture times, may reduce image quality. - "balanced": Aims for a balance between quality and speed. - "quality": Prioritizes image quality, may reduce capture speed. See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details. | <code>"speed"</code> | 7.21.0 |
|
|
1647
|
+
| **`mirrorFrontCamera`** | <code>boolean</code> | If true and the front camera is active, horizontally mirror the captured photo so it matches a selfie-style preview. Rear camera captures are never mirrored. Defaults to false to preserve the previous non-mirrored behavior. | <code>false</code> | 8.10.0 |
|
|
1648
|
+
| **`orientation`** | <code>'preview' \| 'device'</code> | Which orientation to apply to the captured photo. - `"device"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked. - `"preview"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera. | <code>"device"</code> | 8.13.0 |
|
|
1644
1649
|
|
|
1645
1650
|
|
|
1646
1651
|
#### CameraSampleOptions
|
|
@@ -521,8 +521,19 @@ public class CameraPreview extends Plugin implements CameraXView.CameraXViewList
|
|
|
521
521
|
final boolean embedTimestamp = Boolean.TRUE.equals(call.getBoolean("embedTimestamp"));
|
|
522
522
|
final boolean embedLocation = Boolean.TRUE.equals(call.getBoolean("embedLocation"));
|
|
523
523
|
final boolean mirrorFrontCamera = Boolean.TRUE.equals(call.getBoolean("mirrorFrontCamera"));
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
final String orientation = call.getString("orientation", CaptureOrientationResolver.ORIENTATION_DEVICE);
|
|
525
|
+
|
|
526
|
+
cameraXView.capturePhoto(
|
|
527
|
+
quality,
|
|
528
|
+
saveToGallery,
|
|
529
|
+
width,
|
|
530
|
+
height,
|
|
531
|
+
location,
|
|
532
|
+
embedTimestamp,
|
|
533
|
+
embedLocation,
|
|
534
|
+
mirrorFrontCamera,
|
|
535
|
+
orientation
|
|
536
|
+
);
|
|
526
537
|
}
|
|
527
538
|
|
|
528
539
|
@PluginMethod
|
|
@@ -2251,7 +2251,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2251
2251
|
Location location,
|
|
2252
2252
|
final boolean embedTimestamp,
|
|
2253
2253
|
final boolean embedLocation,
|
|
2254
|
-
final boolean mirrorFrontCamera
|
|
2254
|
+
final boolean mirrorFrontCamera,
|
|
2255
|
+
String orientationMode
|
|
2255
2256
|
) {
|
|
2256
2257
|
if (imageCapture == null) {
|
|
2257
2258
|
if (listener != null) {
|
|
@@ -2266,11 +2267,23 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2266
2267
|
return;
|
|
2267
2268
|
}
|
|
2268
2269
|
|
|
2269
|
-
|
|
2270
|
-
int
|
|
2270
|
+
int displayRotation = getDisplayRotationFallback();
|
|
2271
|
+
int deviceRotation = getRotationFromAccelerometer();
|
|
2272
|
+
int rotation = CaptureOrientationResolver.resolveRotation(orientationMode, displayRotation, deviceRotation);
|
|
2271
2273
|
lastCaptureRotation = rotation;
|
|
2272
2274
|
imageCapture.setTargetRotation(rotation);
|
|
2273
|
-
Log.d(
|
|
2275
|
+
Log.d(
|
|
2276
|
+
TAG,
|
|
2277
|
+
"capturePhoto: Set target rotation to " +
|
|
2278
|
+
rotation +
|
|
2279
|
+
" (mode=" +
|
|
2280
|
+
orientationMode +
|
|
2281
|
+
", display=" +
|
|
2282
|
+
displayRotation +
|
|
2283
|
+
", device=" +
|
|
2284
|
+
deviceRotation +
|
|
2285
|
+
")"
|
|
2286
|
+
);
|
|
2274
2287
|
|
|
2275
2288
|
Log.d(
|
|
2276
2289
|
TAG,
|
package/android/src/main/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolver.java
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Chooses whether still capture uses on-screen preview rotation or physical device rotation.
|
|
5
|
+
*/
|
|
6
|
+
public final class CaptureOrientationResolver {
|
|
7
|
+
|
|
8
|
+
public static final String ORIENTATION_PREVIEW = "preview";
|
|
9
|
+
public static final String ORIENTATION_DEVICE = "device";
|
|
10
|
+
|
|
11
|
+
private CaptureOrientationResolver() {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param orientationMode {@link #ORIENTATION_PREVIEW}, {@link #ORIENTATION_DEVICE}, or null/empty for device.
|
|
15
|
+
* @param displayRotation rotation matching the preview (typically {@link android.view.Display#getRotation()}).
|
|
16
|
+
* @param deviceRotation rotation from the accelerometer / physical resolver.
|
|
17
|
+
*/
|
|
18
|
+
public static int resolveRotation(String orientationMode, int displayRotation, int deviceRotation) {
|
|
19
|
+
if (ORIENTATION_PREVIEW.equals(orientationMode)) {
|
|
20
|
+
return displayRotation;
|
|
21
|
+
}
|
|
22
|
+
return deviceRotation;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static boolean usesDeviceOrientation(String orientationMode) {
|
|
26
|
+
return !ORIENTATION_PREVIEW.equals(orientationMode);
|
|
27
|
+
}
|
|
28
|
+
}
|
package/android/src/test/java/app/capgo/capacitor/camera/preview/CaptureOrientationResolverTest.java
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package app.capgo.capacitor.camera.preview;
|
|
2
|
+
|
|
3
|
+
import static org.junit.Assert.assertEquals;
|
|
4
|
+
import static org.junit.Assert.assertFalse;
|
|
5
|
+
import static org.junit.Assert.assertTrue;
|
|
6
|
+
|
|
7
|
+
import android.view.Surface;
|
|
8
|
+
import org.junit.Test;
|
|
9
|
+
import org.junit.runner.RunWith;
|
|
10
|
+
import org.robolectric.RobolectricTestRunner;
|
|
11
|
+
import org.robolectric.annotation.Config;
|
|
12
|
+
|
|
13
|
+
@RunWith(RobolectricTestRunner.class)
|
|
14
|
+
@Config(manifest = Config.NONE, sdk = 28)
|
|
15
|
+
public class CaptureOrientationResolverTest {
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
public void defaultsToDeviceRotation() {
|
|
19
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation(null, Surface.ROTATION_0, Surface.ROTATION_90));
|
|
20
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation("", Surface.ROTATION_0, Surface.ROTATION_90));
|
|
21
|
+
assertEquals(Surface.ROTATION_90, CaptureOrientationResolver.resolveRotation("device", Surface.ROTATION_0, Surface.ROTATION_90));
|
|
22
|
+
assertTrue(CaptureOrientationResolver.usesDeviceOrientation(null));
|
|
23
|
+
assertTrue(CaptureOrientationResolver.usesDeviceOrientation("device"));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
public void previewModeUsesDisplayRotation() {
|
|
28
|
+
assertEquals(Surface.ROTATION_270, CaptureOrientationResolver.resolveRotation("preview", Surface.ROTATION_270, Surface.ROTATION_0));
|
|
29
|
+
assertFalse(CaptureOrientationResolver.usesDeviceOrientation("preview"));
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -1066,7 +1066,7 @@
|
|
|
1066
1066
|
"text": "android, ios"
|
|
1067
1067
|
}
|
|
1068
1068
|
],
|
|
1069
|
-
"docs": "Gets the current preview
|
|
1069
|
+
"docs": "Gets the current visible camera preview bounds in web-view coordinates.\n\nWith `aspectMode: 'contain'`, this is the letterboxed camera image rect inside the\npreview container (not the full container when bars are shown). With `aspectMode: 'cover'`,\nthis matches the preview container bounds on both platforms.",
|
|
1070
1070
|
"complexTypes": [],
|
|
1071
1071
|
"slug": "getpreviewsize"
|
|
1072
1072
|
},
|
|
@@ -1088,7 +1088,7 @@
|
|
|
1088
1088
|
},
|
|
1089
1089
|
{
|
|
1090
1090
|
"name": "returns",
|
|
1091
|
-
"text": "A promise that resolves with the
|
|
1091
|
+
"text": "A promise that resolves with the visible camera preview bounds (same contract as {@link CameraPreviewPlugin.getPreviewSize})."
|
|
1092
1092
|
},
|
|
1093
1093
|
{
|
|
1094
1094
|
"name": "since",
|
|
@@ -2086,15 +2086,19 @@
|
|
|
2086
2086
|
"name": "captureResolution",
|
|
2087
2087
|
"tags": [
|
|
2088
2088
|
{
|
|
2089
|
-
"text": "android",
|
|
2089
|
+
"text": "android, ios",
|
|
2090
2090
|
"name": "platform"
|
|
2091
2091
|
},
|
|
2092
2092
|
{
|
|
2093
2093
|
"text": "8.12.0",
|
|
2094
2094
|
"name": "since"
|
|
2095
|
+
},
|
|
2096
|
+
{
|
|
2097
|
+
"text": "8.13.0 (iOS)",
|
|
2098
|
+
"name": "since"
|
|
2095
2099
|
}
|
|
2096
2100
|
],
|
|
2097
|
-
"docs": "Sets the
|
|
2101
|
+
"docs": "Sets the still-capture sensor resolution cap at session start. Preview resolution is unchanged.\nThe shared ViewPort crop from the preview still applies to captures.\n\nOn Android this binds the `ImageCapture` use case to the requested size. On iOS 16+ this sets\n`AVCapturePhotoSettings.maxPhotoDimensions` (and disables high-resolution photo capture when capped)\nso the sensor delivers fewer pixels instead of downscaling a full-sensor frame in software.\nOn iOS 15, `start()` rejects this option.\n\nWhen omitted, capture uses the highest resolution supported by the active camera\n(same as versions before 8.11.10 on Android, and the format default on iOS). Set this to cap\ncapture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }`\nor `{ width: 1600, height: 1200 }`.",
|
|
2098
2102
|
"complexTypes": [
|
|
2099
2103
|
"CameraCaptureResolution"
|
|
2100
2104
|
],
|
|
@@ -2485,6 +2489,22 @@
|
|
|
2485
2489
|
"docs": "If true and the front camera is active, horizontally mirror the captured photo\nso it matches a selfie-style preview. Rear camera captures are never mirrored.\nDefaults to false to preserve the previous non-mirrored behavior.",
|
|
2486
2490
|
"complexTypes": [],
|
|
2487
2491
|
"type": "boolean | undefined"
|
|
2492
|
+
},
|
|
2493
|
+
{
|
|
2494
|
+
"name": "orientation",
|
|
2495
|
+
"tags": [
|
|
2496
|
+
{
|
|
2497
|
+
"text": "\"device\"",
|
|
2498
|
+
"name": "default"
|
|
2499
|
+
},
|
|
2500
|
+
{
|
|
2501
|
+
"text": "8.13.0",
|
|
2502
|
+
"name": "since"
|
|
2503
|
+
}
|
|
2504
|
+
],
|
|
2505
|
+
"docs": "Which orientation to apply to the captured photo.\n- `\"device\"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked.\n- `\"preview\"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera.",
|
|
2506
|
+
"complexTypes": [],
|
|
2507
|
+
"type": "'preview' | 'device' | undefined"
|
|
2488
2508
|
}
|
|
2489
2509
|
]
|
|
2490
2510
|
},
|
|
@@ -314,15 +314,22 @@ export interface CameraPreviewOptions {
|
|
|
314
314
|
*/
|
|
315
315
|
enableVideoMode?: boolean;
|
|
316
316
|
/**
|
|
317
|
-
* Sets the
|
|
318
|
-
*
|
|
317
|
+
* Sets the still-capture sensor resolution cap at session start. Preview resolution is unchanged.
|
|
318
|
+
* The shared ViewPort crop from the preview still applies to captures.
|
|
319
319
|
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
320
|
+
* On Android this binds the `ImageCapture` use case to the requested size. On iOS 16+ this sets
|
|
321
|
+
* `AVCapturePhotoSettings.maxPhotoDimensions` (and disables high-resolution photo capture when capped)
|
|
322
|
+
* so the sensor delivers fewer pixels instead of downscaling a full-sensor frame in software.
|
|
323
|
+
* On iOS 15, `start()` rejects this option.
|
|
323
324
|
*
|
|
324
|
-
*
|
|
325
|
+
* When omitted, capture uses the highest resolution supported by the active camera
|
|
326
|
+
* (same as versions before 8.11.10 on Android, and the format default on iOS). Set this to cap
|
|
327
|
+
* capture size for faster shots on high-megapixel sensors, for example `{ width: 1920, height: 1080 }`
|
|
328
|
+
* or `{ width: 1600, height: 1200 }`.
|
|
329
|
+
*
|
|
330
|
+
* @platform android, ios
|
|
325
331
|
* @since 8.12.0
|
|
332
|
+
* @since 8.13.0 (iOS)
|
|
326
333
|
*/
|
|
327
334
|
captureResolution?: CameraCaptureResolution;
|
|
328
335
|
/**
|
|
@@ -468,6 +475,14 @@ export interface CameraPreviewPictureOptions {
|
|
|
468
475
|
* @since 8.10.0
|
|
469
476
|
*/
|
|
470
477
|
mirrorFrontCamera?: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Which orientation to apply to the captured photo.
|
|
480
|
+
* - `"device"`: uses physical device tilt from the accelerometer (default). Preserves landscape captures when the app UI is rotation-locked.
|
|
481
|
+
* - `"preview"`: matches the on-screen preview. Use for WYSIWYG capture, including retakes without stopping the camera.
|
|
482
|
+
* @default "device"
|
|
483
|
+
* @since 8.13.0
|
|
484
|
+
*/
|
|
485
|
+
orientation?: 'preview' | 'device';
|
|
471
486
|
}
|
|
472
487
|
/** Represents EXIF data extracted from an image. */
|
|
473
488
|
export interface ExifData {
|
|
@@ -966,7 +981,12 @@ export interface CameraPreviewPlugin {
|
|
|
966
981
|
deviceId: string;
|
|
967
982
|
}>;
|
|
968
983
|
/**
|
|
969
|
-
* Gets the current preview
|
|
984
|
+
* Gets the current visible camera preview bounds in web-view coordinates.
|
|
985
|
+
*
|
|
986
|
+
* With `aspectMode: 'contain'`, this is the letterboxed camera image rect inside the
|
|
987
|
+
* preview container (not the full container when bars are shown). With `aspectMode: 'cover'`,
|
|
988
|
+
* this matches the preview container bounds on both platforms.
|
|
989
|
+
*
|
|
970
990
|
* @returns {Promise<{x: number, y: number, width: number, height: number}>}
|
|
971
991
|
* @since 7.5.0
|
|
972
992
|
* @platform android, ios
|
|
@@ -980,7 +1000,7 @@ export interface CameraPreviewPlugin {
|
|
|
980
1000
|
/**
|
|
981
1001
|
* Sets the preview size and position.
|
|
982
1002
|
* @param options The new position and dimensions.
|
|
983
|
-
* @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the
|
|
1003
|
+
* @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the visible camera preview bounds (same contract as {@link CameraPreviewPlugin.getPreviewSize}).
|
|
984
1004
|
* @since 7.5.0
|
|
985
1005
|
* @platform android, ios
|
|
986
1006
|
*/
|