@capgo/camera-preview 7.4.0-beta.11 → 7.4.0-beta.13
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 +18 -0
- package/android/.gradle/8.14.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.14.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.14.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +27 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +59 -25
- package/dist/docs.json +29 -0
- package/dist/esm/definitions.d.ts +13 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +33 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +33 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +33 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreview/CameraController.swift +60 -7
- package/ios/Sources/CapgoCameraPreview/Plugin.swift +39 -1
- package/package.json +2 -2
|
@@ -66,8 +66,8 @@ extension CameraController {
|
|
|
66
66
|
self.captureSession = AVCaptureSession()
|
|
67
67
|
|
|
68
68
|
// 2. Pre-configure session preset (can be changed later)
|
|
69
|
-
if captureSession!.canSetSessionPreset(.
|
|
70
|
-
captureSession!.sessionPreset = .
|
|
69
|
+
if captureSession!.canSetSessionPreset(.high) {
|
|
70
|
+
captureSession!.sessionPreset = .high
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// 3. Discover and configure all cameras
|
|
@@ -258,8 +258,9 @@ extension CameraController {
|
|
|
258
258
|
guard let captureSession = self.captureSession else { throw CameraControllerError.captureSessionIsMissing }
|
|
259
259
|
|
|
260
260
|
// Update session preset based on aspect ratio if needed
|
|
261
|
+
var targetPreset: AVCaptureSession.Preset = .high // Default to high quality
|
|
262
|
+
|
|
261
263
|
if let aspectRatio = aspectRatio {
|
|
262
|
-
var targetPreset: AVCaptureSession.Preset
|
|
263
264
|
switch aspectRatio {
|
|
264
265
|
case "16:9":
|
|
265
266
|
targetPreset = captureSession.canSetSessionPreset(.hd1920x1080) ? .hd1920x1080 : .high
|
|
@@ -268,11 +269,16 @@ extension CameraController {
|
|
|
268
269
|
default:
|
|
269
270
|
targetPreset = .high
|
|
270
271
|
}
|
|
272
|
+
}
|
|
271
273
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
// Always try to set the best preset available
|
|
275
|
+
if captureSession.canSetSessionPreset(targetPreset) {
|
|
276
|
+
captureSession.sessionPreset = targetPreset
|
|
277
|
+
print("[CameraPreview] Updated preset to \(targetPreset) for aspect ratio: \(aspectRatio ?? "default")")
|
|
278
|
+
} else if captureSession.canSetSessionPreset(.high) {
|
|
279
|
+
// Fallback to high if target preset not available
|
|
280
|
+
captureSession.sessionPreset = .high
|
|
281
|
+
print("[CameraPreview] Fallback to high preset")
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
// Add photo output (already created in prepareOutputs)
|
|
@@ -307,6 +313,9 @@ extension CameraController {
|
|
|
307
313
|
self.previewLayer?.connection?.videoOrientation = .portrait
|
|
308
314
|
self.previewLayer?.isOpaque = true
|
|
309
315
|
|
|
316
|
+
// Set contentsScale for retina display quality
|
|
317
|
+
self.previewLayer?.contentsScale = UIScreen.main.scale
|
|
318
|
+
|
|
310
319
|
// Enable high-quality rendering
|
|
311
320
|
if #available(iOS 13.0, *) {
|
|
312
321
|
self.previewLayer?.videoGravity = .resizeAspectFill
|
|
@@ -776,6 +785,50 @@ extension CameraController {
|
|
|
776
785
|
}
|
|
777
786
|
}
|
|
778
787
|
|
|
788
|
+
func setFocus(at point: CGPoint) throws {
|
|
789
|
+
var currentCamera: AVCaptureDevice?
|
|
790
|
+
switch currentCameraPosition {
|
|
791
|
+
case .front:
|
|
792
|
+
currentCamera = self.frontCamera
|
|
793
|
+
case .rear:
|
|
794
|
+
currentCamera = self.rearCamera
|
|
795
|
+
default: break
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
guard let device = currentCamera else {
|
|
799
|
+
throw CameraControllerError.noCamerasAvailable
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
guard device.isFocusPointOfInterestSupported else {
|
|
803
|
+
// Device doesn't support focus point of interest
|
|
804
|
+
return
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
do {
|
|
808
|
+
try device.lockForConfiguration()
|
|
809
|
+
|
|
810
|
+
// Set focus mode to auto if supported
|
|
811
|
+
if device.isFocusModeSupported(.autoFocus) {
|
|
812
|
+
device.focusMode = .autoFocus
|
|
813
|
+
} else if device.isFocusModeSupported(.continuousAutoFocus) {
|
|
814
|
+
device.focusMode = .continuousAutoFocus
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// Set the focus point
|
|
818
|
+
device.focusPointOfInterest = point
|
|
819
|
+
|
|
820
|
+
// Also set exposure point if supported
|
|
821
|
+
if device.isExposurePointOfInterestSupported && device.isExposureModeSupported(.autoExpose) {
|
|
822
|
+
device.exposureMode = .autoExpose
|
|
823
|
+
device.exposurePointOfInterest = point
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
device.unlockForConfiguration()
|
|
827
|
+
} catch {
|
|
828
|
+
throw CameraControllerError.unknown
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
779
832
|
func getFlashMode() throws -> String {
|
|
780
833
|
switch self.flashMode {
|
|
781
834
|
case .off:
|
|
@@ -64,7 +64,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
64
64
|
CAPPluginMethod(name: "setGridMode", returnType: CAPPluginReturnPromise),
|
|
65
65
|
CAPPluginMethod(name: "getGridMode", returnType: CAPPluginReturnPromise),
|
|
66
66
|
CAPPluginMethod(name: "getPreviewSize", returnType: CAPPluginReturnPromise),
|
|
67
|
-
CAPPluginMethod(name: "setPreviewSize", returnType: CAPPluginReturnPromise)
|
|
67
|
+
CAPPluginMethod(name: "setPreviewSize", returnType: CAPPluginReturnPromise),
|
|
68
|
+
CAPPluginMethod(name: "setFocus", returnType: CAPPluginReturnPromise)
|
|
68
69
|
]
|
|
69
70
|
// Camera state tracking
|
|
70
71
|
private var isInitializing: Bool = false
|
|
@@ -1443,4 +1444,41 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
1443
1444
|
call.resolve(result)
|
|
1444
1445
|
}
|
|
1445
1446
|
}
|
|
1447
|
+
|
|
1448
|
+
@objc func setFocus(_ call: CAPPluginCall) {
|
|
1449
|
+
guard isInitialized else {
|
|
1450
|
+
call.reject("Camera not initialized")
|
|
1451
|
+
return
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
guard let x = call.getFloat("x"), let y = call.getFloat("y") else {
|
|
1455
|
+
call.reject("x and y parameters are required")
|
|
1456
|
+
return
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// Ensure values are between 0 and 1
|
|
1460
|
+
let normalizedX = max(0, min(1, x))
|
|
1461
|
+
let normalizedY = max(0, min(1, y))
|
|
1462
|
+
|
|
1463
|
+
DispatchQueue.main.async {
|
|
1464
|
+
do {
|
|
1465
|
+
// Convert normalized coordinates to view coordinates
|
|
1466
|
+
let viewX = CGFloat(normalizedX) * self.previewView.bounds.width
|
|
1467
|
+
let viewY = CGFloat(normalizedY) * self.previewView.bounds.height
|
|
1468
|
+
let focusPoint = CGPoint(x: viewX, y: viewY)
|
|
1469
|
+
|
|
1470
|
+
// Convert view coordinates to device coordinates
|
|
1471
|
+
guard let previewLayer = self.cameraController.previewLayer else {
|
|
1472
|
+
call.reject("Preview layer not available")
|
|
1473
|
+
return
|
|
1474
|
+
}
|
|
1475
|
+
let devicePoint = previewLayer.captureDevicePointConverted(fromLayerPoint: focusPoint)
|
|
1476
|
+
|
|
1477
|
+
try self.cameraController.setFocus(at: devicePoint)
|
|
1478
|
+
call.resolve()
|
|
1479
|
+
} catch {
|
|
1480
|
+
call.reject("Failed to set focus: \(error.localizedDescription)")
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1446
1484
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/camera-preview",
|
|
3
|
-
"version": "7.4.0-beta.
|
|
3
|
+
"version": "7.4.0-beta.13",
|
|
4
4
|
"description": "Camera preview",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
31
|
-
"verify:ios": "
|
|
31
|
+
"verify:ios": "xcodebuild -scheme CapgoCameraPreview -destination generic/platform=iOS",
|
|
32
32
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
33
33
|
"verify:web": "npm run build",
|
|
34
34
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|