diff --git a/CHANGELOG.md b/CHANGELOG.md index d2342e94..3448f84b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). # Upcoming ### ✅ Added -- Add message highlighting on jumping to a quoted message [#1032](https://github.com/GetStream/stream-chat-swiftui/pull/1030) +- Add message highlighting on jumping to a quoted message [#1032](https://github.com/GetStream/stream-chat-swiftui/pull/1032) ### 🐞 Fixed - Fix composer deleting newly entered text after deleting draft text [#1030](https://github.com/GetStream/stream-chat-swiftui/pull/1030) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift index f37c6722..76185ec4 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift @@ -183,7 +183,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { } // Clear highlight after animation completes DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { [weak self] in - self?.highlightedMessageId = nil + withAnimation { + self?.highlightedMessageId = nil + } } self?.messageCachingUtils.jumpToReplyId = nil } else if messageController == nil { @@ -324,9 +326,11 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [weak self] in self?.scrolledId = nil } - // Clear highlight after animation completes (0.6s delay from StreamChatUI implementation) + // Clear highlight after animation completes DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { [weak self] in - self?.highlightedMessageId = nil + withAnimation { + self?.highlightedMessageId = nil + } } return true } else { @@ -362,7 +366,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { } // Clear highlight after animation completes DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { - self?.highlightedMessageId = nil + withAnimation { + self?.highlightedMessageId = nil + } } } } diff --git a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift index 656faf46..cf9324c9 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift @@ -287,7 +287,9 @@ public struct MessageContainerView: View { .padding(.top, isLast ? paddingValue : 0) .background( Group { - if let highlightedMessageId = highlightedMessageId, highlightedMessageId == message.messageId { + if utils.messageListConfig.highlightMessageWhenJumping, + let highlightedMessageId = highlightedMessageId, + highlightedMessageId == message.messageId { Color(colors.messageCellHighlightBackground) } else if messageViewModel.isPinned { Color(colors.pinnedBackground) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift index b03d8550..2339728d 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift @@ -26,6 +26,7 @@ public struct MessageListConfig { iPadSplitViewEnabled: Bool = true, scrollingAnchor: UnitPoint = .center, showNewMessagesSeparator: Bool = true, + highlightMessageWhenJumping: Bool = true, handleTabBarVisibility: Bool = true, messageListAlignment: MessageListAlignment = .standard, uniqueReactionsEnabled: Bool = false, @@ -57,6 +58,7 @@ public struct MessageListConfig { self.iPadSplitViewEnabled = iPadSplitViewEnabled self.scrollingAnchor = scrollingAnchor self.showNewMessagesSeparator = showNewMessagesSeparator + self.highlightMessageWhenJumping = highlightMessageWhenJumping self.handleTabBarVisibility = handleTabBarVisibility self.messageListAlignment = messageListAlignment self.uniqueReactionsEnabled = uniqueReactionsEnabled @@ -121,6 +123,11 @@ public struct MessageListConfig { /// A boolean value that determines if download action is shown for file attachments. public let downloadFileAttachmentsEnabled: Bool + + /// Highlights the message background when jumping to a message. + /// + /// By default it is enabled and it uses the color from `ColorPalette.messageCellHighlightBackground`. + public let highlightMessageWhenJumping: Bool } /// Contains information about the message paddings. diff --git a/Sources/StreamChatSwiftUI/ColorPalette.swift b/Sources/StreamChatSwiftUI/ColorPalette.swift index e38841bb..ec71b5ec 100644 --- a/Sources/StreamChatSwiftUI/ColorPalette.swift +++ b/Sources/StreamChatSwiftUI/ColorPalette.swift @@ -59,7 +59,7 @@ public struct ColorPalette { public var highlightedBackground: UIColor = .streamGrayGainsboro public var highlightedAccentBackground: UIColor = .streamAccentBlue public var highlightedAccentBackground1: UIColor = .streamBlueAlice - public var pinnedBackground: UIColor = .streamHighlight + public var pinnedBackground: UIColor = .streamYellowBackground public var messageCellHighlightBackground: UIColor = .streamYellowBackground // MARK: - Borders and shadows @@ -167,8 +167,7 @@ private extension UIColor { static let streamAccentGreen = mode(0x20e070, 0x20e070) static let streamGrayDisabledText = mode(0x72767e, 0x72767e) static let streamInnerBorder = mode(0xdbdde1, 0x272a30) - static let streamHighlight = mode(0xfbf4dd, 0x333024) - static let streamYellowBackground = mode(0xfff2a1, 0x4a3d00) + static let streamYellowBackground = mode(0xfbf4dd, 0x333024) static let streamDisabled = mode(0xb4b7bb, 0x4c525c) // Currently we are not using the correct shadow color from figma's color palette. This is to avoid diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/__Snapshots__/MessageContainerView_Tests/test_messageContainerHighlighted_snapshot.1.png b/StreamChatSwiftUITests/Tests/ChatChannel/__Snapshots__/MessageContainerView_Tests/test_messageContainerHighlighted_snapshot.1.png index d7de7e4b..fba36a54 100644 Binary files a/StreamChatSwiftUITests/Tests/ChatChannel/__Snapshots__/MessageContainerView_Tests/test_messageContainerHighlighted_snapshot.1.png and b/StreamChatSwiftUITests/Tests/ChatChannel/__Snapshots__/MessageContainerView_Tests/test_messageContainerHighlighted_snapshot.1.png differ