From 46332cd1b9dc6a3029bc730faddd2e7d1fc62e36 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 11 May 2022 19:12:28 -0400 Subject: [PATCH] Jump to statuses below parent when expanding subthread in conversation --- .../ConversationTableViewController.swift | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Conversation/ConversationTableViewController.swift b/Tusker/Screens/Conversation/ConversationTableViewController.swift index 3c8f3e7c..1c68550b 100644 --- a/Tusker/Screens/Conversation/ConversationTableViewController.swift +++ b/Tusker/Screens/Conversation/ConversationTableViewController.swift @@ -31,6 +31,7 @@ class ConversationTableViewController: EnhancedTableViewController { let mainStatusID: String let mainStatusState: StatusState + var statusIDToScrollToOnLoad: String private(set) var dataSource: UITableViewDiffableDataSource! var showStatusesAutomatically = false @@ -41,6 +42,7 @@ class ConversationTableViewController: EnhancedTableViewController { init(for mainStatusID: String, state: StatusState = .unknown, mastodonController: MastodonController) { self.mainStatusID = mainStatusID self.mainStatusState = state + self.statusIDToScrollToOnLoad = mainStatusID self.mastodonController = mastodonController super.init(style: .plain) @@ -227,10 +229,19 @@ class ConversationTableViewController: EnhancedTableViewController { } self.dataSource.apply(snapshot, animatingDifferences: false) { - // ensure that the main status is on-screen after newly loaded statuses are added + let item: Item + let position: UITableView.ScrollPosition + if self.statusIDToScrollToOnLoad == self.mainStatusID { + item = mainStatusItem + position = .middle + } else { + item = Item.status(id: self.statusIDToScrollToOnLoad, state: .unknown) + position = .top + } + // ensure that the status is on-screen after newly loaded statuses are added // todo: should this not happen if the user has already started scrolling (e.g. because the main status is very long)? - if let indexPath = self.dataSource.indexPath(for: mainStatusItem) { - self.tableView.scrollToRow(at: indexPath, at: .middle, animated: false) + if let indexPath = self.dataSource.indexPath(for: item) { + self.tableView.scrollToRow(at: indexPath, at: position, animated: false) } } @@ -339,9 +350,11 @@ class ConversationTableViewController: EnhancedTableViewController { // MARK: - Table view delegate override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if case .expandThread = dataSource.itemIdentifier(for: indexPath), + if case let .expandThread(childThreads: childThreads, inline: _) = dataSource.itemIdentifier(for: indexPath), case let .status(id: id, state: state) = dataSource.itemIdentifier(for: IndexPath(row: indexPath.row - 1, section: indexPath.section)) { - self.selected(status: id, state: state) + let conv = ConversationTableViewController(for: id, state: state, mastodonController: mastodonController) + conv.statusIDToScrollToOnLoad = childThreads.first!.status.id + show(conv) } else { super.tableView(tableView, didSelectRowAt: indexPath) }