Various fixes

This commit is contained in:
Ilya Laktyushin 2023-07-11 21:31:41 +02:00
parent 2b40dc2989
commit 148947a0e9
6 changed files with 62 additions and 53 deletions

View File

@ -878,8 +878,8 @@ public final class Camera {
}
}
public static var isDualCamSupported: Bool {
if #available(iOS 13.0, *), AVCaptureMultiCamSession.isMultiCamSupported {
public static var isDualCameraSupported: Bool {
if #available(iOS 13.0, *), AVCaptureMultiCamSession.isMultiCamSupported && !DeviceModel.current.isIpad {
return true
} else {
return false

View File

@ -198,6 +198,10 @@ enum DeviceModel: CaseIterable, Equatable {
}
}
var isIpad: Bool {
return self.modelId.first?.hasPrefix("iPad") ?? false
}
static let current = DeviceModel()
private init() {

View File

@ -752,7 +752,7 @@ private final class CameraScreenComponent: CombinedComponent {
.disappear(.default(scale: true))
)
if !isTablet && Camera.isDualCamSupported {
if !isTablet && Camera.isDualCameraSupported {
let dualButton = dualButton.update(
component: CameraButton(
content: AnyComponentWithIdentity(
@ -1164,9 +1164,11 @@ public class CameraScreen: ViewController {
self.previewBlurView = BlurView()
self.previewBlurView.isUserInteractionEnabled = false
var isDualCameraEnabled = true
if let isDualCameraEnabledValue = UserDefaults.standard.object(forKey: "TelegramStoryCameraIsDualEnabled") as? NSNumber {
isDualCameraEnabled = isDualCameraEnabledValue.boolValue
var isDualCameraEnabled = Camera.isDualCameraSupported
if isDualCameraEnabled {
if let isDualCameraEnabledValue = UserDefaults.standard.object(forKey: "TelegramStoryCameraIsDualEnabled") as? NSNumber {
isDualCameraEnabled = isDualCameraEnabledValue.boolValue
}
}
var dualCameraPosition: PIPPosition = .topRight
@ -2078,8 +2080,9 @@ public class CameraScreen: ViewController {
let dualCamUpdated = self.appliedDualCamera != isDualCameraEnabled
self.appliedDualCamera = isDualCameraEnabled
let circleSide = floorToScreenPixels(previewSize.width * 160.0 / 430.0)
let circleOffset = CGPoint(x: previewSize.width * 224.0 / 1080.0, y: previewSize.width * 480.0 / 1080.0)
let dualCameraSize: CGFloat = 160.0
let circleSide = floorToScreenPixels(previewSize.width * dualCameraSize / 393.0)
let circleOffset = CGPoint(x: previewSize.width * (dualCameraSize + 107.0) / 1080.0, y: previewSize.width * (dualCameraSize + 278.0) / 1080.0)
var origin: CGPoint
switch self.pipPosition {

View File

@ -1231,13 +1231,13 @@ final class MediaEditorScreenComponent: Component {
transition: transition,
component: AnyComponent(BlurredGradientComponent(position: .bottom, tag: nil)),
environment: {},
containerSize: CGSize(width: availableSize.width, height: keyboardHeight + 100.0)
containerSize: CGSize(width: availableSize.width, height: keyboardHeight + 60.0)
)
if let inputPanelBackgroundView = self.inputPanelBackground.view {
if inputPanelBackgroundView.superview == nil {
self.addSubview(inputPanelBackgroundView)
}
let isVisible = inputHeight > 44.0
let isVisible = isEditingCaption && inputHeight > 44.0
transition.setFrame(view: inputPanelBackgroundView, frame: CGRect(origin: CGPoint(x: 0.0, y: isVisible ? availableSize.height - inputPanelBackgroundSize.height : availableSize.height), size: inputPanelBackgroundSize))
if !self.animatingButtons {
transition.setAlpha(view: inputPanelBackgroundView, alpha: isVisible ? 1.0 : 0.0, delay: isVisible ? 0.0 : 0.4)
@ -1928,7 +1928,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
})
let imageEntity = DrawingStickerEntity(content: .image(image ?? additionalImage, false))
imageEntity.referenceDrawingSize = storyDimensions
imageEntity.scale = 1.49
imageEntity.scale = 1.625
imageEntity.position = position.getPosition(storyDimensions)
self.entitiesView.add(imageEntity, announce: false)
} else if case let .video(_, _, mirror, additionalVideoPath, _, _, _, changes, position) = subject {
@ -1936,7 +1936,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
if let additionalVideoPath {
let videoEntity = DrawingStickerEntity(content: .dualVideoReference)
videoEntity.referenceDrawingSize = storyDimensions
videoEntity.scale = 1.49
videoEntity.scale = 1.625
videoEntity.position = position.getPosition(storyDimensions)
self.entitiesView.add(videoEntity, announce: false)
@ -1955,8 +1955,8 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
if case let .asset(asset) = subject, asset.mediaType == .video {
let videoEntity = DrawingStickerEntity(content: .dualVideoReference)
videoEntity.referenceDrawingSize = storyDimensions
videoEntity.scale = 1.49
videoEntity.position = PIPPosition.bottomRight.getPosition(storyDimensions)
videoEntity.scale = 1.625
videoEntity.position = PIPPosition.topRight.getPosition(storyDimensions)
self.entitiesView.add(videoEntity, announce: false)
mediaEditor.setAdditionalVideo("", positionChanges: [VideoPositionChange(additional: false, timestamp: 0.0), VideoPositionChange(additional: true, timestamp: 3.0)])
@ -2375,7 +2375,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
backgroundImage.draw(in: CGRect(origin: .zero, size: size))
let ellipsePosition = pipPosition.getPosition(storyDimensions)
let ellipseSize = CGSize(width: 401.0, height: 401.0)
let ellipseSize = CGSize(width: 439.0, height: 439.0)
let ellipseRect = CGRect(origin: CGPoint(x: ellipsePosition.x - ellipseSize.width / 2.0, y: ellipsePosition.y - ellipseSize.height / 2.0), size: ellipseSize)
let foregroundSize = foregroundImage.size.aspectFilled(ellipseSize)
let foregroundRect = CGRect(origin: CGPoint(x: ellipseRect.center.x - foregroundSize.width / 2.0, y: ellipseRect.center.y - foregroundSize.height / 2.0), size: foregroundSize)
@ -2427,10 +2427,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
view.animateIn(from: .camera, completion: completion)
}
}
// Queue.mainQueue().after(0.5) {
// self.presentPrivacyTooltip()
// }
}
func animateOut(finished: Bool, saveDraft: Bool, completion: @escaping () -> Void) {
@ -2609,22 +2605,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}
self.requestUpdate(transition: transition)
}
func presentPrivacyTooltip() {
guard let sourceView = self.componentHost.findTaggedView(tag: privacyButtonTag) else {
return
}
let parentFrame = self.view.convert(self.bounds, to: nil)
let absoluteFrame = sourceView.convert(sourceView.bounds, to: nil).offsetBy(dx: -parentFrame.minX, dy: 0.0)
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.maxY + 3.0), size: CGSize())
let tooltipController = TooltipScreen(account: self.context.account, sharedContext: self.context.sharedContext, text: .plain(text: "You can set who can view this story."), location: .point(location, .top), displayDuration: .manual, inset: 16.0, shouldDismissOnTouch: { _, _ in
return .ignore
})
self.controller?.present(tooltipController, in: .current)
}
private weak var muteTooltip: ViewController?
func presentMutedTooltip() {
guard let sourceView = self.componentHost.findTaggedView(tag: muteButtonTag) else {
@ -3151,16 +3132,17 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
case bottomRight
func getPosition(_ size: CGSize) -> CGPoint {
let offset = CGPoint(x: 224.0, y: 480.0)
let topOffset = CGPoint(x: 267.0, y: 438.0)
let bottomOffset = CGPoint(x: 267.0, y: 438.0)
switch self {
case .topLeft:
return CGPoint(x: offset.x, y: offset.y)
return CGPoint(x: topOffset.x, y: topOffset.y)
case .topRight:
return CGPoint(x: size.width - offset.x, y: offset.y)
return CGPoint(x: size.width - topOffset.x, y: topOffset.y)
case .bottomLeft:
return CGPoint(x: offset.x, y: size.height - offset.y)
return CGPoint(x: bottomOffset.x, y: size.height - bottomOffset.y)
case .bottomRight:
return CGPoint(x: size.width - offset.x, y: size.height - offset.y)
return CGPoint(x: size.width - bottomOffset.x, y: size.height - bottomOffset.y)
}
}
}
@ -4483,6 +4465,7 @@ public final class BlurredGradientComponent: Component {
}
private var gradientMask = UIImageView()
private var gradientBackground = SimpleLayer()
private var gradientForeground = SimpleGradientLayer()
public func update(component: BlurredGradientComponent, availableSize: CGSize, transition: Transition) -> CGSize {
@ -4492,17 +4475,21 @@ public final class BlurredGradientComponent: Component {
self.updateColor(color: UIColor(rgb: 0x000000, alpha: component.position == .top ? 0.15 : 0.25), transition: transition.containedViewLayoutTransition)
let gradientHeight: CGFloat = 100.0
if self.mask == nil {
self.mask = self.gradientMask
self.gradientMask.image = generateGradientImage(
size: CGSize(width: 1.0, height: availableSize.height),
size: CGSize(width: 1.0, height: gradientHeight),
colors: [UIColor(rgb: 0xffffff, alpha: 1.0), UIColor(rgb: 0xffffff, alpha: 1.0), UIColor(rgb: 0xffffff, alpha: 0.0)],
locations: component.position == .top ? [0.0, 0.8, 1.0] : [1.0, 0.20, 0.0],
direction: .vertical
)
self.gradientMask.layer.addSublayer(self.gradientBackground)
self.gradientBackground.backgroundColor = UIColor(rgb: 0xffffff).cgColor
if component.dark {
self.gradientForeground.colors = [UIColor(rgb: 0x000000, alpha: 0.6).cgColor, UIColor(rgb: 0x000000, alpha: 0.6).cgColor, UIColor(rgb: 0x000000, alpha: 0.0).cgColor]
self.gradientForeground.colors = [UIColor(rgb: 0x000000, alpha: 0.4).cgColor, UIColor(rgb: 0x000000, alpha: 0.4).cgColor, UIColor(rgb: 0x000000, alpha: 0.0).cgColor]
self.gradientForeground.locations = [0.0, 0.8, 1.0]
} else {
self.gradientForeground.colors = [UIColor(rgb: 0x000000, alpha: 0.35).cgColor, UIColor(rgb: 0x000000, alpha: 0.0).cgColor]
@ -4513,7 +4500,8 @@ public final class BlurredGradientComponent: Component {
self.layer.addSublayer(self.gradientForeground)
}
transition.setFrame(view: self.gradientMask, frame: CGRect(origin: .zero, size: availableSize))
transition.setFrame(view: self.gradientMask, frame: CGRect(origin: .zero, size: CGSize(width: availableSize.width, height: gradientHeight)))
transition.setFrame(layer: self.gradientBackground, frame: CGRect(origin: CGPoint(x: 0.0, y: gradientHeight), size: availableSize))
transition.setFrame(layer: self.gradientForeground, frame: CGRect(origin: .zero, size: availableSize))
self.update(size: availableSize, transition: transition.containedViewLayoutTransition)

View File

@ -355,6 +355,7 @@ public final class StoryItemSetContainerComponent: Component {
var videoRecordingBackgroundView: UIVisualEffectView?
let inputPanel = ComponentView<Empty>()
let inputPanelExternalState = MessageInputPanelComponent.ExternalState()
private let inputPanelContainer = UIView()
private let inputPanelBackground = ComponentView<Empty>()
var preparingToDisplayViewList: Bool = false
@ -427,6 +428,9 @@ public final class StoryItemSetContainerComponent: Component {
self.transitionCloneContainerView = UIView()
self.inputPanelContainer.isUserInteractionEnabled = false
self.inputPanelContainer.layer.cornerRadius = 11.0
super.init(frame: frame)
self.itemsContainerView.addSubview(self.scroller)
@ -1870,11 +1874,11 @@ public final class StoryItemSetContainerComponent: Component {
}
}
let inputMediaNodeHeight = self.sendMessageContext.updateInputMediaNode(inputPanel: self.inputPanel, availableSize: availableSize, bottomInset: component.safeInsets.bottom, inputHeight: component.inputHeight, effectiveInputHeight: inputHeight, metrics: component.metrics, deviceMetrics: component.deviceMetrics, transition: transition)
let inputMediaNodeHeight = self.sendMessageContext.updateInputMediaNode(inputPanel: self.inputPanel, availableSize: availableSize, bottomInset: component.safeInsets.bottom, bottomContainerInset: component.containerInsets.bottom, inputHeight: component.inputHeight, effectiveInputHeight: inputHeight, metrics: component.metrics, deviceMetrics: component.deviceMetrics, transition: transition)
if inputMediaNodeHeight > 0.0 {
inputHeight = inputMediaNodeHeight
}
keyboardHeight = max(keyboardHeight, inputMediaNodeHeight)
keyboardHeight = inputHeight
let hasRecordingBlurBackground = self.sendMessageContext.videoRecorderValue != nil || self.sendMessageContext.hasRecordedVideoPreview
if hasRecordingBlurBackground {
@ -1905,11 +1909,12 @@ public final class StoryItemSetContainerComponent: Component {
transition: transition,
component: AnyComponent(BlurredGradientComponent(position: .bottom, dark: true, tag: nil)),
environment: {},
containerSize: CGSize(width: availableSize.width, height: keyboardHeight + 100.0)
containerSize: CGSize(width: availableSize.width, height: max(0.0, keyboardHeight + 100.0 - component.containerInsets.bottom))
)
if let inputPanelBackgroundView = self.inputPanelBackground.view {
if inputPanelBackgroundView.superview == nil {
self.addSubview(inputPanelBackgroundView)
self.addSubview(self.inputPanelContainer)
self.inputPanelContainer.addSubview(inputPanelBackgroundView)
}
let isVisible = inputHeight > 44.0 && !hasRecordingBlurBackground
transition.setFrame(view: inputPanelBackgroundView, frame: CGRect(origin: CGPoint(x: 0.0, y: isVisible ? availableSize.height - inputPanelBackgroundSize.height : availableSize.height), size: inputPanelBackgroundSize))
@ -2189,6 +2194,8 @@ public final class StoryItemSetContainerComponent: Component {
let contentFrame = CGRect(origin: CGPoint(x: 0.0, y: component.containerInsets.top - (contentSize.height - contentVisualHeight) * 0.5), size: contentSize)
transition.setFrame(view: self.inputPanelContainer, frame: contentFrame)
let itemLayout = ItemLayout(
containerSize: availableSize,
contentFrame: contentFrame,
@ -2855,8 +2862,8 @@ public final class StoryItemSetContainerComponent: Component {
let _ = (enqueueMessages(account: context.account, peerId: peer.id, messages: [message])
|> deliverOnMainQueue).start(next: { [weak self] messageIds in
if let animation {
presentController(UndoOverlayController(
if let animation, let self {
let controller = UndoOverlayController(
presentationData: presentationData,
content: .sticker(context: context, file: animation, loop: false, title: nil, text: "Reaction Sent.", undoText: "View in Chat", customAction: { [weak self] in
if let messageId = messageIds.first, let self {
@ -2865,8 +2872,15 @@ public final class StoryItemSetContainerComponent: Component {
}),
elevatedLayout: false,
animateInAsReplacement: false,
action: { _ in return false }
), nil)
action: { [weak self] _ in
self?.sendMessageContext.tooltipScreen = nil
self?.updateIsProgressPaused()
return false
}
)
self.sendMessageContext.tooltipScreen = controller
self.updateIsProgressPaused()
presentController(controller, nil)
}
})
})

View File

@ -199,7 +199,7 @@ final class StoryItemSetContainerSendMessage {
}
}
func updateInputMediaNode(inputPanel: ComponentView<Empty>, availableSize: CGSize, bottomInset: CGFloat, inputHeight: CGFloat, effectiveInputHeight: CGFloat, metrics: LayoutMetrics, deviceMetrics: DeviceMetrics, transition: Transition) -> CGFloat {
func updateInputMediaNode(inputPanel: ComponentView<Empty>, availableSize: CGSize, bottomInset: CGFloat, bottomContainerInset: CGFloat, inputHeight: CGFloat, effectiveInputHeight: CGFloat, metrics: LayoutMetrics, deviceMetrics: DeviceMetrics, transition: Transition) -> CGFloat {
guard let context = self.context, let inputPanelView = inputPanel.view as? MessageInputPanelComponent.View else {
return 0.0
}
@ -254,7 +254,7 @@ final class StoryItemSetContainerSendMessage {
isGeneralThreadClosed: nil
)
let heightAndOverflow = inputMediaNode.updateLayout(width: availableSize.width, leftInset: 0.0, rightInset: 0.0, bottomInset: bottomInset, standardInputHeight: deviceMetrics.standardInputHeight(inLandscape: false), inputHeight: inputHeight, maximumHeight: availableSize.height, inputPanelHeight: 0.0, transition: .immediate, interfaceState: presentationInterfaceState, layoutMetrics: metrics, deviceMetrics: deviceMetrics, isVisible: true, isExpanded: false)
let heightAndOverflow = inputMediaNode.updateLayout(width: availableSize.width, leftInset: 0.0, rightInset: 0.0, bottomInset: bottomInset, standardInputHeight: deviceMetrics.standardInputHeight(inLandscape: false), inputHeight: inputHeight < 100.0 ? inputHeight - bottomContainerInset : inputHeight, maximumHeight: availableSize.height, inputPanelHeight: 0.0, transition: .immediate, interfaceState: presentationInterfaceState, layoutMetrics: metrics, deviceMetrics: deviceMetrics, isVisible: true, isExpanded: false)
let inputNodeHeight = heightAndOverflow.0
let inputNodeFrame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - inputNodeHeight), size: CGSize(width: availableSize.width, height: inputNodeHeight))