Skip to content

Commit 9163837

Browse files
authored
Channel was sometimes marked as read on open (#593)
1 parent da9a7db commit 9163837

File tree

10 files changed

+83
-2
lines changed

10 files changed

+83
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99

1010
### 🐞 Fixed
1111
- Typing users did not update reliably in the message list [#591](https://github.com/GetStream/stream-chat-swiftui/pull/591)
12+
- Channel was sometimes marked as read when the first unread message was one of the first not visible messages [#593](https://github.com/GetStream/stream-chat-swiftui/pull/593)
1213

1314
# [4.62.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.62.0)
1415
_August 16, 2024_

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
202202
}
203203
.id(listId)
204204
}
205+
.delayedRendering()
205206
.modifier(factory.makeMessageListModifier())
206207
.modifier(ScrollTargetLayoutModifier(enabled: loadingNextMessages))
207208
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright © 2024 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import Foundation
6+
import SwiftUI
7+
8+
extension View {
9+
/// Delays rendering the content to the next run loop.
10+
///
11+
/// - Important: This is used to workaround `FB15010770` where pushing a `LazyVStack` to `NavigationStack` causes the `LazyVStack` to load views using the height of the `UIScreen.main`, not the destination height.
12+
func delayedRendering() -> some View {
13+
modifier(DelayedRenderingViewModifier())
14+
}
15+
}
16+
17+
struct DelayedRenderingViewModifier: ViewModifier {
18+
static var isEnabled = true
19+
@State private var canShowContent = Self.isEnabled ? false : true
20+
21+
func body(content: Content) -> some View {
22+
if canShowContent {
23+
content
24+
} else {
25+
Color.clear
26+
.onAppear {
27+
Task { @MainActor in
28+
canShowContent = true
29+
}
30+
}
31+
}
32+
}
33+
}

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
402C54482B6AAC0100672BFB /* StreamChatSwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; };
1111
402C54492B6AAC0100672BFB /* StreamChatSwiftUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
12+
4F077EF82C85E05700F06D83 /* DelayedRenderingViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */; };
1213
4F198FDD2C0480EC00148F49 /* Publisher+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */; };
1314
4F6D83352C0F05040098C298 /* PollCommentsViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6D83342C0F05040098C298 /* PollCommentsViewModel_Tests.swift */; };
1415
4F6D83512C1079A00098C298 /* AlertBannerViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6D83502C1079A00098C298 /* AlertBannerViewModifier.swift */; };
@@ -573,6 +574,7 @@
573574

574575
/* Begin PBXFileReference section */
575576
4A65451E274BA170003C5FA8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
577+
4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelayedRenderingViewModifier.swift; sourceTree = "<group>"; };
576578
4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+Extensions.swift"; sourceTree = "<group>"; };
577579
4F6D83342C0F05040098C298 /* PollCommentsViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollCommentsViewModel_Tests.swift; sourceTree = "<group>"; };
578580
4F6D83502C1079A00098C298 /* AlertBannerViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertBannerViewModifier.swift; sourceTree = "<group>"; };
@@ -1656,6 +1658,7 @@
16561658
children = (
16571659
8465FCFA2746A95600AF091E /* ActionItemView.swift */,
16581660
4F6D83502C1079A00098C298 /* AlertBannerViewModifier.swift */,
1661+
4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */,
16591662
84AB7B1C2771F4AA00631A10 /* DiscardButtonView.swift */,
16601663
84F2908D276B92A40045472D /* GalleryHeaderView.swift */,
16611664
8465FD4B2746A95600AF091E /* LoadingView.swift */,
@@ -2527,6 +2530,7 @@
25272530
82D64BCE2AD7E5B700C5C79E /* ImageViewExtensions.swift in Sources */,
25282531
8465FD8C2746A95700AF091E /* ImagePickerView.swift in Sources */,
25292532
82D64BFB2AD7E5B700C5C79E /* ImageProcessors+Composition.swift in Sources */,
2533+
4F077EF82C85E05700F06D83 /* DelayedRenderingViewModifier.swift in Sources */,
25302534
82D64BD32AD7E5B700C5C79E /* FrameStore.swift in Sources */,
25312535
8465FDB22746A95700AF091E /* InputTextView.swift in Sources */,
25322536
8465FDB32746A95700AF091E /* NSLayoutConstraint+Extensions.swift in Sources */,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewDateOverlay_Tests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class ChatChannelViewDateOverlay_Tests: StreamChatTestCase {
2424
messageListConfig: MessageListConfig(dateIndicatorPlacement: .messageList)
2525
)
2626
streamChat = StreamChat(chatClient: chatClient, utils: utils)
27+
DelayedRenderingViewModifier.isEnabled = false
28+
}
29+
30+
override func tearDown() {
31+
super.tearDown()
32+
DelayedRenderingViewModifier.isEnabled = true
2733
}
2834

