Skip to content

Commit f5a17fa

Browse files
authored
Send a large reaction on the first hold in the reactions window (#87)
Holding an emoji in the full reactions window did nothing the first time it was used: while the hold ran, the row was rebuilt with fresh item data, and the check that the cursor was still on the same emoji compared the whole item, so it failed. The hold now matches the emoji by its file and position.
1 parent 5b22e3c commit f5a17fa

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎packages/EntertainmentUI/Sources/EntertainmentUI/EmojiesSectionRowItem.swift‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ import InlineStickerLayer
2121

2222
private let largeReactionHoldDuration: Double = 0.8
2323

24+
private func isSameEmojiEntry(_ lhs: EmojiesSectionRowItem.Item?, _ rhs: EmojiesSectionRowItem.Item?) -> Bool {
25+
guard let lhs, let rhs, lhs.rect == rhs.rect else {
26+
return false
27+
}
28+
switch (lhs, rhs) {
29+
case let (.item(_, lhsItem, _, _), .item(_, rhsItem, _, _)):
30+
return lhsItem.file.fileId == rhsItem.file.fileId
31+
case (.more, .more):
32+
return true
33+
default:
34+
return false
35+
}
36+
}
37+
2438
public final class EmojiesSectionRowItem : GeneralRowItem {
2539

2640
public enum Item : Equatable {
@@ -633,7 +647,7 @@ private final class EmojiesSectionRowView : TableRowView, ModalPreviewRowViewPro
633647
return
634648
}
635649
self.largeHoldTimer = nil
636-
if self.itemUnderMouse?.1 == current.1, let sticker = current.1.item, let window = self.window, let item = self.item as? EmojiesSectionRowItem {
650+
if isSameEmojiEntry(self.itemUnderMouse?.1, current.1), let sticker = current.1.item, let window = self.window, let item = self.item as? EmojiesSectionRowItem {
637651
self.largeInvoked = true
638652
let wrect = self.contentView.convert(current.1.rect, to: nil)
639653
let srect = window.convertToScreen(wrect)
@@ -670,7 +684,7 @@ private final class EmojiesSectionRowView : TableRowView, ModalPreviewRowViewPro
670684
}
671685
private func updateDragging() {
672686
if largeHoldTimer != nil {
673-
if self.itemUnderMouse?.1 != self.currentDownItem?.1 {
687+
if !isSameEmojiEntry(self.itemUnderMouse?.1, self.currentDownItem?.1) {
674688
cancelLargeHold()
675689
self.currentDownItem = nil
676690
}
@@ -708,7 +722,7 @@ private final class EmojiesSectionRowView : TableRowView, ModalPreviewRowViewPro
708722
}
709723
if largeHoldTimer != nil {
710724
cancelLargeHold()
711-
if self.currentDownItem?.1 == self.itemUnderMouse?.1 {
725+
if isSameEmojiEntry(self.currentDownItem?.1, self.itemUnderMouse?.1) {
712726
self.click()
713727
}
714728
self.currentDownItem = nil

0 commit comments

Comments
 (0)