From a932749bda3b51065103f50bffa1b427f949641e Mon Sep 17 00:00:00 2001 From: jk234ert Date: Thu, 25 Feb 2021 17:40:11 +0800 Subject: [PATCH] chore: optimize the expand & scroll animation --- .../Scene/PickServer/PickServerViewController.swift | 11 ++++++----- .../PickServer/TableViewCell/PickServerCell.swift | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Mastodon/Scene/PickServer/PickServerViewController.swift b/Mastodon/Scene/PickServer/PickServerViewController.swift index d02276f3..ef87e814 100644 --- a/Mastodon/Scene/PickServer/PickServerViewController.swift +++ b/Mastodon/Scene/PickServer/PickServerViewController.swift @@ -384,11 +384,12 @@ extension PickServerViewController: PickServerCellDelegate { expandServerDomainSet.insert(server.domain) } - tableView.performBatchUpdates(updates) { _ in - // Scroll to fully show the expanded cell, do not scroll when collapse - if newMode == .expand, let modeChangeIndex = self.viewModel.searchedServers.value.firstIndex(where: { $0 == server }), self.tableView.indexPathsForVisibleRows?.last?.row == modeChangeIndex { - self.tableView.scrollToRow(at: IndexPath(row: modeChangeIndex, section: 3), at: .bottom, animated: true) - } + tableView.beginUpdates() + updates() + tableView.endUpdates() + + if newMode == .expand, let modeChangeIndex = self.viewModel.searchedServers.value.firstIndex(where: { $0 == server }), self.tableView.indexPathsForVisibleRows?.last?.row == modeChangeIndex { + self.tableView.scrollToRow(at: IndexPath(row: modeChangeIndex, section: 3), at: .bottom, animated: true) } } } diff --git a/Mastodon/Scene/PickServer/TableViewCell/PickServerCell.swift b/Mastodon/Scene/PickServer/TableViewCell/PickServerCell.swift index a6a330ce..c9ff335d 100644 --- a/Mastodon/Scene/PickServer/TableViewCell/PickServerCell.swift +++ b/Mastodon/Scene/PickServer/TableViewCell/PickServerCell.swift @@ -249,12 +249,12 @@ extension PickServerCell { // Set expandBox constraints expandBox.leadingAnchor.constraint(equalTo: bgView.leadingAnchor, constant: 16), bgView.trailingAnchor.constraint(equalTo: expandBox.trailingAnchor, constant: 16), - expandBox.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: 8), - expandBox.bottomAnchor.constraint(equalTo: infoStackView.bottomAnchor), + expandBox.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: 8).priority(.defaultHigh), + expandBox.bottomAnchor.constraint(equalTo: infoStackView.bottomAnchor).priority(.defaultHigh), thumbImageView.leadingAnchor.constraint(equalTo: expandBox.leadingAnchor), expandBox.trailingAnchor.constraint(equalTo: thumbImageView.trailingAnchor), - thumbImageView.topAnchor.constraint(equalTo: expandBox.topAnchor), + thumbImageView.topAnchor.constraint(equalTo: expandBox.topAnchor).priority(.defaultHigh), thumbImageView.heightAnchor.constraint(equalTo: thumbImageView.widthAnchor, multiplier: 151.0 / 303.0).priority(.defaultHigh), infoStackView.leadingAnchor.constraint(equalTo: expandBox.leadingAnchor),