2935
func test_chatChannelView_snapshot() {

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelView_Tests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class ChatChannelView_Tests: StreamChatTestCase {
1515
super.setUp()
1616
let utils = Utils(dateFormatter: EmptyDateFormatter())
1717
streamChat = StreamChat(chatClient: chatClient, utils: utils)
18+
DelayedRenderingViewModifier.isEnabled = false
19+
}
20+
21+
override func tearDown() {
22+
super.tearDown()
23+
DelayedRenderingViewModifier.isEnabled = true
1824
}
1925

2026
func test_chatChannelView_snapshot() {

StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewAvatars_Tests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import StreamSwiftTestHelpers
99
import XCTest
1010

1111
class MessageListViewAvatars_Tests: StreamChatTestCase {
12-
12+
override func setUp() {
13+
super.setUp()
14+
DelayedRenderingViewModifier.isEnabled = false
15+
}
16+
17+
override func tearDown() {
18+
super.tearDown()
19+
DelayedRenderingViewModifier.isEnabled = true
20+
}
21+
1322
func test_messageListView_defaultDMChannel() {
1423
// Given
1524
setupConfig(showAvatars: true, showAvatarsInGroups: nil)

StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewLastGroupHeader_Tests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class MessageListViewLastGroupHeader_Tests: StreamChatTestCase {
2121
let messageListConfig = MessageListConfig(messageDisplayOptions: messageDisplayOptions)
2222
let utils = Utils(messageListConfig: messageListConfig)
2323
streamChat = StreamChat(chatClient: chatClient, utils: utils)
24+
DelayedRenderingViewModifier.isEnabled = false
25+
}
26+
27+
override func tearDown() {
28+
super.tearDown()
29+
DelayedRenderingViewModifier.isEnabled = true
2430
}
2531

2632
func test_messageListView_headerOnTop() {

StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewNewMessages_Tests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ final class MessageListViewNewMessages_Tests: StreamChatTestCase {
1616
let messageListConfig = MessageListConfig(showNewMessagesSeparator: true)
1717
let utils = Utils(dateFormatter: EmptyDateFormatter(), messageListConfig: messageListConfig)
1818
streamChat = StreamChat(chatClient: chatClient, utils: utils)
19+
DelayedRenderingViewModifier.isEnabled = false
20+
}
21+
22+
override func tearDown() {
23+
super.tearDown()
24+
DelayedRenderingViewModifier.isEnabled = true
1925
}
2026

2127
func test_messageListViewNewMessages_singleMessage() {

StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ import SwiftUI
1010
import XCTest
1111

1212
class MessageListView_Tests: StreamChatTestCase {
13-
13+
override func setUp() {
14+
super.setUp()
15+
DelayedRenderingViewModifier.isEnabled = false
16+
}
17+
18+
override func tearDown() {
19+
super.tearDown()
20+
DelayedRenderingViewModifier.isEnabled = true
21+
}
22+
1423
func test_messageListView_withReactions() {
1524
// Given
1625
let channelConfig = ChannelConfig(reactionsEnabled: true)

0 commit comments

Comments
 (0)