From 7d962cc90fec2e06d81487782e396da8ddb11c55 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 30 Jul 2019 16:52:34 +0300 Subject: [PATCH] Fixed chat message preview layout on scrolling --- .../ChatHistoryNavigationButtonNode.swift | 4 +++- ...SendMessageActionSheetControllerNode.swift | 20 +++++++++++-------- .../Sources/PresentationThemeSettings.swift | 18 ++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryNavigationButtonNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryNavigationButtonNode.swift index d2e263c84e..6d27116d42 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryNavigationButtonNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryNavigationButtonNode.swift @@ -37,9 +37,11 @@ class ChatHistoryNavigationButtonNode: ASControlNode { } private var theme: PresentationTheme + private let type: ChatHistoryNavigationButtonType init(theme: PresentationTheme, type: ChatHistoryNavigationButtonType) { self.theme = theme + self.type = type self.imageNode = ASImageNode() self.imageNode.displayWithoutProcessing = true @@ -77,7 +79,7 @@ class ChatHistoryNavigationButtonNode: ASControlNode { if self.theme !== theme { self.theme = theme - switch type { + switch self.type { case .down: self.imageNode.image = PresentationResourcesChat.chatHistoryNavigationButtonImage(theme) case .mentions: diff --git a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift index 43b3567ceb..ac7dee2106 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift @@ -390,14 +390,6 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, intermediateCompletion() }) - Queue.mainQueue().after(0.7) { - completedAlpha = true - completedButton = true - completedBubble = true - completedEffect = true - intermediateCompletion() - } - self.dimNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) self.contentContainerNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in }) @@ -453,6 +445,8 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, let textOffset = self.textInputNode.textView.contentSize.height - self.textInputNode.textView.contentOffset.y - self.textInputNode.textView.frame.height self.fromMessageTextNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: delta * 2.0 + textOffset), duration: duration, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true) self.toMessageTextNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: delta * 2.0 + textOffset), duration: duration, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true) + } else { + completedBubble = true } self.contentContainerNode.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 160.0, y: 0.0), duration: duration, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true) @@ -460,6 +454,12 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, } } + func scrollViewDidScroll(_ scrollView: UIScrollView) { + if let layout = self.validLayout { + self.containerLayoutUpdated(layout, transition: .immediate) + } + } + func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { self.validLayout = layout @@ -484,10 +484,13 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, let insets = layout.insets(options: [.statusBar, .input]) let inputHeight = layout.inputHeight ?? 0.0 + let contentOffset = self.scrollNode.view.contentOffset.y + var contentOrigin = CGPoint(x: layout.size.width - sideInset - contentSize.width - layout.safeInsets.right, y: layout.size.height - 6.0 - insets.bottom - contentSize.height) if inputHeight > 0.0 { contentOrigin.y += 60.0 } + contentOrigin.y = min(contentOrigin.y + contentOffset, layout.size.height - 6.0 - layout.intrinsicInsets.bottom - contentSize.height) transition.updateFrame(node: self.contentContainerNode, frame: CGRect(origin: contentOrigin, size: contentSize)) var nextY: CGFloat = 0.0 @@ -502,6 +505,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, if inputHeight.isZero { sendButtonFrame.origin.y -= 60.0 } + sendButtonFrame.origin.y = min(sendButtonFrame.origin.y + contentOffset, layout.size.height - layout.intrinsicInsets.bottom - initialSendButtonFrame.height) transition.updateFrame(node: self.sendButtonNode, frame: sendButtonFrame) var messageFrame = self.textFieldFrame diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index 2a89a985b0..1d63717c6e 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -257,15 +257,15 @@ public struct PresentationThemeAccentColor: PostboxCoding, Equatable { } public var color: UIColor { - let color: UIColor - if self.value < 0.5 { - color = self.baseColor.color.interpolateTo(self.baseColor.edgeColors.0, fraction: 0.5 - self.value)! - } else if self.value > 0.5 { - color = self.baseColor.color.interpolateTo(self.baseColor.edgeColors.1, fraction: self.value - 0.5)! - } else { - color = self.baseColor.color - } - return color +// let color: UIColor +// if self.value < 0.5 { +// color = self.baseColor.color.interpolateTo(self.baseColor.edgeColors.0, fraction: 0.5 - self.value)! +// } else if self.value > 0.5 { +// color = self.baseColor.color.interpolateTo(self.baseColor.edgeColors.1, fraction: self.value - 0.5)! +// } else { +// color = self.baseColor.color +// } + return self.baseColor.color } }