mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
b4415c251b
commit
af5408d526
@ -559,7 +559,11 @@ private final class CameraContext {
|
||||
guard let mainDeviceContext = self.mainDeviceContext else {
|
||||
return .complete()
|
||||
}
|
||||
mainDeviceContext.device.setTorchMode(self._flashMode)
|
||||
if self.initialConfiguration.isRoundVideo && self.positionValue == .front {
|
||||
|
||||
} else {
|
||||
mainDeviceContext.device.setTorchMode(self._flashMode)
|
||||
}
|
||||
|
||||
let orientation = self.simplePreviewView?.videoPreviewLayer.connection?.videoOrientation ?? .portrait
|
||||
if self.initialConfiguration.isRoundVideo {
|
||||
|
@ -121,6 +121,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
let push: (ViewController) -> Void
|
||||
let startRecording: ActionSlot<Void>
|
||||
let stopRecording: ActionSlot<Void>
|
||||
let cancelRecording: ActionSlot<Void>
|
||||
let completion: ActionSlot<VideoMessageCameraScreen.CaptureResult>
|
||||
|
||||
init(
|
||||
@ -135,6 +136,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
push: @escaping (ViewController) -> Void,
|
||||
startRecording: ActionSlot<Void>,
|
||||
stopRecording: ActionSlot<Void>,
|
||||
cancelRecording: ActionSlot<Void>,
|
||||
completion: ActionSlot<VideoMessageCameraScreen.CaptureResult>
|
||||
) {
|
||||
self.context = context
|
||||
@ -148,6 +150,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
self.push = push
|
||||
self.startRecording = startRecording
|
||||
self.stopRecording = stopRecording
|
||||
self.cancelRecording = cancelRecording
|
||||
self.completion = completion
|
||||
}
|
||||
|
||||
@ -216,6 +219,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
private let present: (ViewController) -> Void
|
||||
private let startRecording: ActionSlot<Void>
|
||||
private let stopRecording: ActionSlot<Void>
|
||||
private let cancelRecording: ActionSlot<Void>
|
||||
private let completion: ActionSlot<VideoMessageCameraScreen.CaptureResult>
|
||||
private let getController: () -> VideoMessageCameraScreen?
|
||||
|
||||
@ -234,6 +238,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
present: @escaping (ViewController) -> Void,
|
||||
startRecording: ActionSlot<Void>,
|
||||
stopRecording: ActionSlot<Void>,
|
||||
cancelRecording: ActionSlot<Void>,
|
||||
completion: ActionSlot<VideoMessageCameraScreen.CaptureResult>,
|
||||
getController: @escaping () -> VideoMessageCameraScreen? = {
|
||||
return nil
|
||||
@ -243,6 +248,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
self.present = present
|
||||
self.startRecording = startRecording
|
||||
self.stopRecording = stopRecording
|
||||
self.cancelRecording = cancelRecording
|
||||
self.completion = completion
|
||||
self.getController = getController
|
||||
|
||||
@ -260,6 +266,10 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
self.stopRecording.connect({ [weak self] _ in
|
||||
self?.stopVideoRecording()
|
||||
})
|
||||
|
||||
self.cancelRecording.connect({ [weak self] _ in
|
||||
self?.cancelVideoRecording()
|
||||
})
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -284,19 +294,28 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
}
|
||||
self.lastFlipTimestamp = currentTimestamp
|
||||
|
||||
let isFrontCamera = controller.cameraState.position == .back
|
||||
camera.togglePosition()
|
||||
|
||||
|
||||
self.hapticFeedback.impact(.veryLight)
|
||||
|
||||
self.updateScreenBrightness(isFrontCamera: isFrontCamera)
|
||||
|
||||
if isFrontCamera {
|
||||
camera.setTorchActive(false)
|
||||
} else {
|
||||
camera.setTorchActive(controller.cameraState.flashMode == .on)
|
||||
}
|
||||
}
|
||||
|
||||
func toggleFlashMode() {
|
||||
guard let controller = self.getController(), let camera = controller.camera else {
|
||||
return
|
||||
}
|
||||
var flashOn = false
|
||||
var isFlashOn = false
|
||||
switch controller.cameraState.flashMode {
|
||||
case .off:
|
||||
flashOn = true
|
||||
isFlashOn = true
|
||||
camera.setFlashMode(.on)
|
||||
case .on:
|
||||
camera.setFlashMode(.off)
|
||||
@ -305,22 +324,29 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
}
|
||||
self.hapticFeedback.impact(.light)
|
||||
|
||||
self.updateScreenBrightness(flashOn: flashOn)
|
||||
self.updateScreenBrightness(isFlashOn: isFlashOn)
|
||||
|
||||
if controller.cameraState.position == .back {
|
||||
if isFlashOn {
|
||||
camera.setTorchActive(true)
|
||||
} else {
|
||||
camera.setTorchActive(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var initialBrightness: CGFloat?
|
||||
private var brightnessArguments: (Double, Double, CGFloat, CGFloat)?
|
||||
private var brightnessAnimator: ConstantDisplayLinkAnimator?
|
||||
|
||||
func updateScreenBrightness(flashOn: Bool?) {
|
||||
func updateScreenBrightness(isFrontCamera: Bool? = nil, isFlashOn: Bool? = nil) {
|
||||
guard let controller = self.getController() else {
|
||||
return
|
||||
}
|
||||
let isFrontCamera = controller.cameraState.position == .front
|
||||
let isVideo = true
|
||||
let isFlashOn = flashOn ?? (controller.cameraState.flashMode == .on)
|
||||
let isFrontCamera = isFrontCamera ?? (controller.cameraState.position == .front)
|
||||
let isFlashOn = isFlashOn ?? (controller.cameraState.flashMode == .on)
|
||||
|
||||
if isFrontCamera && isVideo && isFlashOn {
|
||||
if isFrontCamera && isFlashOn {
|
||||
if self.initialBrightness == nil {
|
||||
self.initialBrightness = UIScreen.main.brightness
|
||||
self.brightnessArguments = (CACurrentMediaTime(), 0.2, UIScreen.main.brightness, 1.0)
|
||||
@ -439,7 +465,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
}
|
||||
}))
|
||||
|
||||
if case .front = controller.cameraState.position, let initialBrightness = self.initialBrightness {
|
||||
if let initialBrightness = self.initialBrightness {
|
||||
self.initialBrightness = nil
|
||||
self.brightnessArguments = (CACurrentMediaTime(), 0.2, UIScreen.main.brightness, initialBrightness)
|
||||
self.animateBrightnessChange()
|
||||
@ -453,6 +479,14 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
controller.updateCameraState({ $0.updatedRecording(.handsFree) }, transition: .spring(duration: 0.4))
|
||||
}
|
||||
|
||||
func cancelVideoRecording() {
|
||||
if let initialBrightness = self.initialBrightness {
|
||||
self.initialBrightness = nil
|
||||
self.brightnessArguments = (CACurrentMediaTime(), 0.2, UIScreen.main.brightness, initialBrightness)
|
||||
self.animateBrightnessChange()
|
||||
}
|
||||
}
|
||||
|
||||
func updateZoom(fraction: CGFloat) {
|
||||
guard let camera = self.getController()?.camera else {
|
||||
return
|
||||
@ -462,7 +496,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
}
|
||||
|
||||
func makeState() -> State {
|
||||
return State(context: self.context, present: self.present, startRecording: self.startRecording, stopRecording: self.stopRecording, completion: self.completion, getController: self.getController)
|
||||
return State(context: self.context, present: self.present, startRecording: self.startRecording, stopRecording: self.stopRecording, cancelRecording: self.cancelRecording, completion: self.completion, getController: self.getController)
|
||||
}
|
||||
|
||||
static var body: Body {
|
||||
@ -517,7 +551,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
|
||||
}
|
||||
|
||||
if !component.isPreviewing {
|
||||
if case .on = component.cameraState.flashMode {
|
||||
if case .on = component.cameraState.flashMode, case .front = component.cameraState.position {
|
||||
let frontFlash = frontFlash.update(
|
||||
component: Image(image: state.image(.flashImage, theme: environment.theme), tintColor: component.cameraState.flashTint.color),
|
||||
availableSize: availableSize,
|
||||
@ -801,6 +835,7 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
|
||||
fileprivate let startRecording = ActionSlot<Void>()
|
||||
fileprivate let stopRecording = ActionSlot<Void>()
|
||||
fileprivate let cancelRecording = ActionSlot<Void>()
|
||||
private let completion = ActionSlot<VideoMessageCameraScreen.CaptureResult>()
|
||||
|
||||
var cameraState: CameraState {
|
||||
@ -1432,6 +1467,7 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
},
|
||||
startRecording: self.startRecording,
|
||||
stopRecording: self.stopRecording,
|
||||
cancelRecording: self.cancelRecording,
|
||||
completion: self.completion
|
||||
)
|
||||
),
|
||||
@ -1894,6 +1930,8 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
}
|
||||
|
||||
public func discardVideo() {
|
||||
self.node.cancelRecording.invoke(Void())
|
||||
|
||||
self.requestDismiss(animated: true)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user