@capgo/camera-preview 7.4.0-beta.20 → 7.4.0-beta.22

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.
@@ -89,6 +89,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
89
89
  var currentLocation: CLLocation?
90
90
  private var aspectRatio: String?
91
91
  private var gridMode: String = "none"
92
+ private var positioning: String = "center"
92
93
  private var permissionCallID: String?
93
94
  private var waitingForLocation: Bool = false
94
95
 
@@ -435,6 +436,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
435
436
  self.disableAudio = call.getBool("disableAudio") ?? true
436
437
  self.aspectRatio = call.getString("aspectRatio")
437
438
  self.gridMode = call.getString("gridMode") ?? "none"
439
+ self.positioning = call.getString("positioning") ?? "top"
438
440
  let initialZoomLevel = call.getFloat("initialZoomLevel") ?? 1.0
439
441
  if self.aspectRatio != nil && (call.getInt("width") != nil || call.getInt("height") != nil) {
440
442
  call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.")
@@ -472,6 +474,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
472
474
  // Create and configure the preview view first
473
475
  self.updateCameraFrame()
474
476
 
477
+ print("[CameraPreview] completeStartCamera - Preview frame after updateCameraFrame: \(self.previewView.frame)")
478
+
475
479
  // Make webview transparent - comprehensive approach
476
480
  self.makeWebViewTransparent()
477
481
 
@@ -505,7 +509,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
505
509
  // Set up callback to wait for first frame before resolving
506
510
  self.cameraController.firstFrameReadyCallback = { [weak self] in
507
511
  guard let self = self else { return }
508
-
512
+
509
513
  DispatchQueue.main.async {
510
514
  var returnedObject = JSObject()
511
515
  returnedObject["width"] = self.previewView.frame.width as any JSValue
@@ -515,7 +519,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
515
519
  call.resolve(returnedObject)
516
520
  }
517
521
  }
518
-
522
+
519
523
  // If already received first frame (unlikely but possible), resolve immediately
520
524
  if self.cameraController.hasReceivedFirstFrame {
521
525
  var returnedObject = JSObject()
@@ -601,6 +605,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
601
605
  }
602
606
 
603
607
  @objc func capture(_ call: CAPPluginCall) {
608
+ print("[CameraPreview] capture called with options: \(call.options)")
604
609
  let withExifLocation = call.getBool("withExifLocation", false)
605
610
  print("[CameraPreview] capture called, withExifLocation: \(withExifLocation)")
606
611
 
@@ -675,6 +680,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
675
680
 
676
681
  private func performCapture(call: CAPPluginCall) {
677
682
  print("[CameraPreview] performCapture called")
683
+ print("[CameraPreview] Call parameters: \(call.options)")
678
684
  let quality = call.getFloat("quality", 85)
679
685
  let saveToGallery = call.getBool("saveToGallery", false)
680
686
  let withExifLocation = call.getBool("withExifLocation", false)
@@ -682,6 +688,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
682
688
  let height = call.getInt("height")
683
689
  let aspectRatio = call.getString("aspectRatio")
684
690
 
691
+ print("[CameraPreview] Raw parameter values - width: \(String(describing: width)), height: \(String(describing: height)), aspectRatio: \(String(describing: aspectRatio))")
692
+
685
693
  // Check for conflicting parameters
686
694
  if aspectRatio != nil && (width != nil || height != nil) {
687
695
  print("[CameraPreview] Error: Cannot set both aspectRatio and size (width/height)")
@@ -689,16 +697,18 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
689
697
  return
690
698
  }
691
699
 
692
- // Use the stored aspectRatio if none is provided and no width/height is specified
693
- // If no aspectRatio was set at all, use "4:3" as default (matching getAspectRatio behavior)
694
- let captureAspectRatio: String? = if width == nil && height == nil && aspectRatio == nil {
695
- self.aspectRatio ?? "4:3"
696
- } else {
697
- aspectRatio
698
- }
699
-
700
+ // When no dimensions are specified, we should capture exactly what's visible in the preview
701
+ // Don't pass aspectRatio in this case - let the capture method handle preview matching
702
+ print("[CameraPreview] Capture decision - width: \(width == nil), height: \(height == nil), aspectRatio param: \(aspectRatio == nil)")
703
+ print("[CameraPreview] Stored aspectRatio: \(self.aspectRatio ?? "nil")")
704
+
705
+ // Only pass aspectRatio if explicitly provided in the capture call
706
+ // Never use the stored aspectRatio when capturing without dimensions
707
+ let captureAspectRatio: String? = aspectRatio
708
+
700
709
  print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation), width: \(width ?? -1), height: \(height ?? -1), aspectRatio: \(aspectRatio ?? "nil"), using aspectRatio: \(captureAspectRatio ?? "nil")")
701
710
  print("[CameraPreview] Current location: \(self.currentLocation?.description ?? "nil")")
711
+ print("[CameraPreview] Preview dimensions: \(self.previewView.frame.width)x\(self.previewView.frame.height)")
702
712
 
703
713
  self.cameraController.captureImage(width: width, height: height, aspectRatio: captureAspectRatio, quality: quality, gpsLocation: self.currentLocation) { (image, error) in
704
714
  print("[CameraPreview] captureImage callback received")
@@ -1344,9 +1354,9 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1344
1354
  // Handle auto-centering when position is -1
1345
1355
  if currentX == -1 || currentY == -1 {
1346
1356
  // Only override dimensions if aspect ratio is provided and no explicit dimensions given
1347
- if let ratio = currentAspectRatio,
1348
- currentWidth == UIScreen.main.bounds.size.width &&
1349
- currentHeight == UIScreen.main.bounds.size.height {
1357
+ if let ratio = currentAspectRatio,
1358
+ currentWidth == UIScreen.main.bounds.size.width &&
1359
+ currentHeight == UIScreen.main.bounds.size.height {
1350
1360
  finalWidth = webViewWidth
1351
1361
 
1352
1362
  // Calculate height based on aspect ratio
@@ -1365,12 +1375,21 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1365
1375
  finalX = currentX
1366
1376
  }
1367
1377
 
1368
- // Center vertically if y is -1
1378
+ // Position vertically if y is -1
1369
1379
  if currentY == -1 {
1370
- // Use full screen height for centering
1380
+ // Use full screen height for positioning
1371
1381
  let screenHeight = UIScreen.main.bounds.size.height
1372
- finalY = (screenHeight - finalHeight) / 2
1373
- print("[CameraPreview] Centering vertically: screenHeight=\(screenHeight), finalHeight=\(finalHeight), finalY=\(finalY)")
1382
+ switch self.positioning {
1383
+ case "top":
1384
+ finalY = 0
1385
+ print("[CameraPreview] Positioning at top: finalY=0")
1386
+ case "bottom":
1387
+ finalY = screenHeight - finalHeight
1388
+ print("[CameraPreview] Positioning at bottom: screenHeight=\(screenHeight), finalHeight=\(finalHeight), finalY=\(finalY)")
1389
+ default: // "center"
1390
+ finalY = (screenHeight - finalHeight) / 2
1391
+ print("[CameraPreview] Centering vertically: screenHeight=\(screenHeight), finalHeight=\(finalHeight), finalY=\(finalY)")
1392
+ }
1374
1393
  } else {
1375
1394
  finalY = currentY
1376
1395
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.4.0-beta.20",
3
+ "version": "7.4.0-beta.22",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {