Skip to content

Commit a14440b

Browse files
Fixed reaction overlay display in a modal chat view
1 parent e186962 commit a14440b

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
### 🐞 Fixed
7+
- Reaction overlay display in a modal chat view
78

89
# [4.30.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.30.0)
910
_March 30, 2023_

Sources/StreamChatSwiftUI/ChatChannel/Reactions/ReactionsOverlayView.swift

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import SwiftUI
77

88
public struct ReactionsOverlayView<Factory: ViewFactory>: View {
99
@Injected(\.utils) private var utils
10-
10+
@Injected(\.colors) private var colors
11+
1112
@StateObject var viewModel: ReactionsOverlayViewModel
1213

1314
@State private var popIn = false
1415
@State private var willPopOut = false
16+
@State private var screenHeight = UIScreen.main.bounds.size.height
1517

1618
var factory: Factory
1719
var channel: ChatChannel
@@ -23,7 +25,9 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
2325
private var messageActionsCount: Int
2426
private let paddingValue: CGFloat = 16
2527
private let messageItemSize: CGFloat = 40
26-
private let maxMessageActionsSize: CGFloat = UIScreen.main.bounds.size.height / 3
28+
private var maxMessageActionsSize: CGFloat {
29+
screenHeight / 3
30+
}
2731

2832
public init(
2933
factory: Factory,
@@ -58,6 +62,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
5862
currentSnapshot: currentSnapshot,
5963
popInAnimationInProgress: !popIn
6064
)
65+
.offset(y: spacing > 0 ? screenHeight - currentSnapshot.size.height : 0)
6166
.transition(.opacity)
6267
.onTapGesture {
6368
dismissReactionsOverlay() { /* No additional handling. */ }
@@ -80,6 +85,9 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
8085
}
8186

8287
GeometryReader { reader in
88+
let frame = reader.frame(in: .local)
89+
let height = frame.height
90+
Color.clear.preference(key: HeightPreferenceKey.self, value: height)
8391
VStack(alignment: .leading) {
8492
Group {
8593
if messageDisplayInfo.frame.height > messageContainerHeight {
@@ -170,10 +178,16 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
170178
.animation(willPopOut ? .easeInOut : popInAnimation, value: popIn)
171179
}
172180
}
173-
.offset(y: !popIn ? messageDisplayInfo.frame.origin.y : originY)
181+
.offset(y: !popIn ? (messageDisplayInfo.frame.origin.y - spacing) : originY)
182+
}
183+
}
184+
.onPreferenceChange(HeightPreferenceKey.self) { value in
185+
if let value = value, value != screenHeight {
186+
self.screenHeight = value
174187
}
175188
}
176189
.edgesIgnoringSafeArea(.all)
190+
.background(Color(colors.background))
177191
.onAppear {
178192
popIn = true
179193
}
@@ -205,7 +219,6 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
205219
}
206220

207221
private var messageContainerHeight: CGFloat {
208-
let screenHeight = UIScreen.main.bounds.size.height
209222
let maxAllowed = screenHeight / 2
210223
let containerHeight = messageDisplayInfo.frame.height
211224
return containerHeight > maxAllowed ? maxAllowed : containerHeight
@@ -228,16 +241,21 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
228241
let bottomPopupOffset =
229242
messageDisplayInfo.showsMessageActions ? messageActionsSize : userReactionsPopupHeight
230243
var originY = messageDisplayInfo.frame.origin.y
231-
let screenHeight = UIScreen.main.bounds.size.height
232244
let minOrigin: CGFloat = 100
233245
let maxOrigin: CGFloat = screenHeight - messageContainerHeight - bottomPopupOffset - minOrigin
234246
if originY < minOrigin {
235247
originY = minOrigin
236248
} else if originY > maxOrigin {
237249
originY = maxOrigin
238250
}
239-
240-
return originY
251+
252+
return originY - spacing
253+
}
254+
255+
private var spacing: CGFloat {
256+
let divider: CGFloat = isIPad ? 2 : 1
257+
let spacing = (UIScreen.main.bounds.height - screenHeight) / divider
258+
return spacing > 0 ? spacing : 0
241259
}
242260

243261
private var messageActionsSize: CGFloat {

StreamChatSwiftUITests/Tests/ChatChannel/ReactionsOverlayView_Tests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import SwiftUI
99
import XCTest
1010

1111
class ReactionsOverlayView_Tests: StreamChatTestCase {
12+
13+
private static let screenSize = CGSize(width: 393, height: 852)
1214

1315
private let testMessage = ChatMessage.mock(
1416
id: "test",
@@ -27,7 +29,7 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
2729
private let overlayImage = UIColor
2830
.black
2931
.withAlphaComponent(0.2)
30-
.image(defaultScreenSize)
32+
.image(screenSize)
3133

3234
func test_reactionsOverlayView_snapshot() {
3335
// Given
@@ -40,7 +42,6 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
4042
onBackgroundTap: {},
4143
onActionExecuted: { _ in }
4244
)
43-
.applyDefaultSize()
4445
}
4546

4647
// Then
@@ -60,7 +61,6 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
6061
onBackgroundTap: {},
6162
onActionExecuted: { _ in }
6263
)
63-
.applyDefaultSize()
6464
}
6565

6666
// Then
@@ -104,7 +104,6 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
104104
onBackgroundTap: {},
105105
onActionExecuted: { _ in }
106106
)
107-
.applyDefaultSize()
108107
}
109108

110109
// Then
@@ -141,7 +140,6 @@ class ReactionsOverlayView_Tests: StreamChatTestCase {
141140
onBackgroundTap: {},
142141
onActionExecuted: { _ in }
143142
)
144-
.applyDefaultSize()
145143
}
146144

147145
// Then
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)