@capgo/camera-preview 7.13.5 → 7.13.7

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.
@@ -789,23 +789,21 @@ extension CameraController {
789
789
  }
790
790
 
791
791
  func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
792
- print("[CameraPreview] captureImage called - width: \(width ?? -1), height: \(height ?? -1), requestedAspectRatio: \(self.requestedAspectRatio ?? "nil")")
793
-
794
792
  guard let photoOutput = self.photoOutput else {
795
793
  completion(nil, nil, nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Photo output is not available"]))
796
794
  return
797
795
  }
798
796
 
799
797
  let settings = AVCapturePhotoSettings()
800
- // Configure photo capture settings
798
+ // Configure photo capture settings optimized for speed
801
799
  if #available(iOS 13.0, *) {
802
- // Enable high resolution capture if max dimensions are specified or no aspect ratio constraint
803
- // When aspect ratio is specified WITHOUT max dimensions, use session preset dimensions
804
- let shouldUseHighRes = (width != nil || height != nil) || (self.requestedAspectRatio == nil)
800
+ // Only use high res if explicitly requesting large dimensions
801
+ let shouldUseHighRes = width.map { $0 > 1920 } ?? false || height.map { $0 > 1920 } ?? false
805
802
  settings.isHighResolutionPhotoEnabled = shouldUseHighRes
806
803
  }
807
804
  if #available(iOS 15.0, *) {
808
- settings.photoQualityPrioritization = .balanced
805
+ // Prioritize speed over quality
806
+ settings.photoQualityPrioritization = .speed
809
807
  }
810
808
 
811
809
  // Apply the current flash mode to the photo settings
@@ -1965,20 +1963,30 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
1965
1963
  return
1966
1964
  }
1967
1965
 
1968
- // Get the photo data using the modern API
1969
- guard let imageData = photo.fileDataRepresentation() else {
1970
- self.photoCaptureCompletionBlock?(nil, nil, nil, CameraControllerError.unknown)
1971
- return
1972
- }
1966
+ // Process photo in background to avoid blocking main thread
1967
+ DispatchQueue.global(qos: .userInitiated).async {
1968
+ // Get the photo data using the modern API
1969
+ guard let imageData = photo.fileDataRepresentation() else {
1970
+ DispatchQueue.main.async {
1971
+ self.photoCaptureCompletionBlock?(nil, nil, nil, CameraControllerError.unknown)
1972
+ }
1973
+ return
1974
+ }
1973
1975
 
1974
- guard let image = UIImage(data: imageData) else {
1975
- self.photoCaptureCompletionBlock?(nil, nil, nil, CameraControllerError.unknown)
1976
- return
1977
- }
1976
+ // Create image from data
1977
+ guard let image = UIImage(data: imageData) else {
1978
+ DispatchQueue.main.async {
1979
+ self.photoCaptureCompletionBlock?(nil, nil, nil, CameraControllerError.unknown)
1980
+ }
1981
+ return
1982
+ }
1978
1983
 
1979
- // Pass through original file data and metadata so callers can preserve EXIF
1980
- // Don't call fixedOrientation() here - let the completion block handle it after cropping
1981
- self.photoCaptureCompletionBlock?(image, imageData, photo.metadata, nil)
1984
+ // Pass through original file data and metadata so callers can preserve EXIF
1985
+ // Don't call fixedOrientation() here - let the completion block handle it after cropping
1986
+ DispatchQueue.main.async {
1987
+ self.photoCaptureCompletionBlock?(image, imageData, photo.metadata, nil)
1988
+ }
1989
+ }
1982
1990
  }
1983
1991
  }
1984
1992
 
@@ -1935,7 +1935,14 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
1935
1935
  }
1936
1936
  }
1937
1937
 
1938
+ private var lastOrientation: String?
1939
+
1938
1940
  @objc private func handleOrientationChange() {
1941
+ var currentOrientation = self.currentOrientationString()
1942
+ if currentOrientation == "portrait-upside-down" || currentOrientation == lastOrientation {
1943
+ return
1944
+ }
1945
+ lastOrientation = currentOrientation
1939
1946
  DispatchQueue.main.async {
1940
1947
  let result = self.rawSetAspectRatio()
1941
1948
  self.notifyListeners("screenResize", data: result)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.13.5",
3
+ "version": "7.13.7",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {