Skip to content

Commit 88d1c11

Browse files
committed
Add option to trigger reloading UI for search view controller
1 parent 12f3454 commit 88d1c11

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

WooCommerce/Classes/ViewRelated/Search/SearchUICommand.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Combine
12
import UIKit
23
import Yosemite
34

@@ -35,6 +36,9 @@ protocol SearchUICommand {
3536
///
3637
var adjustTableViewBottomInsetWhenKeyboardIsShown: Bool { get }
3738

39+
/// Stream of UI reload request - necessary when the search list need to be refreshed manually.
40+
var reloadUIRequests: AnyPublisher<Void, Never> { get }
41+
3842
/// A closure to resynchronize models if the data source might change (e.g. when the filter changes in products search).
3943
/// Set externally to enable resyncing the models when needed. Otherwise, an empty closure can be set by default.
4044
var resynchronizeModels: (() -> Void) { get set }
@@ -182,6 +186,12 @@ extension SearchUICommand {
182186

183187
extension SearchUICommand {
184188

189+
/// Default value for the optional property
190+
///
191+
var reloadUIRequests: AnyPublisher<Void, Never> {
192+
Empty<Void, Never>().eraseToAnyPublisher()
193+
}
194+
185195
/// Creates an instance of `EmptySearchResultsViewController`
186196
///
187197
func createEmptyStateViewController() -> EmptyStateViewController {

WooCommerce/Classes/ViewRelated/Search/SearchViewController.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ where Cell.SearchModel == Command.CellViewModel {
158158
configureResultsController()
159159
configureStarterViewController()
160160
configureSearchResync()
161+
configureUIReload()
161162
observeSelectedObjectAndDataLoadedStateToUpdateSelectedRow()
162163

163164
if searchUICommand.adjustTableViewBottomInsetWhenKeyboardIsShown {
@@ -443,6 +444,14 @@ private extension SearchViewController {
443444
}
444445
}
445446

447+
func configureUIReload() {
448+
searchUICommand.reloadUIRequests
449+
.sink { [weak self] in
450+
self?.tableView.reloadData()
451+
}
452+
.store(in: &subscriptions)
453+
}
454+
446455
func observeSelectedObjectAndDataLoadedStateToUpdateSelectedRow() {
447456
guard let selectedObject else {
448457
return

0 commit comments

Comments
 (0)