diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift index 822c9739..205e8102 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewController.swift @@ -47,6 +47,10 @@ class CollectiblesCollectionsViewController: UIViewController, UICollectionViewD case .success: //self?.hideLoadingView(completion: nil) if self?.refreshingFromParent == true || self?.viewModel.needsLayoutChange == true { + if self?.viewModel.isSearching == false { + self?.clearSearchTextField() + } + self?.collectionView.collectionViewLayout = self?.viewModel.layout() ?? UICollectionViewFlowLayout() self?.collectionView.contentOffset = CGPoint(x: 0, y: 0) self?.refreshingFromParent = false @@ -219,14 +223,7 @@ extension CollectiblesCollectionsViewController: ValidatorTextFieldDelegate { private func hideSearchingUI() { self.viewModel.isSearching = false - - let searchCell = collectionView.cellForItem(at: IndexPath(row: 0, section: 0)) as? CollectiblesSearchCell - searchCell?.searchBar.text = "" - searchCell?.cancelButton.isHidden = true - - UIView.animate(withDuration: 0.3) { - searchCell?.contentView.layoutIfNeeded() - } + self.clearSearchTextField() viewModel.endSearching(forColelctionView: self.collectionView, completion: {}) @@ -245,4 +242,14 @@ extension CollectiblesCollectionsViewController: ValidatorTextFieldDelegate { } */ } + + private func clearSearchTextField() { + let searchCell = collectionView.cellForItem(at: IndexPath(row: 0, section: 0)) as? CollectiblesSearchCell + searchCell?.searchBar.text = "" + searchCell?.cancelButton.isHidden = true + + UIView.animate(withDuration: 0.3) { + searchCell?.contentView.layoutIfNeeded() + } + } } diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift index 0746b144..944ba825 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesCollectionsViewModel.swift @@ -58,6 +58,9 @@ class CollectiblesCollectionsViewModel: ViewModel, UICollectionViewDiffableDataS .sink { [weak self] address in if DependencyManager.shared.selectedWalletAddress == address { self?.forceRefresh = true + self?.isSearching = false + self?.needsLayoutChange = true + if self?.isVisible == true { self?.refresh(animate: true) }