@@ -7,11 +7,13 @@ import SwiftUI
77
88public 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 {
0 commit comments