mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Edit message media preview
This commit is contained in:
@@ -40,10 +40,12 @@ public enum SendMessageActionSheetControllerParams {
|
||||
public final class EditMessage {
|
||||
public let messages: [EngineMessage]
|
||||
public let mediaPreview: ChatSendMessageContextScreenMediaPreview?
|
||||
public let mediaCaptionIsAbove: (Bool, (Bool) -> Void)?
|
||||
|
||||
public init(messages: [EngineMessage], mediaPreview: ChatSendMessageContextScreenMediaPreview?) {
|
||||
public init(messages: [EngineMessage], mediaPreview: ChatSendMessageContextScreenMediaPreview?, mediaCaptionIsAbove: (Bool, (Bool) -> Void)?) {
|
||||
self.messages = messages
|
||||
self.mediaPreview = mediaPreview
|
||||
self.mediaCaptionIsAbove = mediaCaptionIsAbove
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -320,9 +320,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
case let .sendMessage(sendMessage):
|
||||
self.mediaCaptionIsAbove = sendMessage.mediaCaptionIsAbove?.0 ?? false
|
||||
case let .editMessage(editMessage):
|
||||
self.mediaCaptionIsAbove = editMessage.messages.contains(where: {
|
||||
return $0.attributes.contains(where: { $0 is InvertMediaMessageAttribute })
|
||||
})
|
||||
self.mediaCaptionIsAbove = editMessage.mediaCaptionIsAbove?.0 ?? false
|
||||
}
|
||||
|
||||
component.gesture.externalUpdated = { [weak self] view, location in
|
||||
@@ -483,8 +481,8 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
switch component.params {
|
||||
case let .sendMessage(sendMessage):
|
||||
sendMessage.mediaCaptionIsAbove?.1(self.mediaCaptionIsAbove)
|
||||
case .editMessage:
|
||||
break
|
||||
case let .editMessage(editMessage):
|
||||
editMessage.mediaCaptionIsAbove?.1(self.mediaCaptionIsAbove)
|
||||
}
|
||||
if !self.isUpdating {
|
||||
self.state?.updated(transition: .spring(duration: 0.35))
|
||||
@@ -704,6 +702,11 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
messageItemViewContainerSize = CGSize(width: availableSize.width - 16.0 - 40.0, height: availableSize.height)
|
||||
}
|
||||
|
||||
var isEditMessage = false
|
||||
if case .editMessage = component.params {
|
||||
isEditMessage = true
|
||||
}
|
||||
|
||||
let messageItemSize = messageItemView.update(
|
||||
context: component.context,
|
||||
presentationData: presentationData,
|
||||
@@ -719,6 +722,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
maxTextHeight: 20000.0,
|
||||
containerSize: messageItemViewContainerSize,
|
||||
effect: self.presentationAnimationState.key == .animatedIn ? self.selectedMessageEffect : nil,
|
||||
isEditMessage: isEditMessage,
|
||||
transition: transition
|
||||
)
|
||||
let sourceMessageItemFrame = CGRect(origin: CGPoint(x: localSourceTextInputViewFrame.minX - sourceMessageTextInsets.left, y: localSourceTextInputViewFrame.minY - 2.0), size: messageItemSize)
|
||||
@@ -1141,6 +1145,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
|
||||
messageItemView.animateIn(
|
||||
sourceTextInputView: component.textInputView as? ChatInputTextView,
|
||||
isEditMessage: isEditMessage,
|
||||
transition: transition
|
||||
)
|
||||
case .animatedOut:
|
||||
@@ -1150,6 +1155,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
messageItemView.animateOut(
|
||||
sourceTextInputView: component.textInputView as? ChatInputTextView,
|
||||
toEmpty: self.animateOutToEmpty,
|
||||
isEditMessage: isEditMessage,
|
||||
transition: transition
|
||||
)
|
||||
}
|
||||
|
||||
@@ -245,23 +245,35 @@ final class MessageItemView: UIView {
|
||||
|
||||
func animateIn(
|
||||
sourceTextInputView: ChatInputTextView?,
|
||||
isEditMessage: Bool,
|
||||
transition: Transition
|
||||
) {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
mediaPreview.animateIn(transition: transition)
|
||||
if isEditMessage {
|
||||
transition.animateScale(view: self, from: 0.001, to: 1.0)
|
||||
transition.animateAlpha(view: self, from: 0.0, to: 1.0)
|
||||
} else {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
mediaPreview.animateIn(transition: transition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(
|
||||
sourceTextInputView: ChatInputTextView?,
|
||||
toEmpty: Bool,
|
||||
isEditMessage: Bool,
|
||||
transition: Transition
|
||||
) {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
if toEmpty {
|
||||
mediaPreview.animateOutOnSend(transition: transition)
|
||||
} else {
|
||||
mediaPreview.animateOut(transition: transition)
|
||||
if isEditMessage {
|
||||
transition.setScale(view: self, scale: 0.001)
|
||||
transition.setAlpha(view: self, alpha: 0.0)
|
||||
} else {
|
||||
if let mediaPreview = self.mediaPreview {
|
||||
if toEmpty {
|
||||
mediaPreview.animateOutOnSend(transition: transition)
|
||||
} else {
|
||||
mediaPreview.animateOut(transition: transition)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,6 +293,7 @@ final class MessageItemView: UIView {
|
||||
maxTextHeight: CGFloat,
|
||||
containerSize: CGSize,
|
||||
effect: AvailableMessageEffects.MessageEffect?,
|
||||
isEditMessage: Bool,
|
||||
transition: Transition
|
||||
) -> CGSize {
|
||||
self.emojiViewProvider = emojiViewProvider
|
||||
@@ -387,6 +400,8 @@ final class MessageItemView: UIView {
|
||||
backgroundAlpha = 0.0
|
||||
}
|
||||
|
||||
let backgroundScale: CGFloat = 1.0
|
||||
|
||||
var backgroundFrame = mediaPreviewFrame.insetBy(dx: -2.0, dy: -2.0)
|
||||
backgroundFrame.size.width += 6.0
|
||||
|
||||
@@ -502,10 +517,14 @@ 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.setPosition(view: self.backgroundWallpaperNode.view, position: CGRect(origin: CGPoint(), size: backgroundFrame.size).center)
|
||||
transition.setBounds(view: self.backgroundWallpaperNode.view, bounds: CGRect(origin: CGPoint(), size: backgroundFrame.size))
|
||||
alphaTransition.setAlpha(view: self.backgroundWallpaperNode.view, alpha: backgroundAlpha)
|
||||
transition.setScale(view: self.backgroundWallpaperNode.view, scale: backgroundScale)
|
||||
self.backgroundWallpaperNode.updateFrame(backgroundFrame, transition: transition.containedViewLayoutTransition)
|
||||
transition.setFrame(view: self.backgroundNode.view, frame: backgroundFrame)
|
||||
transition.setPosition(view: self.backgroundNode.view, position: backgroundFrame.center)
|
||||
transition.setBounds(view: self.backgroundNode.view, bounds: CGRect(origin: CGPoint(), size: backgroundFrame.size))
|
||||
transition.setScale(view: self.backgroundNode.view, scale: backgroundScale)
|
||||
alphaTransition.setAlpha(view: self.backgroundNode.view, alpha: backgroundAlpha)
|
||||
self.backgroundNode.updateLayout(size: backgroundFrame.size, transition: transition.containedViewLayoutTransition)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user