Skip to content
Merged
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
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ PODS:
- React-perflogger (= 0.81.0)
- React-utils (= 0.81.0)
- SocketRocket
- ReactNativeCameraKit (16.0.1):
- ReactNativeCameraKit (16.1.1):
- boost
- DoubleConversion
- fast_float
Expand Down Expand Up @@ -2528,14 +2528,14 @@ SPEC CHECKSUMS:
React-performancetimeline: 1f86dc9782e3fe78727c5fbb3e2178b9fd1aa6fd
React-RCTActionSheet: 550c9c6c2e7dcd85a51954dc08e2f3837a148e7c
React-RCTAnimation: 19d4bb6d2190983d1354b096b7b65dbd591924da
React-RCTAppDelegate: 4512132c26eb717a81d4a0b6516f178639e9abf0
React-RCTAppDelegate: 6c71d16eef920831a312ff363355fc3b99c02a98
React-RCTBlob: b81a0cffe1a083bcf9d8aa9f27f4d37864579e90
React-RCTFabric: e256e79bdab3d2c4bb6e5975224484d0f42131f3
React-RCTFBReactNativeSpec: 8442e61116ea32de3fc3664651f7a78da11c6ba0
React-RCTFabric: 01005d2fa799bba6e21aae18820498f56fe0be5f
React-RCTFBReactNativeSpec: 5adb84a81c4ed7a1f2661835d166e4b2c4320cd4
React-RCTImage: 607e5e373fb56d72417464bd82e8046af81ab502
React-RCTLinking: 301434c7bf1100458be5a3866326ba33491e3687
React-RCTNetwork: a118a47bd123ac96c9877e04f5731a1d6545aba5
React-RCTRuntime: b1e67bc601a330d1f72c71246557541efbc121a4
React-RCTRuntime: 85fdbf469fe8a12c4db6c836731b190efc33d11d
React-RCTSettings: 5a5aa2cf9ac40f7a8897cc0f9d945ac803886604
React-RCTText: e6e00bee9847a8af1218079b73c8bfed16c75b8d
React-RCTVibration: 5a05fa0ef05ee73d074a3314e57586afc969f1ba
Expand All @@ -2552,10 +2552,10 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: c91900fa724baee992f01c05eeb4c9e01a807f78
ReactCodegen: a55799cae416c387aeaae3aabc1bc0289ac19cee
ReactCommon: 116d6ee71679243698620d8cd9a9042541e44aa6
ReactNativeCameraKit: 29206675814ffb96b09a200b999ad5fa9b858a08
ReactNativeCameraKit: b01e637c97fb6eefe43eff31917d1410fc77e1f8
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 00013dd9cde63a2d98e8002fcc4f5ddb66c10782

PODFILE CHECKSUM: 2a7cb4991754518b63a1c5b884f5861886abdce4
PODFILE CHECKSUM: 831b9773c4c6aed2643524d13cb247994d19e1e9

COCOAPODS: 1.15.2
47 changes: 23 additions & 24 deletions ios/ReactNativeCameraKit/RealCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
private var maxPhotoQualityPrioritization: MaxPhotoQualityPrioritization?
private var resetFocus: (() -> Void)?
private var focusFinished: (() -> Void)?
private var onBarcodeRead: ((_ barcode: String,_ codeFormat : CodeFormat) -> Void)?

Check warning on line 40 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

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

Check warning on line 40 in ios/ReactNativeCameraKit/RealCamera.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)
private var scannerFrameSize: CGRect? = nil

Check warning on line 41 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Initializing an optional variable with nil is redundant (redundant_optional_initialization)
private var barcodeFrameSize: CGSize? = nil

Check warning on line 42 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Initializing an optional variable with nil is redundant (redundant_optional_initialization)
private var onOrientationChange: RCTDirectEventBlock?
private var onZoomCallback: RCTDirectEventBlock?
private var lastOnZoom: Double?
Expand All @@ -58,7 +58,7 @@
private var inProgressPhotoCaptureDelegates = [Int64: PhotoCaptureDelegate]()

// MARK: - Lifecycle

Check warning on line 61 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
#if !targetEnvironment(macCatalyst)
override init() {
super.init()
Expand All @@ -79,7 +79,7 @@
// Mac Catalyst doesn't support device orientation notifications
}
#endif

Check warning on line 82 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Lines should not have trailing whitespace (trailing_whitespace)
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down Expand Up @@ -128,9 +128,6 @@

if self.setupResult == .success {
self.session.startRunning()

// We need to reapply the configuration after starting the camera
self.update(torchMode: self.torchMode)
}

