iOS
Signature
Explore example code
Browse the Hierarchical Menu example code on GitHub.
About this widget
AHierarchical Menu is a component that displays a hierarchical navigation menu, based on facet attributes.
Examples
Instantiate aHierarchicalConnector and launch an initial search on its Searcher.
Swift
Parameters
The
FilterState that holds your filters.The names of the hierarchical attributes to target, in ascending order.
The delimiter used to separate hierarchical facets.
Usually something like ” > ”, including spaces as shown in this example.
The Controller interfacing with a concrete hierarchical view.
The Presenter defining how hierarchical facets appear in the controller.
Presenter
The presenter defining how to display the
HierarchicalFacet list.Takes a list of HierarchicalFacet as input and returns a new HierarchicalFacet list.A HierarchicalFacet is a tuple of a Facet, its level, and whether it’s selected or not.Swift
Low-level API
If you want to fully control theHierarchical Menu components and connect them manually, you can use the following components:
Searcher. TheSearcherthat handles your searches.FilterState. The current state of the filters.HierarchicalInteractor. The logic applied to the hierarchical facets.HierarchicalController. The controller that interfaces with a concrete hierarchical facet list view.HierarchicalPresenter. Optional. The presenter that controls the sorting and other settings of the refinement facet list view.
Swift
Customizing your view
The default controllers, for example,HierarchicalTableViewController,
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 HierarchicalController protocol.
Protocol
var onClick: ((String) -> Void)?:
Closure to call when a new hierarchical facet is clicked.
func setItem(_ item: [HierarchicalFacet])
Function called when a new array of hierarchical facets is updated. This is the UI State of the refinement list. Make sure to reload your view here when you get the new items.
Example
Swift
SwiftUI
InstantSearch provides theHierarchicalList SwiftUI view which you can embed in your views.
It uses HierarchicalObservableController as a data model,
which is an implementation of the HierarchicalController protocol adapted for usage with SwiftUI.
HierarchicalObservableController must be connected to the HierarchicalConnector or HierarchicalInteractor like any other HierarchicalController implementation.
You can define the appearance of the view representing a single hierarchical facet and its selection state or use the HierarchicalFacetRow view provided by InstantSearch.
Swift
HierarchicalObservableController as a data model.
It provides the hierarchicalFacets property along with the toggle function to streamline the design process of your custom SwiftUI view.