Skip to content

Commit d3de7c4

Browse files
Updated the reactions animation
1 parent ff62fb3 commit d3de7c4

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
397397
}
398398

399399
var skipChanges = true
400+
var animateChanges = false
400401
for change in changes {
401402
switch change {
402403
case .insert(_, index: _),
@@ -407,6 +408,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
407408
message.messageId != messages[index.row].messageId
408409
|| message.type == .ephemeral {
409410
skipChanges = false
411+
if index.row < messages.count && message.reactionScoresId != messages[index.row].reactionScoresId {
412+
animateChanges = true
413+
}
410414
}
411415
default:
412416
skipChanges = false
@@ -417,7 +421,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
417421
return .skip
418422
}
419423

420-
return .notAnimated
424+
return animateChanges ? .animated : .notAnimated
421425
}
422426

423427
private func enableDateIndicator() {

Sources/StreamChatSwiftUI/ChatChannel/Reactions/ReactionsOverlayView.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
5959
.blur(radius: !popIn ? 0 : 4)
6060
.transition(.opacity)
6161
.onTapGesture {
62-
withAnimation {
63-
willPopOut = true
64-
popIn = false
65-
}
66-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
67-
onBackgroundTap()
68-
}
62+
dismissReactionsOverlay() { /* No additional handling. */ }
6963
}
7064
.edgesIgnoringSafeArea(.all)
7165
.alert(isPresented: $viewModel.errorShown) {
@@ -118,8 +112,9 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
118112
message: viewModel.message,
119113
contentRect: messageDisplayInfo.frame,
120114
onReactionTap: { reaction in
121-
viewModel.reactionTapped(reaction)
122-
onBackgroundTap()
115+
dismissReactionsOverlay {
116+
viewModel.reactionTapped(reaction)
117+
}
123118
}
124119
)
125120
.scaleEffect(popIn ? 1 : 0)
@@ -181,6 +176,17 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
181176
}
182177
}
183178

179+
private func dismissReactionsOverlay(completion: @escaping () -> Void) {
180+
withAnimation {
181+
willPopOut = true
182+
popIn = false
183+
}
184+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
185+
onBackgroundTap()
186+
completion()
187+
}
188+
}
189+
184190
private func messageActionsOffsetX(reader: GeometryProxy) -> CGFloat {
185191
let originX = messageActionsOriginX(availableWidth: reader.size.width)
186192
let sentByCurrentUser = messageDisplayInfo.message.isSentByCurrentUser

0 commit comments

Comments
 (0)