Concepts / Building Search UI / Create your own widgets
May. 10, 2019

Create Your Own Widgets

On this page

Introduction

You are trying to create your own widget with iOS InstantSearch and that’s awesome 🎉. But that also means that you couldn’t find the widgets or built-in options you were looking for. We’d love to hear about your use case as our mission with our InstantSearch libraries is to provide the best out-of-the-box experience. Don’t hesitate to send us a quick message explaining what you were trying to achieve either using the form at the end of that page or directly by submitting a feature request

If none of the widgets fits your use-case, you can implement your own!

Any class implementing the AlgoliaWidget protocol can be added to InstantSearch and will be able to manage the search state or receive specific search events.

These are the protocols that you can add to your class:

  • SearchableViewModel: the widget will have a reference to Searcher by implementing function configure(with:), and will therefore be able to use it to trigger methods such as search() (e.g: UISearchBar), or updateNumericRefinement() (e.g: UISlider).
  • ResultingDelegate: the widget can process the results or handle the error of a search request to Algolia by implementing on(results:error:userInfo:).
  • RefinableDelegate: the widget receives events when search parameters are being altered in the Searcher. The widget will have to specify the refinement attribute that it is associated with, and then can subscribe to 4 different methods:
    • onRefinementChange(numericMap:) for a change in any numeric refinements.
    • onRefinementChange(numerics:) for a change in the numeric refinement associated with the widget’s attribute.
    • onRefinementChange(facetMap:) for a change in any facet refinements.
    • onRefinementChange(facets:) for a change in the facet refinement associated with the widget’s attribute.

Did you find this page helpful?