mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Message preview improvements
This commit is contained in:
@@ -29,8 +29,8 @@ private final class ChatSendMessageActionSheetControllerImpl: ViewController, Ch
|
||||
private let attachment: Bool
|
||||
private let canSendWhenOnline: Bool
|
||||
private let completion: () -> Void
|
||||
private let sendMessage: (SendMode, MessageEffect?) -> Void
|
||||
private let schedule: (MessageEffect?) -> Void
|
||||
private let sendMessage: (SendMode, SendParameters?) -> Void
|
||||
private let schedule: (SendParameters?) -> Void
|
||||
private let reactionItems: [ReactionItem]?
|
||||
|
||||
private var presentationData: PresentationData
|
||||
@@ -44,7 +44,7 @@ private final class ChatSendMessageActionSheetControllerImpl: ViewController, Ch
|
||||
|
||||
private let emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?
|
||||
|
||||
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peerId: EnginePeer.Id?, isScheduledMessages: Bool = false, forwardMessageIds: [EngineMessage.Id]?, hasEntityKeyboard: Bool, gesture: ContextGesture, sourceSendButton: ASDisplayNode, textInputView: UITextView, emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?, attachment: Bool = false, canSendWhenOnline: Bool, completion: @escaping () -> Void, sendMessage: @escaping (SendMode, MessageEffect?) -> Void, schedule: @escaping (MessageEffect?) -> Void, reactionItems: [ReactionItem]? = nil) {
|
||||
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peerId: EnginePeer.Id?, isScheduledMessages: Bool = false, forwardMessageIds: [EngineMessage.Id]?, hasEntityKeyboard: Bool, gesture: ContextGesture, sourceSendButton: ASDisplayNode, textInputView: UITextView, emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?, attachment: Bool = false, canSendWhenOnline: Bool, completion: @escaping () -> Void, sendMessage: @escaping (SendMode, SendParameters?) -> Void, schedule: @escaping (SendParameters?) -> Void, reactionItems: [ReactionItem]? = nil) {
|
||||
self.context = context
|
||||
self.peerId = peerId
|
||||
self.isScheduledMessages = isScheduledMessages
|
||||
@@ -108,32 +108,16 @@ private final class ChatSendMessageActionSheetControllerImpl: ViewController, Ch
|
||||
}
|
||||
|
||||
self.displayNode = ChatSendMessageActionSheetControllerNode(context: self.context, presentationData: self.presentationData, reminders: reminders, gesture: gesture, sourceSendButton: self.sourceSendButton, textInputView: self.textInputView, attachment: self.attachment, canSendWhenOnline: self.canSendWhenOnline, forwardedCount: forwardedCount, hasEntityKeyboard: self.hasEntityKeyboard, emojiViewProvider: self.emojiViewProvider, send: { [weak self] in
|
||||
var messageEffect: MessageEffect?
|
||||
if let selectedEffect = self?.controllerNode.selectedMessageEffect {
|
||||
messageEffect = MessageEffect(id: selectedEffect.id)
|
||||
}
|
||||
self?.sendMessage(.generic, messageEffect)
|
||||
self?.sendMessage(.generic, nil)
|
||||
self?.dismiss(cancel: false)
|
||||
}, sendSilently: { [weak self] in
|
||||
var messageEffect: MessageEffect?
|
||||
if let selectedEffect = self?.controllerNode.selectedMessageEffect {
|
||||
messageEffect = MessageEffect(id: selectedEffect.id)
|
||||
}
|
||||
self?.sendMessage(.silently, messageEffect)
|
||||
self?.sendMessage(.silently, nil)
|
||||
self?.dismiss(cancel: false)
|
||||
}, sendWhenOnline: { [weak self] in
|
||||
var messageEffect: MessageEffect?
|
||||
if let selectedEffect = self?.controllerNode.selectedMessageEffect {
|
||||
messageEffect = MessageEffect(id: selectedEffect.id)
|
||||
}
|
||||
self?.sendMessage(.whenOnline, messageEffect)
|
||||
self?.sendMessage(.whenOnline, nil)
|
||||
self?.dismiss(cancel: false)
|
||||
}, schedule: !canSchedule ? nil : { [weak self] in
|
||||
var messageEffect: MessageEffect?
|
||||
if let selectedEffect = self?.controllerNode.selectedMessageEffect {
|
||||
messageEffect = MessageEffect(id: selectedEffect.id)
|
||||
}
|
||||
self?.schedule(messageEffect)
|
||||
self?.schedule(nil)
|
||||
self?.dismiss(cancel: false)
|
||||
}, cancel: { [weak self] in
|
||||
self?.dismiss(cancel: true)
|
||||
@@ -191,8 +175,8 @@ public func makeChatSendMessageActionSheetController(
|
||||
attachment: Bool = false,
|
||||
canSendWhenOnline: Bool,
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
reactionItems: [ReactionItem]? = nil,
|
||||
availableMessageEffects: AvailableMessageEffects? = nil,
|
||||
isPremium: Bool = false
|
||||
|
||||
@@ -69,8 +69,8 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
let attachment: Bool
|
||||
let canSendWhenOnline: Bool
|
||||
let completion: () -> Void
|
||||
let sendMessage: (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.MessageEffect?) -> Void
|
||||
let schedule: (ChatSendMessageActionSheetController.MessageEffect?) -> Void
|
||||
let sendMessage: (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void
|
||||
let schedule: (ChatSendMessageActionSheetController.SendParameters?) -> Void
|
||||
let reactionItems: [ReactionItem]?
|
||||
let availableMessageEffects: AvailableMessageEffects?
|
||||
let isPremium: Bool
|
||||
@@ -92,8 +92,8 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
attachment: Bool,
|
||||
canSendWhenOnline: Bool,
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
reactionItems: [ReactionItem]?,
|
||||
availableMessageEffects: AvailableMessageEffects?,
|
||||
isPremium: Bool
|
||||
@@ -222,7 +222,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
self.animateOutToEmpty = true
|
||||
component.sendMessage(.generic, self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.MessageEffect(id: $0.id) }))
|
||||
|
||||
let sendParameters = ChatSendMessageActionSheetController.SendParameters(
|
||||
effect: self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.SendParameters.Effect(id: $0.id) }),
|
||||
textIsAboveMedia: self.mediaCaptionIsAbove
|
||||
)
|
||||
|
||||
component.sendMessage(.generic, sendParameters)
|
||||
self.environment?.controller()?.dismiss()
|
||||
}
|
||||
|
||||
@@ -327,6 +333,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
)
|
||||
}
|
||||
|
||||
let textString: NSAttributedString
|
||||
if let attributedText = component.textInputView.attributedText {
|
||||
textString = attributedText
|
||||
} else {
|
||||
textString = NSAttributedString(string: " ", font: Font.regular(17.0), textColor: .black)
|
||||
}
|
||||
|
||||
let sendButton: SendButton
|
||||
if let current = self.sendButton {
|
||||
sendButton = current
|
||||
@@ -365,7 +378,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
|
||||
var items: [ContextMenuItem] = []
|
||||
if component.mediaCaptionIsAbove != nil {
|
||||
if component.mediaCaptionIsAbove != nil, textString.length != 0, case .media = component.mediaPreview?.layoutType {
|
||||
//TODO:localize
|
||||
let mediaCaptionIsAbove = self.mediaCaptionIsAbove
|
||||
items.append(.action(ContextMenuActionItem(
|
||||
@@ -398,7 +411,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
self.animateOutToEmpty = true
|
||||
component.sendMessage(.silently, self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.MessageEffect(id: $0.id) }))
|
||||
|
||||
let sendParameters = ChatSendMessageActionSheetController.SendParameters(
|
||||
effect: self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.SendParameters.Effect(id: $0.id) }),
|
||||
textIsAboveMedia: self.mediaCaptionIsAbove
|
||||
)
|
||||
|
||||
component.sendMessage(.silently, sendParameters)
|
||||
self.environment?.controller()?.dismiss()
|
||||
}
|
||||
)))
|
||||
@@ -414,7 +433,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
self.animateOutToEmpty = true
|
||||
component.sendMessage(.whenOnline, self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.MessageEffect(id: $0.id) }))
|
||||
|
||||
let sendParameters = ChatSendMessageActionSheetController.SendParameters(
|
||||
effect: self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.SendParameters.Effect(id: $0.id) }),
|
||||
textIsAboveMedia: self.mediaCaptionIsAbove
|
||||
)
|
||||
|
||||
component.sendMessage(.whenOnline, sendParameters)
|
||||
self.environment?.controller()?.dismiss()
|
||||
}
|
||||
)))
|
||||
@@ -431,7 +456,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
self.animateOutToEmpty = true
|
||||
component.schedule(self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.MessageEffect(id: $0.id) }))
|
||||
|
||||
let sendParameters = ChatSendMessageActionSheetController.SendParameters(
|
||||
effect: self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.SendParameters.Effect(id: $0.id) }),
|
||||
textIsAboveMedia: self.mediaCaptionIsAbove
|
||||
)
|
||||
|
||||
component.schedule(sendParameters)
|
||||
self.environment?.controller()?.dismiss()
|
||||
}
|
||||
)))
|
||||
@@ -499,13 +530,6 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
self.addSubview(messageItemView)
|
||||
}
|
||||
|
||||
let textString: NSAttributedString
|
||||
if let attributedText = component.textInputView.attributedText {
|
||||
textString = attributedText
|
||||
} else {
|
||||
textString = NSAttributedString(string: " ", font: Font.regular(17.0), textColor: .black)
|
||||
}
|
||||
|
||||
let localSourceTextInputViewFrame = convertFrame(component.textInputView.bounds, from: component.textInputView, to: self)
|
||||
|
||||
let sourceMessageTextInsets = UIEdgeInsets(top: 7.0, left: 12.0, bottom: 6.0, right: 20.0)
|
||||
@@ -952,12 +976,19 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
Transition.immediate.setScale(view: actionsStackNode.view, scale: 1.0)
|
||||
actionsStackNode.layer.animateSpring(from: 0.001 as NSNumber, to: 1.0 as NSNumber, keyPath: "transform.scale", duration: 0.42, damping: 104.0)
|
||||
|
||||
messageItemView.animateIn(transition: transition)
|
||||
messageItemView.animateIn(
|
||||
sourceTextInputView: component.textInputView as? ChatInputTextView,
|
||||
transition: transition
|
||||
)
|
||||
case .animatedOut:
|
||||
transition.setAlpha(view: actionsStackNode.view, alpha: 0.0)
|
||||
transition.setScale(view: actionsStackNode.view, scale: 0.001)
|
||||
|
||||
messageItemView.animateOut(toEmpty: self.animateOutToEmpty, transition: transition)
|
||||
messageItemView.animateOut(
|
||||
sourceTextInputView: component.textInputView as? ChatInputTextView,
|
||||
toEmpty: self.animateOutToEmpty,
|
||||
transition: transition
|
||||
)
|
||||
}
|
||||
} else {
|
||||
switch self.presentationAnimationState {
|
||||
@@ -1141,8 +1172,8 @@ public class ChatSendMessageContextScreen: ViewControllerComponentContainer, Cha
|
||||
attachment: Bool,
|
||||
canSendWhenOnline: Bool,
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.MessageEffect?) -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
reactionItems: [ReactionItem]?,
|
||||
availableMessageEffects: AvailableMessageEffects?,
|
||||
isPremium: Bool
|
||||
|
||||
@@ -155,6 +155,7 @@ final class MessageItemView: UIView {
|
||||
|
||||
private var chatTheme: ChatPresentationThemeData?
|
||||
private var currentSize: CGSize?
|
||||
private var currentMediaCaptionIsAbove: Bool = false
|
||||
|
||||
override init(frame: CGRect) {
|
||||
self.backgroundWallpaperNode = ChatMessageBubbleBackdrop()
|
||||
@@ -162,6 +163,7 @@ final class MessageItemView: UIView {
|
||||
self.backgroundNode.backdropNode = self.backgroundWallpaperNode
|
||||
|
||||
self.textClippingContainer = UIView()
|
||||
self.textClippingContainer.layer.anchorPoint = CGPoint()
|
||||
self.textClippingContainer.clipsToBounds = true
|
||||
|
||||
super.init(frame: frame)
|
||||
@@ -178,13 +180,20 @@ final class MessageItemView: UIView {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
func animateIn(transition: Transition) {
|
||||
func animateIn(
|
||||
sourceTextInputView: ChatInputTextView?,
|
||||
transition: Transition
|
||||
) {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
mediaPreview.animateIn(transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(toEmpty: Bool, transition: Transition) {
|
||||
func animateOut(
|
||||
sourceTextInputView: ChatInputTextView?,
|
||||
toEmpty: Bool,
|
||||
transition: Transition
|
||||
) {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
if toEmpty {
|
||||
mediaPreview.animateOutOnSend(transition: transition)
|
||||
@@ -266,6 +275,8 @@ final class MessageItemView: UIView {
|
||||
backgroundNode: backgroundNode
|
||||
)
|
||||
|
||||
let alphaTransition: Transition = transition.animation.isImmediate ? .immediate : .easeInOut(duration: 0.25)
|
||||
|
||||
if let sourceMediaPreview {
|
||||
let mediaPreviewClippingView: UIView
|
||||
if let current = self.mediaPreviewClippingView {
|
||||
@@ -304,7 +315,11 @@ final class MessageItemView: UIView {
|
||||
let backgroundAlpha: CGFloat
|
||||
switch sourceMediaPreview.layoutType {
|
||||
case .media:
|
||||
backgroundAlpha = explicitBackgroundSize != nil ? 0.0 : 1.0
|
||||
if textString.length != 0 {
|
||||
backgroundAlpha = explicitBackgroundSize != nil ? 0.0 : 1.0
|
||||
} else {
|
||||
backgroundAlpha = 0.0
|
||||
}
|
||||
case .message, .videoMessage:
|
||||
backgroundAlpha = 0.0
|
||||
}
|
||||
@@ -312,7 +327,7 @@ final class MessageItemView: UIView {
|
||||
var backgroundFrame = mediaPreviewFrame.insetBy(dx: -2.0, dy: -2.0)
|
||||
backgroundFrame.size.width += 6.0
|
||||
|
||||
if textString.length != 0 {
|
||||
if textString.length != 0, case .media = sourceMediaPreview.layoutType {
|
||||
let textNode: ChatInputTextNode
|
||||
if let current = self.textNode {
|
||||
textNode = current
|
||||
@@ -414,9 +429,10 @@ final class MessageItemView: UIView {
|
||||
textClippingContainerBounds.origin.y = max(0.0, textClippingContainerBounds.origin.y)
|
||||
}
|
||||
|
||||
transition.setPosition(view: self.textClippingContainer, position: textClippingContainerFrame.center)
|
||||
transition.setPosition(view: self.textClippingContainer, position: textClippingContainerFrame.origin)
|
||||
transition.setBounds(view: self.textClippingContainer, bounds: textClippingContainerBounds)
|
||||
|
||||
alphaTransition.setAlpha(view: textNode.view, alpha: backgroundAlpha)
|
||||
transition.setFrame(view: textNode.view, frame: CGRect(origin: CGPoint(x: textFrame.minX + textPositioningInsets.left - textClippingContainerFrame.minX, y: textFrame.minY + textPositioningInsets.top - textClippingContainerFrame.minY), size: CGSize(width: maxTextWidth, height: textHeight)))
|
||||
self.updateTextContents()
|
||||
}
|
||||
@@ -424,10 +440,10 @@ final class MessageItemView: UIView {
|
||||
transition.setFrame(view: sourceMediaPreview.view, frame: mediaPreviewFrame)
|
||||
|
||||
transition.setFrame(view: self.backgroundWallpaperNode.view, frame: CGRect(origin: CGPoint(), size: backgroundFrame.size))
|
||||
transition.setAlpha(view: self.backgroundWallpaperNode.view, alpha: backgroundAlpha)
|
||||
alphaTransition.setAlpha(view: self.backgroundWallpaperNode.view, alpha: backgroundAlpha)
|
||||
self.backgroundWallpaperNode.updateFrame(backgroundFrame, transition: transition.containedViewLayoutTransition)
|
||||
transition.setFrame(view: self.backgroundNode.view, frame: backgroundFrame)
|
||||
transition.setAlpha(view: self.backgroundNode.view, alpha: backgroundAlpha)
|
||||
alphaTransition.setAlpha(view: self.backgroundNode.view, alpha: backgroundAlpha)
|
||||
self.backgroundNode.updateLayout(size: backgroundFrame.size, transition: transition.containedViewLayoutTransition)
|
||||
|
||||
if let effectIcon = self.effectIcon, let effectIconSize {
|
||||
@@ -598,7 +614,7 @@ final class MessageItemView: UIView {
|
||||
textClippingContainerBounds.origin.y = max(0.0, textClippingContainerBounds.origin.y)
|
||||
}
|
||||
|
||||
transition.setPosition(view: self.textClippingContainer, position: textClippingContainerFrame.center)
|
||||
transition.setPosition(view: self.textClippingContainer, position: textClippingContainerFrame.origin)
|
||||
transition.setBounds(view: self.textClippingContainer, bounds: textClippingContainerBounds)
|
||||
|
||||
textNode.view.frame = CGRect(origin: CGPoint(x: textFrame.minX + textPositioningInsets.left - textClippingContainerFrame.minX, y: textFrame.minY + textPositioningInsets.top - textClippingContainerFrame.minY), size: CGSize(width: maxTextWidth, height: textHeight))
|
||||
|
||||
Reference in New Issue
Block a user