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
5de8f50b79
commit
f9b6a1e3f9
@ -473,6 +473,8 @@ private final class CameraContext {
|
||||
}
|
||||
|
||||
public func startRecording() -> Signal<Double, NoError> {
|
||||
self.mainDeviceContext.device.setTorchMode(self._flashMode)
|
||||
|
||||
if let additionalDeviceContext = self.additionalDeviceContext {
|
||||
return combineLatest(
|
||||
self.mainDeviceContext.output.startRecording(isDualCamera: true, position: self.positionValue),
|
||||
|
@ -234,6 +234,24 @@ final class CameraDevice {
|
||||
}
|
||||
}
|
||||
|
||||
func setTorchMode(_ flashMode: AVCaptureDevice.FlashMode) {
|
||||
guard let device = self.videoDevice else {
|
||||
return
|
||||
}
|
||||
self.transaction(device) { device in
|
||||
switch flashMode {
|
||||
case .on:
|
||||
device.torchMode = .on
|
||||
case .off:
|
||||
device.torchMode = .off
|
||||
case .auto:
|
||||
device.torchMode = .auto
|
||||
@unknown default:
|
||||
device.torchMode = .off
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setZoomLevel(_ zoomLevel: CGFloat) {
|
||||
guard let device = self.videoDevice else {
|
||||
return
|
||||
|
@ -1140,14 +1140,19 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
if state.drawingViewState.isDrawing || component.isInteractingWithEntities {
|
||||
controlsAreVisible = false
|
||||
}
|
||||
|
||||
|
||||
var controlsBottomInset: CGFloat = 0.0
|
||||
let previewSize: CGSize
|
||||
let previewTopInset: CGFloat = environment.statusBarHeight + 5.0
|
||||
var previewTopInset: CGFloat = environment.statusBarHeight + 5.0
|
||||
if case .regular = environment.metrics.widthClass {
|
||||
let previewHeight = context.availableSize.height - previewTopInset - 75.0
|
||||
previewSize = CGSize(width: floorToScreenPixels(previewHeight / 1.77778), height: previewHeight)
|
||||
} else {
|
||||
previewSize = CGSize(width: context.availableSize.width, height: floorToScreenPixels(context.availableSize.width * 1.77778))
|
||||
if context.availableSize.height < previewSize.height + 30.0 {
|
||||
previewTopInset = 0.0
|
||||
controlsBottomInset = -50.0
|
||||
}
|
||||
}
|
||||
let previewBottomInset = context.availableSize.height - previewSize.height - previewTopInset
|
||||
|
||||
@ -1155,6 +1160,7 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
if component.sourceHint == .storyEditor {
|
||||
topInset = previewTopInset + 31.0
|
||||
}
|
||||
|
||||
let bottomInset: CGFloat = environment.inputHeight > 0.0 ? environment.inputHeight : 145.0
|
||||
|
||||
var leftEdge: CGFloat = environment.safeInsets.left
|
||||
@ -1985,7 +1991,7 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
if case .regular = environment.metrics.widthClass {
|
||||
doneButtonPosition.x -= 20.0
|
||||
}
|
||||
doneButtonPosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 3.0 + doneButton.size.height / 2.0)
|
||||
doneButtonPosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 3.0 + doneButton.size.height / 2.0) + controlsBottomInset
|
||||
}
|
||||
context.add(doneButton
|
||||
.position(doneButtonPosition)
|
||||
@ -2063,7 +2069,7 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
)
|
||||
var modeAndSizePosition = CGPoint(x: context.availableSize.width / 2.0 - (modeRightInset - 57.0) / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - modeAndSize.size.height / 2.0 - 9.0)
|
||||
if component.sourceHint == .storyEditor {
|
||||
modeAndSizePosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 8.0 + modeAndSize.size.height / 2.0)
|
||||
modeAndSizePosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 8.0 + modeAndSize.size.height / 2.0) + controlsBottomInset
|
||||
}
|
||||
context.add(modeAndSize
|
||||
.position(modeAndSizePosition)
|
||||
@ -2108,7 +2114,7 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
if case .regular = environment.metrics.widthClass {
|
||||
backButtonPosition.x += 20.0
|
||||
}
|
||||
backButtonPosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 3.0 + backButton.size.height / 2.0)
|
||||
backButtonPosition.y = floorToScreenPixels(context.availableSize.height - previewBottomInset + 3.0 + backButton.size.height / 2.0) + controlsBottomInset
|
||||
}
|
||||
context.add(backButton
|
||||
.position(backButtonPosition)
|
||||
|
@ -2154,7 +2154,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
}
|
||||
}
|
||||
|
||||
private var enhanceGestureOffset: CGFloat?
|
||||
private var enhanceInitialTranslation: Float?
|
||||
|
||||
@objc func handleDismissPan(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||
guard let controller = self.controller, let layout = self.validLayout, (layout.inputHeight ?? 0.0).isZero else {
|
||||
@ -2180,7 +2180,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
self.isDismissBySwipeSuppressed = controller.isEligibleForDraft()
|
||||
controller.requestLayout(transition: .animated(duration: 0.25, curve: .easeInOut))
|
||||
}
|
||||
} else if abs(translation.x) > 10.0 && !self.isDismissing {
|
||||
} else if abs(translation.x) > 10.0 && !self.isDismissing && !self.isEnhancing {
|
||||
self.isEnhancing = true
|
||||
controller.requestLayout(transition: .animated(duration: 0.3, curve: .easeInOut))
|
||||
}
|
||||
@ -2197,14 +2197,27 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
} else if self.isEnhancing {
|
||||
if let mediaEditor = self.mediaEditor {
|
||||
let value = mediaEditor.getToolValue(.enhance) as? Float ?? 0.0
|
||||
|
||||
if self.enhanceInitialTranslation == nil && value != 0.0 {
|
||||
self.enhanceInitialTranslation = value
|
||||
}
|
||||
|
||||
let delta = Float((translation.x / self.frame.width) * 1.5)
|
||||
let updatedValue = max(-1.0, min(1.0, value + delta))
|
||||
var updatedValue = max(-1.0, min(1.0, value + delta))
|
||||
if let enhanceInitialTranslation = self.enhanceInitialTranslation {
|
||||
if enhanceInitialTranslation > 0.0 {
|
||||
updatedValue = max(0.0, updatedValue)
|
||||
} else {
|
||||
updatedValue = min(0.0, updatedValue)
|
||||
}
|
||||
}
|
||||
mediaEditor.setToolValue(.enhance, value: updatedValue)
|
||||
}
|
||||
self.requestUpdate()
|
||||
gestureRecognizer.setTranslation(.zero, in: self.view)
|
||||
}
|
||||
case .ended, .cancelled:
|
||||
self.enhanceInitialTranslation = nil
|
||||
if self.isDismissing {
|
||||
if abs(translation.y) > self.view.frame.height * 0.33 || abs(velocity.y) > 1000.0, !controller.isEligibleForDraft() {
|
||||
controller.requestDismiss(saveDraft: false, animated: true)
|
||||
@ -4329,7 +4342,11 @@ private final class ToolValueComponent: Component {
|
||||
}
|
||||
|
||||
if let previousValue, component.value != previousValue, self.alpha > 0.0 {
|
||||
self.hapticFeedback.impact(.click05)
|
||||
if component.value == "100" || component.value == "0" {
|
||||
self.hapticFeedback.impact(.medium)
|
||||
} else {
|
||||
self.hapticFeedback.impact(.click05)
|
||||
}
|
||||
}
|
||||
|
||||
return availableSize
|
||||
|
@ -214,6 +214,7 @@ private final class MediaToolsScreenComponent: Component {
|
||||
|
||||
public final class View: UIView {
|
||||
private let buttonsContainerView = UIView()
|
||||
private let buttonsBackgroundView = UIView()
|
||||
private let cancelButton = ComponentView<Empty>()
|
||||
private let adjustmentsButton = ComponentView<Empty>()
|
||||
private let tintButton = ComponentView<Empty>()
|
||||
@ -244,10 +245,11 @@ private final class MediaToolsScreenComponent: Component {
|
||||
|
||||
self.backgroundColor = .clear
|
||||
|
||||
self.addSubview(self.buttonsContainerView)
|
||||
self.addSubview(self.previewContainerView)
|
||||
self.addSubview(self.buttonsContainerView)
|
||||
self.previewContainerView.addSubview(self.optionsContainerView)
|
||||
self.optionsContainerView.addSubview(self.optionsBackgroundView)
|
||||
self.buttonsContainerView.addSubview(self.buttonsBackgroundView)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@ -277,6 +279,8 @@ private final class MediaToolsScreenComponent: Component {
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
|
||||
}
|
||||
|
||||
self.buttonsBackgroundView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
|
||||
self.optionsContainerView.layer.animatePosition(from: CGPoint(x: 0.0, y: self.optionsContainerView.frame.height), to: .zero, duration: 0.4, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
|
||||
}
|
||||
|
||||
@ -312,6 +316,8 @@ private final class MediaToolsScreenComponent: Component {
|
||||
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false)
|
||||
}
|
||||
|
||||
self.buttonsBackgroundView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false)
|
||||
|
||||
self.optionsContainerView.layer.animatePosition(from: .zero, to: CGPoint(x: 0.0, y: self.optionsContainerView.frame.height), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
|
||||
|
||||
self.state?.updated()
|
||||
@ -335,11 +341,12 @@ private final class MediaToolsScreenComponent: Component {
|
||||
let mediaEditor = (environment.controller() as? MediaToolsScreen)?.mediaEditor
|
||||
|
||||
let sectionUpdated = component.sectionUpdated
|
||||
|
||||
|
||||
let buttonSideInset: CGFloat
|
||||
let buttonBottomInset: CGFloat = 8.0
|
||||
var controlsBottomInset: CGFloat = 0.0
|
||||
let previewSize: CGSize
|
||||
let topInset: CGFloat = environment.statusBarHeight + 5.0
|
||||
var topInset: CGFloat = environment.statusBarHeight + 5.0
|
||||
if isTablet {
|
||||
let previewHeight = availableSize.height - topInset - 75.0
|
||||
previewSize = CGSize(width: floorToScreenPixels(previewHeight / 1.77778), height: previewHeight)
|
||||
@ -347,10 +354,17 @@ private final class MediaToolsScreenComponent: Component {
|
||||
} else {
|
||||
previewSize = CGSize(width: availableSize.width, height: floorToScreenPixels(availableSize.width * 1.77778))
|
||||
buttonSideInset = 10.0
|
||||
if availableSize.height < previewSize.height + 30.0 {
|
||||
topInset = 0.0
|
||||
controlsBottomInset = -75.0
|
||||
// self.buttonsBackgroundView.backgroundColor = .black
|
||||
} else {
|
||||
self.buttonsBackgroundView.backgroundColor = .clear
|
||||
}
|
||||
}
|
||||
|
||||
let previewContainerFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - previewSize.width) / 2.0), y: environment.safeInsets.top), size: CGSize(width: previewSize.width, height: availableSize.height - environment.safeInsets.top - environment.safeInsets.bottom))
|
||||
let buttonsContainerFrame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - environment.safeInsets.bottom), size: CGSize(width: availableSize.width, height: environment.safeInsets.bottom))
|
||||
var previewContainerFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - previewSize.width) / 2.0), y: environment.safeInsets.top), size: CGSize(width: previewSize.width, height: availableSize.height - environment.safeInsets.top - environment.safeInsets.bottom + controlsBottomInset))
|
||||
let buttonsContainerFrame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - environment.safeInsets.bottom + controlsBottomInset), size: CGSize(width: availableSize.width, height: environment.safeInsets.bottom - controlsBottomInset))
|
||||
|
||||
let cancelButtonSize = self.cancelButton.update(
|
||||
transition: transition,
|
||||
@ -873,6 +887,7 @@ private final class MediaToolsScreenComponent: Component {
|
||||
let optionsFrame = CGRect(origin: .zero, size: optionsSize)
|
||||
if let optionsView = self.toolOptions.view {
|
||||
if optionsView.superview == nil {
|
||||
optionsView.clipsToBounds = true
|
||||
self.optionsContainerView.addSubview(optionsView)
|
||||
}
|
||||
optionsTransition.setFrame(view: optionsView, frame: optionsFrame)
|
||||
@ -885,9 +900,11 @@ private final class MediaToolsScreenComponent: Component {
|
||||
}
|
||||
}
|
||||
|
||||
previewContainerFrame.size.height -= controlsBottomInset
|
||||
|
||||
let optionsBackgroundFrame = CGRect(
|
||||
origin: CGPoint(x: 0.0, y: previewContainerFrame.height - optionsSize.height),
|
||||
size: optionsSize
|
||||
origin: CGPoint(x: 0.0, y: previewContainerFrame.height - optionsSize.height + controlsBottomInset),
|
||||
size: CGSize(width: optionsSize.width, height: optionsSize.height - controlsBottomInset)
|
||||
)
|
||||
transition.setFrame(view: self.optionsContainerView, frame: optionsBackgroundFrame)
|
||||
transition.setFrame(view: self.optionsBackgroundView, frame: CGRect(origin: .zero, size: optionsBackgroundFrame.size))
|
||||
@ -906,6 +923,7 @@ private final class MediaToolsScreenComponent: Component {
|
||||
|
||||
transition.setFrame(view: self.previewContainerView, frame: previewContainerFrame)
|
||||
transition.setFrame(view: self.buttonsContainerView, frame: buttonsContainerFrame)
|
||||
transition.setFrame(view: self.buttonsBackgroundView, frame: CGRect(origin: .zero, size: buttonsContainerFrame.size))
|
||||
|
||||
return availableSize
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user