@capgo/camera-preview 7.4.0-beta.12 → 7.4.0-beta.15

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.
@@ -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
@@ -83,7 +84,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
83
84
  var toBack: Bool?
84
85
  var storeToFile: Bool?
85
86
  var enableZoom: Bool?
86
- var highResolutionOutput: Bool = false
87
87
  var disableAudio: Bool = false
88
88
  var locationManager: CLLocationManager?
89
89
  var currentLocation: CLLocation?
@@ -411,8 +411,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
411
411
  self.cameraPosition = call.getString("position") ?? "rear"
412
412
  let deviceId = call.getString("deviceId")
413
413
  let cameraMode = call.getBool("cameraMode") ?? false
414
- self.highResolutionOutput = call.getBool("enableHighResolution") ?? false
415
- self.cameraController.highResolutionOutput = self.highResolutionOutput
416
414
 
417
415
  // Set width - use screen width if not provided or if 0
418
416
  if let width = call.getInt("width"), width > 0 {
@@ -452,6 +450,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
452
450
  self.disableAudio = call.getBool("disableAudio") ?? true
453
451
  self.aspectRatio = call.getString("aspectRatio")
454
452
  self.gridMode = call.getString("gridMode") ?? "none"
453
+ let initialZoomLevel = call.getFloat("initialZoomLevel") ?? 1.0
455
454
  if self.aspectRatio != nil && (call.getInt("width") != nil || call.getInt("height") != nil) {
456
455
  call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.")
457
456
  return
@@ -470,12 +469,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
470
469
  if self.cameraController.captureSession?.isRunning ?? false {
471
470
  call.reject("camera already started")
472
471
  } else {
473
- // Pre-initialize session if not already done
474
- if self.cameraController.captureSession == nil {
475
- self.cameraController.prepareFullSession()
476
- }
477
-
478
- self.cameraController.prepare(cameraPosition: self.cameraPosition, deviceId: deviceId, disableAudio: self.disableAudio, cameraMode: cameraMode, aspectRatio: self.aspectRatio) {error in
472
+ self.cameraController.prepare(cameraPosition: self.cameraPosition, deviceId: deviceId, disableAudio: self.disableAudio, cameraMode: cameraMode, aspectRatio: self.aspectRatio, initialZoomLevel: Float(initialZoomLevel)) {error in
479
473
  if let error = error {
480
474
  print(error)
481
475
  call.reject(error.localizedDescription)
@@ -699,7 +693,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
699
693
  return
700
694
  }
701
695
 
702
- guard let imageDataWithExif = self.createImageDataWithExif(from: image!, quality: Int(quality), location: withExifLocation ? self.currentLocation : nil) else {
696
+ guard let image = image,
697
+ let imageDataWithExif = self.createImageDataWithExif(
698
+ from: image,
699
+ quality: Int(quality),
700
+ location: withExifLocation ? self.currentLocation : nil
701
+ )
702
+ else {
703
703
  print("[CameraPreview] Failed to create image data with EXIF")
704
704
  call.reject("Failed to create image data with EXIF")
705
705
  return
@@ -1059,9 +1059,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1059
1059
  }
1060
1060
 
1061
1061
  let ramp = call.getBool("ramp") ?? true
1062
+ let autoFocus = call.getBool("autoFocus") ?? true
1062
1063
 
1063
1064
  do {
1064
- try self.cameraController.setZoom(level: CGFloat(level), ramp: ramp)
1065
+ try self.cameraController.setZoom(level: CGFloat(level), ramp: ramp, autoFocus: autoFocus)
1065
1066
  call.resolve()
1066
1067
  } catch {
1067
1068
  call.reject("Failed to set zoom: \(error.localizedDescription)")
@@ -1330,10 +1331,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1330
1331
 
1331
1332
  // Handle auto-centering when position is -1
1332
1333
  if posX == -1 || posY == -1 {
1333
- finalWidth = webViewWidth
1334
+ // Only override dimensions if aspect ratio is provided and no explicit dimensions given
1335
+ if let aspectRatio = self.aspectRatio, width == UIScreen.main.bounds.size.width && height == UIScreen.main.bounds.size.height {
1336
+ finalWidth = webViewWidth
1334
1337
 
1335
- // Calculate height based on aspect ratio or use provided height
1336
- if let aspectRatio = self.aspectRatio {
1338
+ // Calculate height based on aspect ratio
1337
1339
  let ratioParts = aspectRatio.split(separator: ":").compactMap { Double($0) }
1338
1340
  if ratioParts.count == 2 {
1339
1341
  // For camera, use portrait orientation: 4:3 becomes 3:4, 16:9 becomes 9:16
@@ -1342,11 +1344,21 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1342
1344
  }
1343
1345
  }
1344
1346
 
1345
- finalX = posX == -1 ? 0 : posX
1347
+ // Center horizontally if x is -1
1348
+ if posX == -1 {
1349
+ finalX = (webViewWidth - finalWidth) / 2
1350
+ } else {
1351
+ finalX = posX
1352
+ }
1346
1353
 
1354
+ // Center vertically if y is -1
1347
1355
  if posY == -1 {
1348
- let availableHeight = webViewHeight - paddingBottom
1349
- finalY = finalHeight < availableHeight ? (availableHeight - finalHeight) / 2 : 0
1356
+ // Use full screen height for centering
1357
+ let screenHeight = UIScreen.main.bounds.size.height
1358
+ finalY = (screenHeight - finalHeight) / 2
1359
+ print("[CameraPreview] Centering vertically: screenHeight=\(screenHeight), finalHeight=\(finalHeight), finalY=\(finalY)")
1360
+ } else {
1361
+ finalY = posY
1350
1362
  }
1351
1363
  }
1352
1364
 
@@ -1443,4 +1455,43 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1443
1455
  call.resolve(result)
1444
1456
  }
1445
1457
  }
1458
+
1459
+ @objc func setFocus(_ call: CAPPluginCall) {
1460
+ guard isInitialized else {
1461
+ call.reject("Camera not initialized")
1462
+ return
1463
+ }
1464
+
1465
+ guard let x = call.getFloat("x"), let y = call.getFloat("y") else {
1466
+ call.reject("x and y parameters are required")
1467
+ return
1468
+ }
1469
+
1470
+ // Reject if values are outside 0-1 range
1471
+ if x < 0 || x > 1 || y < 0 || y > 1 {
1472
+ call.reject("Focus coordinates must be between 0 and 1")
1473
+ return
1474
+ }
1475
+
1476
+ DispatchQueue.main.async {
1477
+ do {
1478
+ // Convert normalized coordinates to view coordinates
1479
+ let viewX = CGFloat(x) * self.previewView.bounds.width
1480
+ let viewY = CGFloat(y) * self.previewView.bounds.height
1481
+ let focusPoint = CGPoint(x: viewX, y: viewY)
1482
+
1483
+ // Convert view coordinates to device coordinates
1484
+ guard let previewLayer = self.cameraController.previewLayer else {
1485
+ call.reject("Preview layer not available")
1486
+ return
1487
+ }
1488
+ let devicePoint = previewLayer.captureDevicePointConverted(fromLayerPoint: focusPoint)
1489
+
1490
+ try self.cameraController.setFocus(at: devicePoint)
1491
+ call.resolve()
1492
+ } catch {
1493
+ call.reject("Failed to set focus: \(error.localizedDescription)")
1494
+ }
1495
+ }
1496
+ }
1446
1497
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.4.0-beta.12",
3
+ "version": "7.4.0-beta.15",
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": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -sdk iphoneos -scheme Plugin && cd ..",
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",