[WIP] Story collage

This commit is contained in:
Ilya Laktyushin
2024-11-27 18:41:03 +04:00
parent 0794812bae
commit d2b5476293
78 changed files with 6086 additions and 1224 deletions

View File

@@ -33,12 +33,22 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
private var currentIsEditing = false
private var currentHeight: CGFloat?
private var currentIsVideo = false
private var currentIsCaptionAbove = false
private let hapticFeedback = HapticFeedback()
private var inputView: LegacyMessageInputPanelInputView?
private var isEmojiKeyboardActive = false
public var sendPressed: ((NSAttributedString?) -> Void)?
public var focusUpdated: ((Bool) -> Void)?
public var heightUpdated: ((Bool) -> Void)?
public var timerUpdated: ((NSNumber?) -> Void)?
public var captionIsAboveUpdated: ((Bool) -> Void)?
private weak var undoController: UndoOverlayController?
private weak var tooltipController: TooltipScreen?
private var validLayout: (width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, keyboardHeight: CGFloat, additionalSideInsets: UIEdgeInsets, maxHeight: CGFloat, isSecondary: Bool, metrics: LayoutMetrics)?
public init(
@@ -67,11 +77,6 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
}
}
public var sendPressed: ((NSAttributedString?) -> Void)?
public var focusUpdated: ((Bool) -> Void)?
public var heightUpdated: ((Bool) -> Void)?
public var timerUpdated: ((NSNumber?) -> Void)?
public func updateLayoutSize(_ size: CGSize, keyboardHeight: CGFloat, sideInset: CGFloat, animated: Bool) -> CGFloat {
return self.updateLayout(width: size.width, leftInset: sideInset, rightInset: sideInset, bottomInset: 0.0, keyboardHeight: keyboardHeight, additionalSideInsets: UIEdgeInsets(), maxHeight: size.height, isSecondary: false, transition: animated ? .animated(duration: 0.2, curve: .easeInOut) : .immediate, metrics: LayoutMetrics(widthClass: .compact, heightClass: .compact, orientation: nil), isMediaInputExpanded: false)
}
@@ -99,14 +104,15 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
transition.setFrame(view: view, frame: frame)
}
public func setTimeout(_ timeout: Int32, isVideo: Bool) {
self.dismissTimeoutTooltip()
public func setTimeout(_ timeout: Int32, isVideo: Bool, isCaptionAbove: Bool) {
self.dismissAllTooltips()
var timeout: Int32? = timeout
if timeout == 0 {
timeout = nil
}
self.currentTimeout = timeout
self.currentIsVideo = isVideo
self.currentIsCaptionAbove = isCaptionAbove
}
public func activateInput() {
@@ -132,7 +138,7 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
}
public func onAnimateOut() {
self.dismissTimeoutTooltip()
self.dismissAllTooltips()
}
public func baseHeight() -> CGFloat {
@@ -233,7 +239,12 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
lockMediaRecording: nil,
stopAndPreviewMediaRecording: nil,
discardMediaRecordingPreview: nil,
attachmentAction: nil,
attachmentAction: { [weak self] in
if let self {
self.toggleIsCaptionAbove()
}
},
attachmentButtonMode: self.currentIsCaptionAbove ? .captionDown : .captionUp,
myReaction: nil,
likeAction: nil,
likeOptionsAction: nil,
@@ -249,6 +260,11 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
} : nil,
forwardAction: nil,
moreAction: nil,
presentCaptionPositionTooltip: { [weak self] sourceView in
if let self {
self.presentCaptionPositionTooltip(sourceView: sourceView)
}
},
presentVoiceMessagesUnavailableTooltip: nil,
presentTextLengthLimitTooltip: nil,
presentTextFormattingTooltip: nil,
@@ -340,6 +356,31 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
}
}
private func toggleIsCaptionAbove() {
//TODO:localize
self.currentIsCaptionAbove = !self.currentIsCaptionAbove
self.captionIsAboveUpdated?(self.currentIsCaptionAbove)
self.update(transition: .animated(duration: 0.3, curve: .spring))
self.dismissAllTooltips()
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
let title = self.currentIsCaptionAbove ? "Caption moved up" : "Caption moved down"
let text = self.currentIsCaptionAbove ? "Text will be shown above the media." : "Text will be shown below the media."
let animationName = self.currentIsCaptionAbove ? "message_preview_sort_above" : "message_preview_sort_below"
let controller = UndoOverlayController(
presentationData: presentationData,
content: .universal(animation: animationName, scale: 1.0, colors: ["__allcolors__": UIColor.white], title: title, text: text, customUndoText: nil, timeout: 2.0),
elevatedLayout: false,
position: self.currentIsCaptionAbove ? .bottom : .top,
action: { _ in return false }
)
self.present(controller)
self.undoController = controller
}
private func presentTimeoutSetup(sourceView: UIView, gesture: ContextGesture?) {
self.hapticFeedback.impact(.light)
@@ -395,10 +436,12 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
let contextController = ContextController(presentationData: presentationData, source: .reference(HeaderContextReferenceContentSource(sourceView: sourceView)), items: .single(ContextController.Items(content: .list(items))), gesture: gesture)
self.present(contextController)
}
private weak var tooltipController: TooltipScreen?
private func dismissTimeoutTooltip() {
private func dismissAllTooltips() {
if let undoController = self.undoController {
self.undoController = nil
undoController.dismissWithCommitAction()
}
if let tooltipController = self.tooltipController {
self.tooltipController = nil
tooltipController.dismiss()
@@ -409,7 +452,7 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
guard let superview = self.view.superview?.superview else {
return
}
self.dismissTimeoutTooltip()
self.dismissAllTooltips()
let parentFrame = superview.convert(superview.bounds, to: nil)
let absoluteFrame = sourceView.convert(sourceView.bounds, to: nil).offsetBy(dx: -parentFrame.minX, dy: 0.0)
@@ -449,6 +492,38 @@ public class LegacyMessageInputPanelNode: ASDisplayNode, TGCaptionPanelView {
self.present(tooltipController)
}
private func presentCaptionPositionTooltip(sourceView: UIView) {
guard let superview = self.view.superview?.superview else {
return
}
self.dismissAllTooltips()
let parentFrame = superview.convert(superview.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 + 2.0, y: absoluteFrame.minY + 6.0), size: CGSize())
//TODO:localize
let text = "Tap here to move caption up."
let tooltipController = TooltipScreen(
account: self.context.account,
sharedContext: self.context.sharedContext,
text: .plain(text: text),
balancedTextLayout: false,
style: .customBlur(UIColor(rgb: 0x18181a), 4.0),
arrowStyle: .small,
icon: nil,
location: .point(location, .bottom),
displayDuration: .default,
inset: 4.0,
cornerRadius: 10.0,
shouldDismissOnTouch: { _, _ in
return .ignore
}
)
self.tooltipController = tooltipController
self.present(tooltipController)
}
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let result = super.hitTest(point, with: event)
if let view = self.inputPanel.view, let panelResult = view.hitTest(self.view.convert(point, to: view), with: event) {