@capgo/camera-preview 8.0.1 → 8.0.2

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.
@@ -34,7 +34,7 @@ extension UIWindow {
34
34
  */
35
35
  @objc(CameraPreview)
36
36
  public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
37
- private let pluginVersion: String = "8.0.1"
37
+ private let pluginVersion: String = "8.0.2"
38
38
  public let identifier = "CameraPreviewPlugin"
39
39
  public let jsName = "CameraPreview"
40
40
  public let pluginMethods: [CAPPluginMethod] = [
@@ -470,8 +470,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
470
470
  availableHeight = webViewHeight - paddingBottom
471
471
  } else {
472
472
  // Manual positioning - calculate remaining space
473
- availableWidth = webViewWidth - self.posX!
474
- availableHeight = webViewHeight - self.posY! - paddingBottom
473
+ availableWidth = webViewWidth - (self.posX ?? 0)
474
+ availableHeight = webViewHeight - (self.posY ?? 0) - paddingBottom
475
475
  }
476
476
 
477
477
  // Parse aspect ratio - convert to portrait orientation for camera use
@@ -722,20 +722,20 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
722
722
  }
723
723
 
724
724
  // Set x position - use exact CSS pixel value from web view, or mark for centering
725
- if let x = call.getInt("x") {
726
- self.posX = CGFloat(x)
725
+ if let xPosition = call.getInt("x") {
726
+ self.posX = CGFloat(xPosition)
727
727
  } else {
728
728
  self.posX = -1 // Use -1 to indicate auto-centering
729
729
  }
730
730
 
731
731
  // Set y position - use exact CSS pixel value from web view, or mark for centering
732
- if let y = call.getInt("y") {
733
- self.posY = CGFloat(y)
732
+ if let yPosition = call.getInt("y") {
733
+ self.posY = CGFloat(yPosition)
734
734
  } else {
735
735
  self.posY = -1 // Use -1 to indicate auto-centering
736
736
  }
737
- if call.getInt("paddingBottom") != nil {
738
- self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
737
+ if let paddingBottomValue = call.getInt("paddingBottom") {
738
+ self.paddingBottom = CGFloat(paddingBottomValue)
739
739
  }
740
740
 
741
741
  self.rotateWhenOrientationChanged = call.getBool("rotateWhenOrientationChanged") ?? true
@@ -823,7 +823,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
823
823
 
824
824
  // Add preview view to hierarchy first
825
825
  self.webView?.addSubview(self.previewView)
826
- if self.toBack! {
826
+ if self.toBack == true {
827
827
  self.webView?.sendSubviewToBack(self.previewView)
828
828
  }
829
829
 
@@ -1177,13 +1177,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1177
1177
  if Thread.isMainThread {
1178
1178
  return (self.previewView.frame.width, self.previewView.frame.height)
1179
1179
  }
1180
- var w: CGFloat = 0
1181
- var h: CGFloat = 0
1180
+ var width: CGFloat = 0
1181
+ var height: CGFloat = 0
1182
1182
  DispatchQueue.main.sync {
1183
- w = self.previewView.frame.width
1184
- h = self.previewView.frame.height
1183
+ width = self.previewView.frame.width
1184
+ height = self.previewView.frame.height
1185
1185
  }
1186
- return (w, h)
1186
+ return (width, height)
1187
1187
  }()
1188
1188
  print("[CameraPreview] Preview dimensions: \(previewWidth)x\(previewHeight)")
1189
1189
 
@@ -1398,7 +1398,7 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1398
1398
  }
1399
1399
 
1400
1400
  @objc func captureSample(_ call: CAPPluginCall) {
1401
- let quality: Int? = call.getInt("quality", 85)
1401
+ let quality: Int = call.getInt("quality") ?? 85
1402
1402
 
1403
1403
  self.cameraController.captureSample { image, error in
1404
1404
  guard let image = image else {
@@ -1410,14 +1410,17 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1410
1410
  let imageData: Data?
1411
1411
  if self.cameraPosition == "front" {
1412
1412
  let flippedImage = image.withHorizontallyFlippedOrientation()
1413
- imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality!/100))
1413
+ imageData = flippedImage.jpegData(compressionQuality: CGFloat(quality)/100)
1414
1414
  } else {
1415
- imageData = image.jpegData(compressionQuality: CGFloat(quality!/100))
1415
+ imageData = image.jpegData(compressionQuality: CGFloat(quality)/100)
1416
1416
  }
1417
1417
 
1418
1418
  if self.storeToFile == false {
1419
- let imageBase64 = imageData?.base64EncodedString()
1420
- call.resolve(["value": imageBase64!])
1419
+ guard let imageBase64 = imageData?.base64EncodedString() else {
1420
+ call.reject("Failed to encode image to base64")
1421
+ return
1422
+ }
1423
+ call.resolve(["value": imageBase64])
1421
1424
  } else {
1422
1425
  do {
1423
1426
  let fileUrl = self.getTempFilePath()
@@ -1464,8 +1467,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1464
1467
  flashModeAsEnum = AVCaptureDevice.FlashMode.auto
1465
1468
  default: break
1466
1469
  }
1467
- if flashModeAsEnum != nil {
1468
- try self.cameraController.setFlashMode(flashMode: flashModeAsEnum!)
1470
+ if let flashModeEnum = flashModeAsEnum {
1471
+ try self.cameraController.setFlashMode(flashMode: flashModeEnum)
1469
1472
  } else if flashMode == "torch" {
1470
1473
  try self.cameraController.setTorchMode()
1471
1474
  } else {
@@ -1905,12 +1908,12 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1905
1908
  }
1906
1909
  }
1907
1910
 
1908
- private func calculateCameraFrame(x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, aspectRatio: String? = nil) -> CGRect {
1911
+ private func calculateCameraFrame(xPosition: CGFloat? = nil, yPosition: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, aspectRatio: String? = nil) -> CGRect {
1909
1912
  // Use provided values or existing ones
1910
1913
  let currentWidth = width ?? self.width ?? UIScreen.main.bounds.size.width
1911
1914
  let currentHeight = height ?? self.height ?? UIScreen.main.bounds.size.height
1912
- let currentX = x ?? self.posX ?? -1
1913
- let currentY = y ?? self.posY ?? -1
1915
+ let currentX = xPosition ?? self.posX ?? -1
1916
+ let currentY = yPosition ?? self.posY ?? -1
1914
1917
  let currentAspectRatio = aspectRatio ?? self.aspectRatio
1915
1918
 
1916
1919
  let paddingBottom = self.paddingBottom ?? 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Camera preview",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {