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.
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.
The default controllers, such as the 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 TagFilterListController 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 we require a reload of the list view.
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 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
Report incorrect code
Copy
struct ContentView: View { @ObservedObject var filterListController: FilterListObservableController<Filter.Tag> var body: some View { FilterList(filterListController) { filter, isSelected in // declare the view presenting a single tag filter and its selection state HStack { Text(filter.value.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 tag filters, you can directly use the 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.