diff --git a/CHANGELOG.md b/CHANGELOG.md index b464cc07c..555e413b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add support for customising the `MessageAvatarView` placeholder [#878](https://github.com/GetStream/stream-chat-swiftui/pull/878) - Add `ViewFactory.makeVideoPlayerFooterView` to customize video player footer [#879](https://github.com/GetStream/stream-chat-swiftui/pull/879) - Add `utils.channelListConfig.channelItemMutedLayoutStyle` [#881](https://github.com/GetStream/stream-chat-swiftui/pull/881) +- Add jumping to pinned message when tapping a message in the pinned messages view [#884](https://github.com/GetStream/stream-chat-swiftui/pull/884) + +### 🔄 Changed +- From now on, jumping to a message will centre it in the middle instead of at the top [#884](https://github.com/GetStream/stream-chat-swiftui/pull/884) # [4.81.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.81.0) _July 03, 2025_ diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesView.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesView.swift index e11fa4ff8..f9f47e4a9 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesView.swift @@ -8,10 +8,13 @@ import SwiftUI /// View displaying pinned messages in the chat info screen. public struct PinnedMessagesView: View { @Injected(\.images) private var images + @Injected(\.utils) private var utils + @Injected(\.chatClient) private var chatClient @StateObject private var viewModel: PinnedMessagesViewModel let factory: Factory + private let channel: ChatChannel public init( factory: Factory = DefaultViewFactory.shared, @@ -24,6 +27,7 @@ public struct PinnedMessagesView: View { channelController: channelController ) ) + self.channel = channel self.factory = factory } @@ -33,7 +37,27 @@ public struct PinnedMessagesView: View { ScrollView { LazyVStack(spacing: 0) { ForEach(viewModel.pinnedMessages) { message in - PinnedMessageView(factory: factory, message: message, channel: viewModel.channel) + ZStack { + PinnedMessageView(factory: factory, message: message, channel: viewModel.channel) + .contentShape(Rectangle()) + .onTapGesture { + viewModel.selectedMessage = message + } + NavigationLink( + tag: message, + selection: $viewModel.selectedMessage + ) { + LazyView( + makeMessageDestination(message: message) + .modifier(HideTabBarModifier( + handleTabBarVisibility: utils.messageListConfig.handleTabBarVisibility + )) + ) + } label: { + EmptyView() + } + .opacity(0) // Fixes showing accessibility button shape + } Divider() } } @@ -49,6 +73,26 @@ public struct PinnedMessagesView: View { } .navigationTitle(L10n.ChatInfo.PinnedMessages.title) } + + private func makeMessageDestination(message: ChatMessage) -> ChatChannelView { + let channelController = utils.channelControllerFactory + .makeChannelController(for: channel.cid) + + var messageController: ChatMessageController? + if let parentMessageId = message.parentMessageId { + messageController = chatClient.messageController( + cid: channel.cid, + messageId: parentMessageId + ) + } + + return ChatChannelView( + viewFactory: factory, + channelController: channelController, + messageController: messageController, + scrollToMessage: message + ) + } } struct PinnedMessageView: View { diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesViewModel.swift index 127ef3e05..78c787264 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/PinnedMessagesViewModel.swift @@ -11,7 +11,8 @@ public class PinnedMessagesViewModel: ObservableObject { let channel: ChatChannel @Published var pinnedMessages: [ChatMessage] - + @Published var selectedMessage: ChatMessage? + private var channelController: ChatChannelController? public init(channel: ChatChannel, channelController: ChatChannelController? = nil) { diff --git a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift index ab61e7ed5..0af97a836 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift @@ -24,7 +24,7 @@ public struct MessageListConfig { maxTimeIntervalBetweenMessagesInGroup: TimeInterval = 60, cacheSizeOnChatDismiss: Int = 1024 * 1024 * 100, iPadSplitViewEnabled: Bool = true, - scrollingAnchor: UnitPoint = .bottom, + scrollingAnchor: UnitPoint = .center, showNewMessagesSeparator: Bool = true, handleTabBarVisibility: Bool = true, messageListAlignment: MessageListAlignment = .standard,