react-native-vision-camera/package/ios/CameraView+Zoom.swift
Marc Rousavy a5e10a8606
fix: Fix torch not staying on while recording (#2249)
* fix: Fix `zoom` on native gesture

* fix: Control `torch` from JS side

* Update CameraView+RecordVideo.kt

* Update CameraView+Zoom.swift
2023-12-04 11:43:17 +01:00

39 lines
975 B
Swift

//
// CameraView+Zoom.swift
// mrousavy
//
// Created by Marc Rousavy on 18.12.20.
// Copyright © 2020 mrousavy. All rights reserved.
//
import Foundation
import UIKit
extension CameraView {
@objc
final func onPinch(_ gesture: UIPinchGestureRecognizer) {
let scale = max(min(gesture.scale * pinchScaleOffset, cameraSession.maxZoom), CGFloat(1.0))
if gesture.state == .ended {
pinchScaleOffset = scale
return
}
// Update zoom React prop
zoom = NSNumber(value: scale)
didSetProps(["zoom"])
}
func addPinchGestureRecognizer() {
removePinchGestureRecognizer()
pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(onPinch(_:)))
addGestureRecognizer(pinchGestureRecognizer!)
}
func removePinchGestureRecognizer() {
if let pinchGestureRecognizer = pinchGestureRecognizer {
removeGestureRecognizer(pinchGestureRecognizer)
self.pinchGestureRecognizer = nil
}
}
}