A view with helpers that displays a paginated list of search results.It uses Android Architecture Components’
Paging library
and LiveData to provide lifecycle-aware,
observable search results that can be loaded as users scroll.To add infinite hits to your search experience, add the following to your build.gradle file:
InstantSearch provides the Paginator,
which exposes a flow property for paging data and an invalidate() method to stop loading.
You must also connect Paginator to other components, such as SearchBoxConnector, FilterState, or FacetListConnector.
Kotlin
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val pagingConfig = PagingConfig(pageSize = 10) val hitsPaginator = Paginator(searcher, pagingConfig) { it.deserialize(Movie.serializer()) } val searchBoxState = SearchBoxState() val searchBox = SearchBoxConnector(searcher) val connections = ConnectionHandler() init { connections += searchBox.connectView(searchBoxState) connections += searchBox.connectPaginator(hitsPaginator) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { SearchBox( searchBoxState = searchBoxState ) val hitsPaging = hitsPaginator.flow.collectAsLazyPagingItems() LazyColumn { items(hitsPaging) { movie -> movie?.let { Text(it.title) } } } } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() connections.disconnect() searcher.cancel() }}