Skip to content

Commit 93eab36

Browse files
authored
fix(ChatUI): scroll to start of day on chat date indicator click before opening calendar (#118)
1 parent 7d39a1e commit 93eab36

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎packages/ChatUI/Sources/ChatUI/ChatController.swift‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4574,7 +4574,9 @@ open class ChatController<Context: AccountContextProtocol>: TelegramGenericViewC
45744574
guard let strongSelf, strongSelf.messageFocusRequestId == requestId,
45754575
strongSelf.chatLocation == chatLocation, strongSelf.locationValue?.tag == locationTag else { return }
45764576
if let messageId = messageId {
4577-
strongSelf.chatInteraction.focusMessageId(nil, .init(messageId: messageId, string: nil), .top(id: 0, innerId: nil, animated: true, focus: .init(focus: false), inset: 30))
4577+
let topInset = strongSelf.genericView.tableView.contentInsets.top
4578+
let inset: CGFloat = topInset + 30 + 10
4579+
strongSelf.chatInteraction.focusMessageId(nil, .init(messageId: messageId, string: nil), .top(id: 0, innerId: nil, animated: true, focus: .init(focus: false), inset: inset))
45784580
}
45794581
}))
45804582
case .scheduled:
@@ -4594,7 +4596,9 @@ open class ChatController<Context: AccountContextProtocol>: TelegramGenericViewC
45944596
return true
45954597
})
45964598
if let targetItem {
4597-
strongSelf.genericView.tableView.scroll(to: .top(id: targetItem.stableId, innerId: nil, animated: true, focus: .init(focus: false), inset: 30))
4599+
let topInset = strongSelf.genericView.tableView.contentInsets.top
4600+
let inset: CGFloat = topInset + 30 + 10
4601+
strongSelf.genericView.tableView.scroll(to: .top(id: targetItem.stableId, innerId: nil, animated: true, focus: .init(focus: false), inset: inset))
45984602
}
45994603
case .pinned:
46004604
break

‎packages/ChatUI/Sources/ChatUI/ChatMessageDateHeader.swift‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,31 @@ public class ChatDateStickView : TableStickView {
241241

242242
containerView.set(handler: { [weak self] _ in
243243
guard let self, let item = self.item as? ChatDateStickItem, let interaction = item.chatInteraction else { return }
244+
var ignore: Bool = false
245+
let table = item.table ?? (self.superview as? TableView)
246+
if let table {
247+
let row = table.visibleRows()
248+
if row.length > 0 {
249+
let minRow = max(0, row.location)
250+
let maxRow = min(table.count - 1, row.location + row.length - 1)
251+
for i in minRow ... maxRow {
252+
if let underItem = table.item(at: i) as? ChatDateStickItem, underItem.timestamp == item.timestamp {
253+
ignore = true
254+
break
255+
}
256+
}
257+
}
258+
}
259+
if self.header && !ignore {
260+
self.cancelCount()
261+
if let location = item.messageCountLocation, case let .peer(_, _, _, _, _, minDate?, _) = location {
262+
interaction.jumpToDate(Date(timeIntervalSince1970: TimeInterval(minDate)))
263+
} else {
264+
let timeDifference = interaction.mode == .scheduled ? 0 : interaction.interactionContext.timeDifference
265+
interaction.jumpToDate(Date(timeIntervalSince1970: TimeInterval(item.timestamp) + timeDifference))
266+
}
267+
return
268+
}
244269
let canOpenCalendar: Bool
245270
switch interaction.mode {
246271
case .history, .thread:

0 commit comments

Comments
 (0)