SwiftLint: Fix force_cast

This commit is contained in:
Marc Rousavy 2021-02-25 14:07:46 +01:00
parent 4d7b8a01f5
commit c6ccae0cf2
2 changed files with 12 additions and 14 deletions

View File

@ -92,6 +92,7 @@ final class CameraView: UIView {
/// Convenience wrapper to get layer as its statically known type. /// Convenience wrapper to get layer as its statically known type.
var videoPreviewLayer: AVCaptureVideoPreviewLayer { var videoPreviewLayer: AVCaptureVideoPreviewLayer {
// swiftlint:disable force_cast
return layer as! AVCaptureVideoPreviewLayer return layer as! AVCaptureVideoPreviewLayer
} }

View File

@ -24,28 +24,27 @@ final class CameraViewManager: RCTViewManager {
return DispatchQueue.main return DispatchQueue.main
} }
private func getCameraView(withTag tag: NSNumber) -> CameraView {
// swiftlint:disable force_cast
return bridge.uiManager.view(forReactTag: node) as! CameraView
}
// pragma MARK: Exported Functions // pragma MARK: Exported Functions
@objc @objc
final func startRecording(_ node: NSNumber, options: NSDictionary, onRecordCallback: @escaping RCTResponseSenderBlock) { final func startRecording(_ node: NSNumber, options: NSDictionary, onRecordCallback: @escaping RCTResponseSenderBlock) {
let component = bridge.uiManager.view( let component = getCameraView(withTag: node)
forReactTag: node
) as! CameraView
component.startRecording(options: options, callback: onRecordCallback) component.startRecording(options: options, callback: onRecordCallback)
} }
@objc @objc
final func stopRecording(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { final func stopRecording(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
let component = bridge.uiManager.view( let component = getCameraView(withTag: node)
forReactTag: node
) as! CameraView
component.stopRecording(promise: Promise(resolver: resolve, rejecter: reject)) component.stopRecording(promise: Promise(resolver: resolve, rejecter: reject))
} }
@objc @objc
final func takePhoto(_ node: NSNumber, options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { final func takePhoto(_ node: NSNumber, options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
let component = bridge.uiManager.view( let component = getCameraView(withTag: node)
forReactTag: node
) as! CameraView
component.takePhoto(options: options, promise: Promise(resolver: resolve, rejecter: reject)) component.takePhoto(options: options, promise: Promise(resolver: resolve, rejecter: reject))
} }
@ -55,16 +54,14 @@ final class CameraViewManager: RCTViewManager {
guard let x = point["x"] as? NSNumber, let y = point["y"] as? NSNumber else { guard let x = point["x"] as? NSNumber, let y = point["y"] as? NSNumber else {
return promise.reject(error: .parameter(.invalid(unionName: "point", receivedValue: point.description))) return promise.reject(error: .parameter(.invalid(unionName: "point", receivedValue: point.description)))
} }
let component = bridge.uiManager.view( let component = getCameraView(withTag: node)
forReactTag: node
) as! CameraView
component.focus(point: CGPoint(x: x.doubleValue, y: y.doubleValue), promise: promise) component.focus(point: CGPoint(x: x.doubleValue, y: y.doubleValue), promise: promise)
} }
@objc @objc
final func getAvailableVideoCodecs(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { final func getAvailableVideoCodecs(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
withPromise(resolve: resolve, reject: reject) { withPromise(resolve: resolve, reject: reject) {
let component = self.bridge.uiManager.view(forReactTag: node) as! CameraView let component = getCameraView(withTag: node)
guard let movieOutput = component.movieOutput else { guard let movieOutput = component.movieOutput else {
throw CameraError.session(SessionError.cameraNotReady) throw CameraError.session(SessionError.cameraNotReady)
} }
@ -75,7 +72,7 @@ final class CameraViewManager: RCTViewManager {
@objc @objc
final func getAvailablePhotoCodecs(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { final func getAvailablePhotoCodecs(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
withPromise(resolve: resolve, reject: reject) { withPromise(resolve: resolve, reject: reject) {
let component = self.bridge.uiManager.view(forReactTag: node) as! CameraView let component = getCameraView(withTag: node)
guard let photoOutput = component.photoOutput else { guard let photoOutput = component.photoOutput else {
throw CameraError.session(SessionError.cameraNotReady) throw CameraError.session(SessionError.cameraNotReady)
} }