Clear Refinements
About this widget
Clear Refinements lets the user clear all refinements that are currently active within the given FilterState
.
To add clear refinements to your search experience, use these components:
FilterClearInteractor
: The logic for clearing refinements in theFilterState
.FilterState
: The current state of the filters.FilterClearController
: The controller that interfaces with a concrete clear refinement view.
Examples
1
2
3
4
5
6
7
8
9
10
let filterState: FilterState = .init()
let filterClearInteractor: FilterClearInteractor = .init()
let clearRefinementsController: FilterClearButtonController = .init(button: UIButton())
override func viewDidLoad() {
super.viewDidLoad()
filterClearInteractor.connectFilterState(filterState)
filterClearInteractor.connectController(clearRefinementsController)
}
Parameters
filterGroupIDs
|
type: [FilterGroup.ID]?
default: nil
Optional
The groupIDs of filters to clear. All filters will be cleared if unspecified. |
||
Copy
|
|||
clearMode
|
type: ClearMode
default: .specified
Optional
Whether we should clear the |
||
Copy
|
Customize your view
The controllers provided by default, like the FilterClearButtonController
work well when you want to use native UIKit with their default behavior.
If you want to use another component (other than a UIButton
) such as a UIView
, a third-party input view, or you want to introduce some custom behavior to the already provided UIKit component, you can create your own controller conforming to the FilterClearController
protocol.
Protocol
var onClick: ((Facet) -> Void)?
:
Closure to call when the clear refinements button is clicked.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class FilterClearButtonController: FilterClearController {
public let button: UIButton
public var onClick: (() -> Void)?
public init(button: UIButton) {
self.button = button
button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)
}
@objc private func didTapButton() {
onClick?()
}
}