Loading
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: TheSearcherthat handles your searches.LoadingViewModel: The logic applied to the loading indicator.LoadingView: The concrete view displayed during loading.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
| Parameter | Description | 
|---|---|
          
            searcher
          
         | 
        
           
                
                type: Searcher
                
               
              
                
                        Required
                
               
          The   | 
      
          
            viewModel
          
         | 
        
           
                
                type: LoadingViewModel
                
               
              
                
                  default: LoadingViewModel()
                
               
              
                
                    Optional
                
               
          The logic applied to the loading indicator.  | 
      
          
            debouncer
          
         | 
        
           
                
                type: Debouncer
                
               
              
                
                  default: Debouncer(debounceLoadingInMillis)
                
               
              
                
                    Optional
                
               
          Delays searcher operations by a specified time duration.  | 
      
ViewModel
| Parameter | Description | ||
|---|---|---|---|
          
            isLoading
          
         | 
        
           
                
                type: Boolean
                
               
              
                
                  default: false
                
               
              
                
                    Optional
                
               
          When true, the interface starts in a loading state.  | 
      ||
| 
           
Copy
 
       | 
      |||
View
| Parameter | Description | ||
|---|---|---|---|
          
            view
          
         | 
        
           
                
                type: LoadingView
                
               
              
                
                        Required
                
               
          The concrete view displayed during load.  | 
      ||
| 
           
Copy
 
       | 
      |||
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()
    }
}