Signature
About this widget
Virtual indices let you use relevant sort, a sorting mechanism that favors relevancy over the attribute you’re sorting on. TherelevantSort
widget displays the current search mode when searching in a virtual replica index,
and allows users to switch between relevant and regular sorting,
which is more exhaustive but can return less relevant results.
Examples
Instantiate aRelevantSortConnector
.
Swift
Parameters
The logic to toggle relevant Sort.
Controller that presents and can toggle the Relevant Sort priority state.
presenter
RelevantSortPresenter<Output> | RelevantSortTextualPresenter
required
default: DefaultPresenter.RelevantSort.present
Presenter transforming the Relevant sort priority state to its representation for a controller.
Presenter
RelevantSort Presenter
RelevantSortPresenter<Output> | RelevantSortTextualPresenter
default:"DefaultPresenter.RelevantSort.present"
required
Presenter transforming the relevant sort priority state to its representation for a controller.
Default presenter transforms relevant sort priority to
RelevantSortTextualRepresentation?
providing a tuple of string constants in English.Swift
Low-level API
If you want to fully control theRelevantSort
components and connect them manually,
you can use the following components:
Searcher
. TheSearcher
that handles your searches.RelevantSortInteractor
. Relevant sort priority toggling logic.RelevantSortController
. The controller that presents and toggles the Relevant sort priority state.RelevantSortPresenter<Output>
. Optional. Generic presenter transforming the Relevant Sort priority state to its representation for a controller.
Swift
Customizing your view
The controllers provided by default, like theButtonRelevantSortController
work well when you want to use native UIKit with their default behavior like a UIButton
.
If you want to use another component,
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 RelevantSortController
protocol.
Protocol
func setItem(_ item: RelevantSortTextualRepresentation?)
Function called when a new array of indices is defined.
var didToggle: (() -> Void)? { get set }
Closure triggered by the controller when the toggle happens (for example, toggle button clicked or switch control state changed)
Example
Swift
SwiftUI
InstantSearch provides theRelevantSortObservableController
data model,
which is an implementation of the RelevantSortController
protocol adapted for usage with SwiftUI.
RelevantSortObservableController
must be connected to the RelevantSortConnector
or RelevantSortInteractor
like any other RelevantSortController
implementation.
The example of the SwiftUI view presenting the relevant sort state.
Swift
RelevantSortObservableController
as a data model.
It provides the state
property along with the toggle
function to streamline the design process of your custom SwiftUI view.