@capgo/camera-preview 7.4.0-beta.13 → 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.
@@ -84,7 +84,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
84
84
  var toBack: Bool?
85
85
  var storeToFile: Bool?
86
86
  var enableZoom: Bool?
87
- var highResolutionOutput: Bool = false
88
87
  var disableAudio: Bool = false
89
88
  var locationManager: CLLocationManager?
90
89
  var currentLocation: CLLocation?
@@ -412,8 +411,6 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
412
411
  self.cameraPosition = call.getString("position") ?? "rear"
413
412
  let deviceId = call.getString("deviceId")
414
413
  let cameraMode = call.getBool("cameraMode") ?? false
415
- self.highResolutionOutput = call.getBool("enableHighResolution") ?? false
416
- self.cameraController.highResolutionOutput = self.highResolutionOutput
417
414
 
418
415
  // Set width - use screen width if not provided or if 0
419
416
  if let width = call.getInt("width"), width > 0 {
@@ -453,6 +450,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
453
450
  self.disableAudio = call.getBool("disableAudio") ?? true
454
451
  self.aspectRatio = call.getString("aspectRatio")
455
452
  self.gridMode = call.getString("gridMode") ?? "none"
453
+ let initialZoomLevel = call.getFloat("initialZoomLevel") ?? 1.0
456
454
  if self.aspectRatio != nil && (call.getInt("width") != nil || call.getInt("height") != nil) {
457
455
  call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.")
458
456
  return
@@ -471,12 +469,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
471
469
  if self.cameraController.captureSession?.isRunning ?? false {
472
470
  call.reject("camera already started")
473
471
  } else {
474
- // Pre-initialize session if not already done
475
- if self.cameraController.captureSession == nil {
476
- self.cameraController.prepareFullSession()
477
- }
478
-
479
- 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
480
473
  if let error = error {
481
474
  print(error)
482
475
  call.reject(error.localizedDescription)
@@ -700,7 +693,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
700
693
  return
701
694
  }
702
695
 
703
- 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 {
704
703
  print("[CameraPreview] Failed to create image data with EXIF")
705
704
  call.reject("Failed to create image data with EXIF")
706
705
  return
@@ -1060,9 +1059,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1060
1059
  }
1061
1060
 
1062
1061
  let ramp = call.getBool("ramp") ?? true
1062
+ let autoFocus = call.getBool("autoFocus") ?? true
1063
1063
 
1064
1064
  do {
1065
- try self.cameraController.setZoom(level: CGFloat(level), ramp: ramp)
1065
+ try self.cameraController.setZoom(level: CGFloat(level), ramp: ramp, autoFocus: autoFocus)
1066
1066
  call.resolve()
1067
1067
  } catch {
1068
1068
  call.reject("Failed to set zoom: \(error.localizedDescription)")
@@ -1331,10 +1331,11 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1331
1331
 
1332
1332
  // Handle auto-centering when position is -1
1333
1333
  if posX == -1 || posY == -1 {
1334
- 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
1335
1337
 
1336
- // Calculate height based on aspect ratio or use provided height
1337
- if let aspectRatio = self.aspectRatio {
1338
+ // Calculate height based on aspect ratio
1338
1339
  let ratioParts = aspectRatio.split(separator: ":").compactMap { Double($0) }
1339
1340
  if ratioParts.count == 2 {
1340
1341
  // For camera, use portrait orientation: 4:3 becomes 3:4, 16:9 becomes 9:16
@@ -1343,11 +1344,21 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1343
1344
  }
1344
1345
  }
1345
1346
 
1346
- 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
+ }
1347
1353
 
1354
+ // Center vertically if y is -1
1348
1355
  if posY == -1 {
1349
- let availableHeight = webViewHeight - paddingBottom
1350
- 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
1351
1362
  }
1352
1363
  }
1353
1364
 
@@ -1456,15 +1467,17 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1456
1467
  return
1457
1468
  }
1458
1469
 
1459
- // Ensure values are between 0 and 1
1460
- let normalizedX = max(0, min(1, x))
1461
- let normalizedY = max(0, min(1, y))
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
+ }
1462
1475
 
1463
1476
  DispatchQueue.main.async {
1464
1477
  do {
1465
1478
  // Convert normalized coordinates to view coordinates
1466
- let viewX = CGFloat(normalizedX) * self.previewView.bounds.width
1467
- let viewY = CGFloat(normalizedY) * self.previewView.bounds.height
1479
+ let viewX = CGFloat(x) * self.previewView.bounds.width
1480
+ let viewY = CGFloat(y) * self.previewView.bounds.height
1468
1481
  let focusPoint = CGPoint(x: viewX, y: viewY)
1469
1482
 
1470
1483
  // Convert view coordinates to device coordinates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.4.0-beta.13",
3
+ "version": "7.4.0-beta.15",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {