Skip to content

Commit a32d90a

Browse files
Fixed an issue with reactions offset with a tabbar
1 parent 7fdc0a5 commit a32d90a

File tree

7 files changed

+118
-2
lines changed

7 files changed

+118
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
6060
onMessageAppear: viewModel.handleMessageAppear(index:),
6161
onScrollToBottom: viewModel.scrollToLastMessage,
6262
onLongPress: { displayInfo in
63+
messageDisplayInfo = displayInfo
6364
withAnimation {
64-
messageDisplayInfo = displayInfo
6565
viewModel.showReactionOverlay()
6666
}
6767
}
@@ -113,6 +113,7 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
113113
if messageDisplayInfo?.keyboardWasShown == true {
114114
becomeFirstResponder()
115115
}
116+
messageDisplayInfo = nil
116117
}, onActionExecuted: { actionInfo in
117118
viewModel.messageActionExecuted(actionInfo)
118119
}
@@ -152,10 +153,14 @@ public struct ChatChannelView<Factory: ViewFactory>: View, KeyboardReadable {
152153
.allowsHitTesting(false)
153154
: nil
154155
)
155-
.padding(.bottom, keyboardShown || !tabBarAvailable ? 0 : bottomPadding)
156+
.padding(.bottom, keyboardShown || !tabBarAvailable || generatingSnapshot ? 0 : bottomPadding)
156157
.ignoresSafeArea(.container, edges: tabBarAvailable ? .bottom : [])
157158
}
158159

