Signature
Explore example code
Browse the Filter List (Tag) example code on GitHub.
About this widget
TagFilterList is a filtering component that displays tag filters
and lets users refine the search results by selecting them.
Compared to the RefinementList,
which takes its values from the search response ,
this widget displays tag filters that you add yourself.
Examples
Instantiate aTagFilterListConnector and launch an initial search on its Searcher.
Swift
Parameters
[TagFilter]
required
default: []
The tag filters to display.
SelectionMode
default: .multiple
Whether a user can select
.single or .multiple values.FilterState
required
The
FilterState that holds your filters.RefinementOperator
required
Whether to apply an
and or or behavior to the filters in the filter state.For example with or, the filter sent to Algolia is _tags:promo OR color:green.String
required
Filter group name.
FilterListTableController<Filter.Tag>
default: nil
Controller interfacing with a concrete filter list view.
Low-level API
If you want to fully control theTagFilterList components and connect them manually, you can use the following components:
Searcher. TheSearcherthat handles your searches.FilterState. The current state of the filters.TagFilterListInteractor. The logic applied to the tag filters.FilterListController. The view that will render the tag filters.
Swift
Customizing your view
The default controllers, such as theFilterListTableController, 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 TagFilterListController protocol.
Protocol
var onClick: ((Filter.Tag) -> Void)?:
Closure to call when a filter is clicked.
func setSelectableItems(selectableItems: [SelectableItem<Filter.Tag>])
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.
Implementation example
Swift
SwiftUI
InstantSearch provides theFilterList 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 TagFilterListConnector or TagFilterListInteractor like any other SelectableListController implementation.
You have to define the appearance of the view representing a single tag filter and its selection state.
Swift
FilterListObservableController<Filter.Tag> 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.