Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ios/ReactNativeCameraKit/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
private var supportedBarcodeType: [CodeFormat] = {
return CodeFormat.allCases
}()

Check warning on line 27 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
// camera
private var ratioOverlayView: RatioOverlayView?

Expand Down Expand Up @@ -60,8 +60,8 @@

@objc public var onCaptureButtonPressIn: RCTDirectEventBlock?
@objc public var onCaptureButtonPressOut: RCTDirectEventBlock?

Check warning on line 63 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
var eventInteraction: Any? = nil

Check warning on line 64 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Initializing an optional variable with nil is redundant (redundant_optional_initialization)

// MARK: - Setup

Expand Down Expand Up @@ -124,10 +124,10 @@
focusInterfaceView.delegate = camera

handleCameraPermission()

Check warning on line 127 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
configureHardwareInteraction()
}

Check warning on line 130 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
private func configureHardwareInteraction() {
#if !targetEnvironment(macCatalyst)
// Create a new capture event interaction with a handler that captures a photo.
Expand Down Expand Up @@ -159,10 +159,13 @@
super.reactSetFrame(frame)
self.updateSubviewsBounds(frame)
}

Check warning on line 162 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
@objc public func updateSubviewsBounds(_ frame: CGRect) {
camera.previewView.frame = bounds

#if targetEnvironment(macCatalyst)
// Do not apply any transform on Mac Catalyst
// (macCatalyst orientation is managed by AVFoundation as set in RealCamera)
#endif
scannerInterfaceView.frame = bounds
// If frame size changes, we have to update the scanner
camera.update(scannerFrameSize: showFrame ? scannerInterfaceView.frameSize : nil)
Expand Down Expand Up @@ -404,7 +407,7 @@
return temporaryFileURL
}

private func onBarcodeRead(barcode: String, codeFormat:CodeFormat) {

Check warning on line 410 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
// Throttle barcode detection
let now = Date.timeIntervalSinceReferenceDate
guard lastBarcodeDetectedTime + Double(scanThrottleDelay) / 1000 < now else {
Expand All @@ -413,7 +416,7 @@

lastBarcodeDetectedTime = now

onReadCode?(["codeStringValue": barcode,"codeFormat":codeFormat.rawValue])

Check warning on line 419 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)

Check warning on line 419 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

There should be no space before and one after any comma (comma)
}

// MARK: - Gesture selectors
Expand All @@ -426,4 +429,4 @@
camera.zoomPinchChange(pinchScale: pinchRecognizer.scale)
}
}
}

Check warning on line 432 in ios/ReactNativeCameraKit/CameraView.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

File should contain 400 lines or less: currently contains 432 (file_length)
23 changes: 16 additions & 7 deletions ios/ReactNativeCameraKit/RealCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
private var inProgressPhotoCaptureDelegates = [Int64: PhotoCaptureDelegate]()

// MARK: - Lifecycle

#if !targetEnvironment(macCatalyst)
override init() {
super.init()
Expand All @@ -75,8 +74,8 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
// Mac Catalyst doesn't support device orientation notifications
}
#endif
@available(*, unavailable)

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down Expand Up @@ -132,6 +131,12 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
DispatchQueue.main.async {
self.setVideoOrientationToInterfaceOrientation()
}

#if targetEnvironment(macCatalyst)
if let connection = self.cameraPreview.previewLayer.connection {
connection.videoOrientation = .portrait
}
#endif
}
}

Expand Down Expand Up @@ -689,17 +694,21 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
}

private func setVideoOrientationToInterfaceOrientation() {
#if !targetEnvironment(macCatalyst)
#if targetEnvironment(macCatalyst)
if let connection = self.cameraPreview.previewLayer.connection {
connection.automaticallyAdjustsVideoMirroring = false // Disable automatic mirroring
connection.videoOrientation = .portrait // Force portrait
connection.isVideoMirrored = false // Ensure no mirroring
}
self.cameraPreview.previewLayer.setAffineTransform(.identity)
#else
var interfaceOrientation: UIInterfaceOrientation
if #available(iOS 13.0, *) {
interfaceOrientation = self.previewView.window?.windowScene?.interfaceOrientation ?? .portrait
} else {
interfaceOrientation = UIApplication.shared.statusBarOrientation
}
self.cameraPreview.previewLayer.connection?.videoOrientation = self.videoOrientation(from: interfaceOrientation)
#else
// Mac Catalyst always uses landscape orientation
self.cameraPreview.previewLayer.connection?.videoOrientation = .landscapeRight
#endif
}

Expand Down