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