iOS
Signature
Explore example code
Browse the Sort By example code on GitHub.
About this widget
This widget displays a list of indices, allowing a user to change the way hits are sorting (with replica indices). Another common use case for this widget is to let users switch between different indices. For this widget to work, you must define all indices that you pass down as options as replicas of the main .Examples
Instantiate aSortByConnector.
Swift
Parameters
The logic applied to the custom model.
The Controller interfacing with a concrete custom data view.
The Presenter defining how a model appears in the controller.
Presenter
The presenter that defines how to display an index, taking as input an
indexName and returning a string.Swift
Low-level API
If you want to fully control theSortBy components and connect them manually,
you can use the following components:
Searcher. TheSearcherthat handles your searches.SortByInteractor. The logic applied to the index sorting/switching.SelectableSegmentController. The controller that interfaces with a concrete index list.IndexPresenter. Optional. The presenter that converts an IndexName to a String output.
Swift
Customizing your view
The controllers provided by default, like theSelectIndexController work well when you want to use native UIKit with their default behavior like a UIAlertController.
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 SelectableSegmentController protocol.
Protocol
func setSelected(_ selected: Int?):
Function called when an index is selected, with the selected position.
func setItems(items: [Int: String])
Function called when a new array of indices is defined.
func reload()
Function called when a reload of the list view is required.
var onClick: ((Int) -> Void)?:
Closure to call when a new index is clicked.
Example
Swift
SwiftUI
InstantSearch provides theSelectableSegmentObservableController data model,
which is an implementation of the SelectableSegmentController protocol adapted for usage with SwiftUI.
SelectableSegmentObservableController must be connected to the SortByConnector or SelectableSegmentInteractor like any other StatsTextController implementation.
The example of the sort by view using the Menu component provided by SwiftUI.
Swift
SelectableSegmentObservableController as a data model.
It provides segmentsTitles and selectedSegmentIndex properties along with select function to streamline the design process of your custom SwiftUI view.