iOS
Signature
Explore example code
Browse the Filter Numeric Range example code on GitHub.
About this widget
Filter Numeric Range is a filtering component made to filter between two numeric values.
The most common interface for this is a slider.
Examples
Instantiate aNumberRangeConnector and launch an initial search on its searcher.
Swift
Parameters
The
FilterState that holds your filters.The attribute to filter.
The logic applied to the numeric range.
The nounds limiting the max and the min value of the range.
The initial range value.
Whether the filter is added to a conjuncitve(
and) or a disjuncitve (or) group in the filter state.Filter group name in the
FilterStateThe Controller interfacing with a concrete number range view.
Low-level API
If you want to fully control theFilter Numeric Range components and connect them manually, you can use the following components:
Searcher. TheSearcherthat handles your searches.FilterState. The current state of the filters.NumberRangeInteractor. The logic applied to the numeric ranges.NumberRangeController. The controller that interfaces with a concrete numeric range view.
Swift
Customizing your view
If you want to use 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 theNumberRangeController protocol.
Protocol
func setBounds(_ bounds: ClosedRange<Double>):
Function called when the minimum and maximum of numeric filter view have been defined.
var onRangeChanged: ((ClosedRange<Double>) -> Void)?
Closure to call when new bounds is set for the numeric range filter.
Example
Suppose you have a range slider control providing the following API:Swift
NumberRangeController including this control as follows:
Swift
SwiftUI
InstantSearch provides theNumberRangeObservableController data model,
which is an implementation of the NumberRangeController protocol adapted for usage with SwiftUI.
NumberRangeObservableController must be connected to the NumberRangeConnector or NumberRangeConnector like any other NumberRangeController implementation.
The example of the number range view using two Stepper components provided by SwiftUI.
Swift
NumberRangeObservableController as a data model.
It provides range and bounds properties to streamline the design process of your custom SwiftUI view.