Skip to content

Commit 1a6564a

Browse files
authored
Fix jumping to message highlight to be consistent with UIKit (#1036)
1 parent 9eae155 commit 1a6564a

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44
# Upcoming
55

66
### ✅ Added
7-
- Add message highlighting on jumping to a quoted message [#1032](https://github.com/GetStream/stream-chat-swiftui/pull/1030)
7+
- Add message highlighting on jumping to a quoted message [#1032](https://github.com/GetStream/stream-chat-swiftui/pull/1032)
88

99
### 🐞 Fixed
1010
- Fix composer deleting newly entered text after deleting draft text [#1030](https://github.com/GetStream/stream-chat-swiftui/pull/1030)

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
183183
}
184184
// Clear highlight after animation completes
185185
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { [weak self] in
186-
self?.highlightedMessageId = nil
186+
withAnimation {
187+
self?.highlightedMessageId = nil
188+
}
187189
}
188190
self?.messageCachingUtils.jumpToReplyId = nil
189191
} else if messageController == nil {
@@ -324,9 +326,11 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
324326
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [weak self] in
325327
self?.scrolledId = nil
326328
}
327-
// Clear highlight after animation completes (0.6s delay from StreamChatUI implementation)
329+
// Clear highlight after animation completes
328330
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { [weak self] in
329-
self?.highlightedMessageId = nil
331+
withAnimation {
332+
self?.highlightedMessageId = nil
333+
}
330334
}
331335
return true
332336
} else {
@@ -362,7 +366,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
362366
}
363367
// Clear highlight after animation completes
364368
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
365-
self?.highlightedMessageId = nil
369+
withAnimation {
370+
self?.highlightedMessageId = nil
371+
}
366372
}
367373
}
368374
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
287287
.padding(.top, isLast ? paddingValue : 0)
288288
.background(
289289
Group {
290-
if let highlightedMessageId = highlightedMessageId, highlightedMessageId == message.messageId {
290+
if utils.messageListConfig.highlightMessageWhenJumping,
291+
let highlightedMessageId = highlightedMessageId,
292+
highlightedMessageId == message.messageId {
291293
Color(colors.messageCellHighlightBackground)
292294
} else if messageViewModel.isPinned {
293295
Color(colors.pinnedBackground)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public struct MessageListConfig {
2626
iPadSplitViewEnabled: Bool = true,
2727
scrollingAnchor: UnitPoint = .center,
2828
showNewMessagesSeparator: Bool = true,
29+
highlightMessageWhenJumping: Bool = true,
2930
handleTabBarVisibility: Bool = true,
3031
messageListAlignment: MessageListAlignment = .standard,
3132
uniqueReactionsEnabled: Bool = false,
@@ -57,6 +58,7 @@ public struct MessageListConfig {
5758
self.iPadSplitViewEnabled = iPadSplitViewEnabled
5859
self.scrollingAnchor = scrollingAnchor
5960
self.showNewMessagesSeparator = showNewMessagesSeparator
61+
self.highlightMessageWhenJumping = highlightMessageWhenJumping
6062
self.handleTabBarVisibility = handleTabBarVisibility
6163
self.messageListAlignment = messageListAlignment
6264
self.uniqueReactionsEnabled = uniqueReactionsEnabled
@@ -121,6 +123,11 @@ public struct MessageListConfig {
121123

122124
/// A boolean value that determines if download action is shown for file attachments.
123125
public let downloadFileAttachmentsEnabled: Bool
126+
127+
/// Highlights the message background when jumping to a message.
128+
///
129+
/// By default it is enabled and it uses the color from `ColorPalette.messageCellHighlightBackground`.
130+
public let highlightMessageWhenJumping: Bool
124131
}
125132

126133
/// Contains information about the message paddings.

Sources/StreamChatSwiftUI/ColorPalette.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct ColorPalette {
5959
public var highlightedBackground: UIColor = .streamGrayGainsboro
6060
public var highlightedAccentBackground: UIColor = .streamAccentBlue
6161
public var highlightedAccentBackground1: UIColor = .streamBlueAlice
62-
public var pinnedBackground: UIColor = .streamHighlight
62+
public var pinnedBackground: UIColor = .streamYellowBackground
6363
public var messageCellHighlightBackground: UIColor = .streamYellowBackground
6464

6565
// MARK: - Borders and shadows
@@ -167,8 +167,7 @@ private extension UIColor {
167167
static let streamAccentGreen = mode(0x20e070, 0x20e070)
168168
static let streamGrayDisabledText = mode(0x72767e, 0x72767e)
169169
static let streamInnerBorder = mode(0xdbdde1, 0x272a30)
170-
static let streamHighlight = mode(0xfbf4dd, 0x333024)
171-
static let streamYellowBackground = mode(0xfff2a1, 0x4a3d00)
170+
static let streamYellowBackground = mode(0xfbf4dd, 0x333024)
172171
static let streamDisabled = mode(0xb4b7bb, 0x4c525c)
173172

174173
// Currently we are not using the correct shadow color from figma's color palette. This is to avoid
-54 Bytes
Loading

0 commit comments

Comments
 (0)