Skip to main content
Signature
LoadingConnector(
    searcher: Searcher,
    viewModel: LoadingViewModel,
    debouncer: Debouncer
)

About this widget

Components that show a loading indicator during pending requests. To add a loading indicator to your search experience, use these components:
  • Searcher. The Searcher that handles your searches.
  • LoadingViewModel. The logic applied to the loading indicator.
  • LoadingView. The concrete view displayed during loading.

Examples

Kotlin
class MyActivity: AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = ApplicationID("YourApplicationID"),
        apiKey = APIKey("YourSearchOnlyAPIKey"),
        indexName = IndexName("YourIndexName")
    )
    val loading = LoadingConnector(searcher)
    val connection = ConnectionHandler(loading)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val swipeRefreshLayout = SwipeRefreshLayout(this)
        val view: LoadingView = LoadingViewSwipeRefreshLayout(swipeRefreshLayout)
        connection += loading.connectView(view)
        searcher.searchAsync()
    }

    override fun onDestroy() {
        super.onDestroy()
        connection.disconnect()
        searcher.cancel()
    }
}

Parameters

searcher
Searcher
required
The Searcher that handles your searches.
viewModel
LoadingViewModel
default: LoadingViewModel()
The logic applied to the loading indicator.
debouncer
Debouncer
default: Debouncer(debounceLoadingInMillis)
Delays searcher operations by a specified time duration.

ViewModel

isLoading
Boolean
When true, the interface starts in a loading state.

ViewModel

isLoading
Boolean
default:false
When true, the interface starts in a loading state.
Kotlin
LoadingViewModel(isLoading = true)

View

view
LoadingView
required
The concrete view displayed during load.
Kotlin
val swipeRefreshLayout = SwipeRefreshLayout(this)
val view: LoadingView = LoadingViewSwipeRefreshLayout(swipeRefreshLayout)
loading.connectView(view)

Compose UI

InstantSearch provides the LoadingState as a state model, which is an implementation of the LoadingView interface. You need to connect LoadingState to the LoadingConnector or LoadingViewModel like any other LoadingView implementation.
Kotlin
class MyActivity : AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = ApplicationID("YourApplicationID"),
        apiKey = APIKey("YourSearchOnlyAPIKey"),
        indexName = IndexName("YourIndexName")
    )
    val loadingState = LoadingState()
    val loading = LoadingConnector(searcher)
    val connections = ConnectionHandler(loading)

    init {
        connections += loading.connectView(loadingState)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            SwipeRefresh(
                state = rememberSwipeRefreshState(loadingState.loading),
                onRefresh = { loadingState.reload() },
            ) {
                //...
            }
        }
        searcher.searchAsync()
    }

    override fun onDestroy() {
        super.onDestroy()
        connections.disconnect()
        searcher.cancel()
    }
}
I