Signature
About this widget
Filter Toggle
is a filtering component that displays any kind of filter, and lets users refine the search results by toggling it on or off.
Examples
Instantiate aFilterToggleConnector
and launch an initial search on its Searcher
.
Swift
Parameters
The
FilterState
that holds your filters.The Filter to toggle.
The logic applied to Filter Toggle.
Whether the filter is initially selected.
Whether the filter is added to a conjuncitve(
and
) or a disjuncitve (or
) group in the filter state.Defines the group name in which filter will be placed in
FilterState
.
If not specified, the name of the filter attribute will be used as a group name.The Controller interfacing with a concrete toggle filter view.
Low-level API
If you want to fully control theFilter Toggle
components and connect them manually, use the following components:
Swift
Customizing your view
The default controllers, such asFilterSwitchController
,
work well when you want to use native UIKit with their default behavior.
If you want to use another component such as a UIButton
,
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 SelectableController
protocol.
Protocol
var onClick: ((Bool) -> Void)?
:
Closure to call when a filter is toggled.
func setSelected(_ isSelected: Bool)
Function called when a selection state of filter is updated. This is the UI State of the toggle. Make sure to update your view here when you get the new selection state.
Example
Swift
SwiftUI
InstantSearch provides theFilterToggleObservableController
data model,
which is an implementation of the SelectableController
protocol adapted for usage with SwiftUI.
FilterToggleObservableController
must be connected to the FilterToggleConnector
or SelectableInteractor<Filter>
like any other SelectableController
implementation.
The example of the toggle filter view using the Toggle
component provided by SwiftUI.
Swift
FilterToggleObservableController
as a data model.
It provides filter
and isSelected
properties to streamline the design process of your custom SwiftUI view.