@@ -7,11 +7,13 @@ import SwiftUI
7
7
8
8
public struct ReactionsOverlayView < Factory: ViewFactory > : View {
9
9
@Injected ( \. utils) private var utils
10
-
10
+ @Injected ( \. colors) private var colors
11
+
11
12
@StateObject var viewModel : ReactionsOverlayViewModel
12
13
13
14
@State private var popIn = false
14
15
@State private var willPopOut = false
16
+ @State private var screenHeight = UIScreen . main. bounds. size. height
15
17
16
18
var factory : Factory
17
19
var channel : ChatChannel
@@ -23,7 +25,9 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
23
25
private var messageActionsCount : Int
24
26
private let paddingValue : CGFloat = 16
25
27
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
+ }
27
31
28
32
public init (
29
33
factory: Factory ,
@@ -58,6 +62,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
58
62
currentSnapshot: currentSnapshot,
59
63
popInAnimationInProgress: !popIn
60
64
)
65
+ . offset ( y: spacing > 0 ? screenHeight - currentSnapshot. size. height : 0 )
61
66
. transition ( . opacity)
62
67
. onTapGesture {
63
68
dismissReactionsOverlay ( ) { /* No additional handling. */ }
@@ -80,6 +85,9 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
80
85
}
81
86
82
87
GeometryReader { reader in
88
+ let frame = reader. frame ( in: . local)
89
+ let height = frame. height
90
+ Color . clear. preference ( key: HeightPreferenceKey . self, value: height)
83
91
VStack ( alignment: . leading) {
84
92
Group {
85
93
if messageDisplayInfo. frame. height > messageContainerHeight {
@@ -170,10 +178,16 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
170
178
. animation ( willPopOut ? . easeInOut : popInAnimation, value: popIn)
171
179
}
172
180
}
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
174
187
}
175
188
}
176
189
. edgesIgnoringSafeArea ( . all)
190
+ . background ( Color ( colors. background) )
177
191
. onAppear {
178
192
popIn = true
179
193
}
@@ -205,7 +219,6 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
205
219
}
206
220
207
221
private var messageContainerHeight : CGFloat {
208
- let screenHeight = UIScreen . main. bounds. size. height
209
222
let maxAllowed = screenHeight / 2
210
223
let containerHeight = messageDisplayInfo. frame. height
211
224
return containerHeight > maxAllowed ? maxAllowed : containerHeight
@@ -228,16 +241,21 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
228
241
let bottomPopupOffset =
229
242
messageDisplayInfo. showsMessageActions ? messageActionsSize : userReactionsPopupHeight
230
243
var originY = messageDisplayInfo. frame. origin. y
231
- let screenHeight = UIScreen . main. bounds. size. height
232
244
let minOrigin : CGFloat = 100
233
245
let maxOrigin : CGFloat = screenHeight - messageContainerHeight - bottomPopupOffset - minOrigin
234
246
if originY < minOrigin {
235
247
originY = minOrigin
236
248
} else if originY > maxOrigin {
237
249
originY = maxOrigin
238
250
}
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
241
259
}
242
260
243
261
private var messageActionsSize : CGFloat {
0 commit comments