NumericFilterList is a filtering component that displays numeric filters and lets users refine the search results by selecting them.Compared to the RefinementList,
which takes its values from the search response facets, this widget displays numeric filters that you add yourself.
Whether we apply an and or or behavior to the filters in the filterState.For example if we have an or behavior,
the filter sent to Algolia will be _tags:promo OR color:green.
The default controllers, such as FilterListTableController,
work well when you want to use native UIKit with their default behavior.If you want to use another component such as a UICollectionView,
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 NumericFilterListController protocol.
var onClick: ((Filter.Numeric) -> Void)?:Closure to call when a filter is clicked.func setSelectableItems(selectableItems: [SelectableItem<Filter.Numeric>])Function called when a new array of selectable facets is updated. This is the UI State of the refinement list.func reload()Function called when the list view requires a reload.
InstantSearch provides the FilterList SwiftUI view which you can embed in your views.
It uses FilterListObservableController as a data model, which is an implementation of the SelectableListController protocol adapted for usage with SwiftUI.
FilterListObservableController must be connected to the NumericFilterListConnector or NumericFilterListInteractor like any other SelectableListController implementation.
You have to define the appearance of the view representing a single numeric filter and its selection state.
Swift
struct ContentView: View { @ObservedObject var filterListController: FilterListObservableController<Filter.Numeric> var body: some View { FilterList(filterListController) { filter, isSelected in // declare the view presenting a single numeric filter and its selection state HStack { Text(filter.description) Spacer() if isSelected { Image(systemName: "checkmark") .foregroundColor(.accentColor) } } .contentShape(Rectangle()) .frame(idealHeight: 44) .padding(.horizontal, 5) } }}
If you prefer to create a custom SwiftUI view that presents the list of numeric filters, you can directly use the FilterListObservableController<Filter.Numeric> as a data model.
It provides filters and selections properties along with toggle and isSelected functions to streamline the design process of your custom SwiftUI view.