Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBertet committed Dec 23, 2023
1 parent 04d9077 commit 6a00fad
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 84 deletions.
7 changes: 3 additions & 4 deletions ios/ReactNativeCameraKit/CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import Foundation
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
guard let cam = self.camera else {
reject("capture_error", "CKCamera capture() was called but camera view is nil", nil)
reject("capture_error", "CKCamera capture() was called but camera view is nil", nil)
return
}
cam.capture(options as! [String: Any],
onSuccess: { resolve($0) },
onError: { reject("capture_error", $0, nil) })
cam.capture(onSuccess: { resolve($0) },
onError: { reject("capture_error", $0, nil) })
}

@objc func checkDeviceCameraAuthorizationStatus(_ resolve: @escaping RCTPromiseResolveBlock,
Expand Down
4 changes: 2 additions & 2 deletions ios/ReactNativeCameraKit/CameraProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ protocol CameraProtocol: AnyObject, FocusInterfaceViewDelegate {
func update(scannerFrameSize: CGRect?)

func capturePicture(onWillCapture: @escaping () -> Void,
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?) -> (),
onError: @escaping (_ message: String) -> ())
onSuccess: @escaping (_ imageData: Data, _ thumbnailData: Data?) -> Void,
onError: @escaping (_ message: String) -> Void)
}
29 changes: 14 additions & 15 deletions ios/ReactNativeCameraKit/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CameraView: UIView {
}

private func setupCamera() {
if (hasPropBeenSetup && hasPermissionBeenGranted && !hasCameraBeenSetup) {
if hasPropBeenSetup && hasPermissionBeenGranted && !hasCameraBeenSetup {
hasCameraBeenSetup = true
camera.setup(cameraType: cameraType, supportedBarcodeType: scanBarcode && onReadCode != nil ? supportedBarcodeType : [])
}
Expand Down Expand Up @@ -141,6 +141,7 @@ class CameraView: UIView {
}

// Called once when all props have been set, then every time one is updated
// swiftlint:disable:next cyclomatic_complexity function_body_length
override func didSetProps(_ changedProps: [String]) {
hasPropBeenSetup = true

Expand All @@ -154,11 +155,11 @@ class CameraView: UIView {
if changedProps.contains("cameraType") || changedProps.contains("torchMode") {
camera.update(torchMode: torchMode)
}

if changedProps.contains("onOrientationChange") {
camera.update(onOrientationChange: onOrientationChange)
}

if changedProps.contains("onZoom") {
camera.update(onZoom: onZoom)
}
Expand Down Expand Up @@ -219,21 +220,20 @@ class CameraView: UIView {
if changedProps.contains("zoomMode") {
self.update(zoomMode: zoomMode)
}

if changedProps.contains("zoom") {
camera.update(zoom: zoom?.doubleValue)
}

if changedProps.contains("maxZoom") {
camera.update(maxZoom: maxZoom?.doubleValue)
}
}

// MARK: Public

func capture(_ options: [String: Any],
onSuccess: @escaping (_ imageObject: [String: Any]) -> (),
onError: @escaping (_ error: String) -> ()) {
func capture(onSuccess: @escaping (_ imageObject: [String: Any]) -> Void,
onError: @escaping (_ error: String) -> Void) {
camera.capturePicture(onWillCapture: { [weak self] in
// Flash/dim preview to indicate shutter action
DispatchQueue.main.async {
Expand All @@ -250,12 +250,12 @@ class CameraView: UIView {
}
}, onError: onError)
}

// MARK: - Private Helper

private func update(zoomMode: ZoomMode) {
if zoomMode == .on {
if (zoomGestureRecognizer == nil) {
if zoomGestureRecognizer == nil {
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchToZoomRecognizer(_:)))
addGestureRecognizer(pinchGesture)
zoomGestureRecognizer = pinchGesture
Expand All @@ -267,13 +267,12 @@ class CameraView: UIView {
}
}
}

private func handleCameraPermission() {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
// The user has previously granted access to the camera.
hasPermissionBeenGranted = true
break
case .notDetermined:
// The user has not yet been presented with the option to grant video access.
AVCaptureDevice.requestAccess(for: .video) { [weak self] granted in
Expand All @@ -289,11 +288,11 @@ class CameraView: UIView {

private func writeCaptured(imageData: Data,
thumbnailData: Data?,
onSuccess: @escaping (_ imageObject: [String: Any]) -> (),
onError: @escaping (_ error: String) -> ()) {
onSuccess: @escaping (_ imageObject: [String: Any]) -> Void,
onError: @escaping (_ error: String) -> Void) {
do {
let temporaryImageFileURL = try saveToTmpFolder(imageData)

onSuccess([
"size": imageData.count,
"uri": temporaryImageFileURL.description,
Expand Down
14 changes: 7 additions & 7 deletions ios/ReactNativeCameraKit/FocusInterfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class FocusInterfaceView: UIView {

func update(focusMode: FocusMode) {
if focusMode == .on {
if (focusGestureRecognizer == nil) {
if focusGestureRecognizer == nil {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(focusAndExposeTap(_:)))
addGestureRecognizer(tapGesture)
focusGestureRecognizer = tapGesture
Expand Down Expand Up @@ -157,17 +157,17 @@ class FocusInterfaceView: UIView {
UIView.animate(withDuration: 0.2, animations: {
self.focusView.frame = focusViewFrame
self.focusView.alpha = 1
}) { _ in
}, completion: { _ in
self.hideFocusViewTimer?.invalidate()
self.hideFocusViewTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { [weak self] _ in
self.hideFocusViewTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: false, block: { [weak self] _ in
guard let self else { return }
UIView.animate(withDuration: 0.2, animations: {
self.focusView.alpha = 0
}) { _ in
}, completion: { _ in
self.focusView.isHidden = true
}
}
}
})
})
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/ReactNativeCameraKit/PhotoCaptureDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
return
}

var thumbnailData: Data? = nil
var thumbnailData: Data?
if let previewPixelBuffer = photo.previewPixelBuffer {
let ciImage = CIImage(cvPixelBuffer: previewPixelBuffer)
let uiImage = UIImage(ciImage: ciImage)
Expand Down
1 change: 1 addition & 0 deletions ios/ReactNativeCameraKit/RatioOverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class RatioOverlayView: UIView {

// MARK: - Private

// swiftlint:disable:next function_body_length
private func setOverlayParts() {
guard let ratioData, ratioData.ratio != 0 else {
isHidden = true
Expand Down
Loading

0 comments on commit 6a00fad

Please sign in to comment.