DispatchQueue.main.async {
Expand Down Expand Up @@ -227,6 +224,7 @@

do {
try videoDevice.lockForConfiguration()
self.reconfigureLockedVideoDevice(videoDevice)

if videoDevice.isFocusPointOfInterestSupported && videoDevice.isFocusModeSupported(focusBehavior.avFocusMode) {
videoDevice.focusPointOfInterest = devicePoint
Expand Down Expand Up @@ -257,14 +255,12 @@
self.torchMode = torchMode
guard let videoDevice = self.videoDeviceInput?.device, videoDevice.torchMode != torchMode.avTorchMode else { return }

if videoDevice.isTorchModeSupported(torchMode.avTorchMode) && videoDevice.hasTorch {
do {
try videoDevice.lockForConfiguration()
videoDevice.torchMode = torchMode.avTorchMode
videoDevice.unlockForConfiguration()
} catch {
print("Error setting torch mode: \(error)")
}
do {
try videoDevice.lockForConfiguration()
defer { videoDevice.unlockForConfiguration() }
self.reconfigureLockedVideoDevice(videoDevice)
} catch {
print("Error setting torch mode: \(error)")
}
}
}
Expand Down Expand Up @@ -300,24 +296,23 @@

self.removeObservers()
self.session.beginConfiguration()
defer { self.session.commitConfiguration() }
defer {
self.session.commitConfiguration()
self.resetZoom(forDevice: videoDevice)
}

// Remove the existing device input first, since using the front and back camera simultaneously is not supported.
self.session.removeInput(currentViewDeviceInput)

if self.session.canAddInput(videoDeviceInput) {
self.session.addInput(videoDeviceInput)
self.resetZoom(forDevice: videoDevice)
self.videoDeviceInput = videoDeviceInput
} else {
// If it fails, put back current camera
self.session.addInput(currentViewDeviceInput)
}

self.addObservers()

// We need to reapply the configuration after reloading the camera
self.update(torchMode: self.torchMode)
}
}

Expand Down Expand Up @@ -380,7 +375,7 @@

func isBarcodeScannerEnabled(_ isEnabled: Bool,
supportedBarcodeTypes supportedBarcodeType: [CodeFormat],
onBarcodeRead: ((_ barcode: String,_ codeFormat:CodeFormat) -> Void)?) {

Check warning on line 378 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

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

Check warning on line 378 in ios/ReactNativeCameraKit/RealCamera.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)
sessionQueue.async {
self.onBarcodeRead = onBarcodeRead
let newTypes: [AVMetadataObject.ObjectType]
Expand All @@ -394,9 +389,6 @@

if self.metadataOutput.metadataObjectTypes != newTypes {
self.metadataOutput.metadataObjectTypes = newTypes

// Setting metadataObjectTypes reloads the camera, we need to reapply the configuration
self.update(torchMode: self.torchMode)
}
}
}
Expand Down Expand Up @@ -425,8 +417,6 @@
}

self.metadataOutput.rectOfInterest = visibleRect ?? CGRect(x: 0, y: 0, width: 1, height: 1)
// We need to reapply the configuration after touching the metadataOutput
self.update(torchMode: self.torchMode)
}
}
}
Expand All @@ -443,7 +433,7 @@
// Determine the barcode type and convert it to CodeFormat
let barcodeType = CodeFormat.fromAVMetadataObjectType(machineReadableCodeObject.type)

onBarcodeRead?(codeStringValue,barcodeType)

Check warning on line 436 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

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

// MARK: - Private
Expand Down Expand Up @@ -506,7 +496,10 @@
}

session.beginConfiguration()
defer { session.commitConfiguration() }
defer {
session.commitConfiguration()
self.resetZoom(forDevice: videoDevice)
}

session.sessionPreset = .photo

Expand All @@ -518,9 +511,7 @@

if session.canAddInput(videoDeviceInput) {
session.addInput(videoDeviceInput)

self.videoDeviceInput = videoDeviceInput
self.resetZoom(forDevice: videoDevice)
} else {
return .sessionConfigurationFailed
}
Expand Down Expand Up @@ -573,12 +564,20 @@
do {
try videoDevice.lockForConfiguration()
defer { videoDevice.unlockForConfiguration() }
reconfigureLockedVideoDevice(videoDevice)
let defaultZoom = defaultZoomFactor(for: videoDevice)
videoDevice.videoZoomFactor = zoom * defaultZoom
} catch {
print("CKCameraKit: setZoomFor error: \(error))")
}
}

// Torch mode will turn off unless set again when the videoDevice is locked and unlocked
private func reconfigureLockedVideoDevice(_ videoDevice: AVCaptureDevice) {
if videoDevice.isTorchModeSupported(torchMode.avTorchMode) && videoDevice.hasTorch {
videoDevice.torchMode = torchMode.avTorchMode
}
}

private func normalizedZoom(for videoDevice: AVCaptureDevice) -> Double {
let defaultZoom = defaultZoomFactor(for: videoDevice)
Expand Down Expand Up @@ -612,7 +611,7 @@
motionManager = CMMotionManager()
motionManager?.accelerometerUpdateInterval = 0.2
motionManager?.gyroUpdateInterval = 0.2
motionManager?.startAccelerometerUpdates(to: OperationQueue(), withHandler: { (accelerometerData, error) -> Void in

Check warning on line 614 in ios/ReactNativeCameraKit/RealCamera.swift

View workflow job for this annotation

GitHub Actions / Lint iOS

Returning Void in a function declaration is redundant (redundant_void_return)
guard error == nil else {
print("\(error!)")
return
Expand Down
Loading