From e37c7f7ebfd2e87704950c137036d1006ce18799 Mon Sep 17 00:00:00 2001 From: Ivan Grachev Date: Thu, 25 Aug 2022 15:10:46 +0300 Subject: [PATCH] Scroll to the first selected account on iOS --- .../Accounts/AccountsListViewController.swift | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift index 46c0928c..af1efdff 100644 --- a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift +++ b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift @@ -102,7 +102,6 @@ class AccountsListViewController: UIViewController, DataStateContainer { tableView.contentInset.bottom += bottomOverlayHeight tableView.contentInset.top += 70 tableView.verticalScrollIndicatorInsets.bottom += bottomOverlayHeight - // TODO: scroll to the first selected account in a list if !selectAccountAction.initiallyConnectedProviders.isEmpty { primaryButton.setTitle(Strings.ok, for: .normal) secondaryButton.setTitle(Strings.disconnect, for: .normal) @@ -128,7 +127,28 @@ class AccountsListViewController: UIViewController, DataStateContainer { self?.navigationController?.navigationBar.sizeToFit() if self?.initialContentOffset == nil { self?.initialContentOffset = self?.tableView.contentOffset.y - self?.tableView.scrollToNearestSelectedRow(at: .none, animated: false) + if let selectedAccounts = self?.selectAccountAction?.selectedAccounts { + self?.scrollToTheFirst(selectedAccounts) + } + } + } + } + + private func scrollToTheFirst(_ specificWalletAccounts: Set) { + for (sectionIndex, section) in sections.enumerated() { + for (row, cellModel) in section.items.enumerated() { + let account: SpecificWalletAccount + switch cellModel { + case let .mnemonicAccount(walletIndex, accountIndex): + account = SpecificWalletAccount(walletId: wallets[walletIndex].id, account: wallets[walletIndex].accounts[accountIndex]) + case let .privateKeyAccount(walletIndex): + account = SpecificWalletAccount(walletId: wallets[walletIndex].id, account: wallets[walletIndex].accounts[0]) + } + if specificWalletAccounts.contains(account) { + let indexPath = IndexPath(row: row, section: sectionIndex) + tableView.scrollToRow(at: indexPath, at: .none, animated: false) + return + } } } }