160+
private var generatingSnapshot: Bool {
161+
tabBarAvailable && messageDisplayInfo != nil && !viewModel.reactionsShown
162+
}
163+
159164
private var bottomPadding: CGFloat {
160165
let bottomPadding = topVC()?.view.safeAreaInsets.bottom ?? 0
161166
return bottomPadding

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListHelperViews.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public struct MessageAuthorAndDateView: View {
2121
public var body: some View {
2222
HStack {
2323
Text(utils.messageCachingUtils.authorName(for: message))
24+
.lineLimit(1)
2425
.font(fonts.footnoteBold)
2526
.foregroundColor(Color(colors.textLowEmphasis))
2627
if utils.messageListConfig.messageDisplayOptions.showMessageDate {

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
847BA08927E0BAEE00ED20C7 /* WebSocketEngineMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BA08827E0BAEE00ED20C7 /* WebSocketEngineMock.swift */; };
189189
847CEFEC27BFAB6400606257 /* StreamChat in Frameworks */ = {isa = PBXBuildFile; productRef = 847CEFEB27BFAB6400606257 /* StreamChat */; };
190190
847CEFEE27C38ABE00606257 /* MessageCachingUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847CEFED27C38ABE00606257 /* MessageCachingUtils.swift */; };
191+
847F7949282A91AD0009F74C /* ChatChannelView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847F7948282A91AD0009F74C /* ChatChannelView_Tests.swift */; };
191192
848399EA275FB3E9003075E4 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 848399E9275FB3E9003075E4 /* SnapshotTesting */; };
192193
848399EC275FB41B003075E4 /* ChatChannelListView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */; };
193194
848399F227601231003075E4 /* ReactionsOverlayView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */; };
@@ -550,6 +551,7 @@
550551
847BA08627E0BACB00ED20C7 /* WebSocketPingControllerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketPingControllerMock.swift; sourceTree = "<group>"; };
551552
847BA08827E0BAEE00ED20C7 /* WebSocketEngineMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketEngineMock.swift; sourceTree = "<group>"; };
552553
847CEFED27C38ABE00606257 /* MessageCachingUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCachingUtils.swift; sourceTree = "<group>"; };
554+
847F7948282A91AD0009F74C /* ChatChannelView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelView_Tests.swift; sourceTree = "<group>"; };
553555
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelListView_Tests.swift; sourceTree = "<group>"; };
554556
848399F127601231003075E4 /* ReactionsOverlayView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsOverlayView_Tests.swift; sourceTree = "<group>"; };
555557
8492974727ABD97F00A8EEB0 /* DemoAppSwiftUI.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DemoAppSwiftUI.entitlements; sourceTree = "<group>"; };
@@ -1328,6 +1330,7 @@
13281330
84C94D482758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift */,
13291331
84C2042227917B6A0024D616 /* MessageListView_Tests.swift */,
13301332
84C94D4C2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift */,
1333+
847F7948282A91AD0009F74C /* ChatChannelView_Tests.swift */,
13311334
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
13321335
84C94D57275A1B89007FE2B9 /* MessageTypeResolver_Tests.swift */,
13331336
84C94D65275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift */,
@@ -1817,6 +1820,7 @@
18171820
842383E02767394200888CFC /* ChatChannelDataSource_Tests.swift in Sources */,
18181821
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */,
18191822
84C94CDA27578B92007FE2B9 /* ChatUser_Mock.swift in Sources */,
1823+
847F7949282A91AD0009F74C /* ChatChannelView_Tests.swift in Sources */,
18201824
84C94D2C275796F7007FE2B9 /* RequestRecorderURLProtocol.swift in Sources */,
18211825
84C94CD627578B92007FE2B9 /* AttachmentUploadingState_Mock.swift in Sources */,
18221826
84C94D20275792EA007FE2B9 /* MockBackgroundTaskScheduler.swift in Sources */,
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
@testable import SnapshotTesting
6+
@testable import StreamChat
7+
@testable import StreamChatSwiftUI
8+
import SwiftUI
9+
import XCTest
10+
11+
class ChatChannelView_Tests: StreamChatTestCase {
12+
13+
func test_chatChannelView_snapshot() {
14+
// Given
15+
let controller = ChatChannelController_Mock(
16+
channelQuery: .init(cid: .unique),
17+
channelListQuery: nil,
18+
client: chatClient
19+
)
20+
let mockChannel = ChatChannel.mock(cid: .unique, name: "Test channel")
21+
var messages = [ChatMessage]()
22+
for i in 0..<15 {
23+
messages.append(
24+
ChatMessage.mock(
25+
id: .unique,
26+
cid: mockChannel.cid,
27+
text: "Test \(i)",
28+
author: .mock(id: .unique, name: "Martin")
29+
)
30+
)
31+
}
32+
controller.simulateInitial(channel: mockChannel, messages: messages, state: .remoteDataFetched)
33+
34+
// When
35+
let view = NavigationView {
36+
ScrollView {
37+
ChatChannelView(
38+
viewFactory: DefaultViewFactory.shared,
39+
channelController: controller
40+
)
41+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height - 64)
42+
}
43+
.navigationBarTitleDisplayMode(.inline)
44+
}
45+
.applyDefaultSize()
46+
47+
// Then
48+
assertSnapshot(matching: view, as: .image)
49+
}
50+
51+
func test_chatChannelView_snapshotEmpty() {
52+
// Given
53+
let controller = ChatChannelController_Mock(
54+
channelQuery: .init(cid: .unique),
55+
channelListQuery: nil,
56+
client: chatClient
57+
)
58+
let messages = [ChatMessage]()
59+
controller.simulateInitial(
60+
channel: .mock(cid: .unique, name: "Test channel"),
61+
messages: messages,
62+
state: .remoteDataFetched
63+
)
64+
65+
// When
66+
let view = NavigationView {
67+
ScrollView {
68+
ChatChannelView(
69+
viewFactory: DefaultViewFactory.shared,
70+
channelController: controller
71+
)
72+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height - 64)
73+
}
74+
.navigationBarTitleDisplayMode(.inline)
75+
}
76+
.applyDefaultSize()
77+
78+
// Then
79+
assertSnapshot(matching: view, as: .image)
80+
}
81+
82+
func test_chatChannelView_snapshotLoading() {
83+
// Given
84+
let controller = ChatChannelController_Mock(
85+
channelQuery: .init(cid: .unique),
86+
channelListQuery: nil,
87+
client: chatClient
88+
)
89+
90+
// When
91+
let view = NavigationView {
92+
ScrollView {
93+
ChatChannelView(
94+
viewFactory: DefaultViewFactory.shared,
95+
channelController: controller
96+
)
97+
.frame(width: defaultScreenSize.width, height: defaultScreenSize.height - 64)
98+
}
99+
.navigationBarTitleDisplayMode(.inline)
100+
}
101+
.applyDefaultSize()
102+
103+
// Then
104+
assertSnapshot(matching: view, as: .image)
105+
}
106+
}
256 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)