CombinedLoadStatesKt

Added in 3.3.4

public final class CombinedLoadStatesKt


Summary

Public methods

static final CombinedLoadStates

Function to wait on a Flow until a load has completed.

Public methods

awaitNotLoading

public static final CombinedLoadStates awaitNotLoading(@NonNull Flow<@NonNull CombinedLoadStates> receiver)

Function to wait on a Flow until a load has completed.

It collects on the Flow and suspends until it collects and returns the firstOrNull CombinedLoadStates where all LoadStates have settled into a non-loading state i.e. LoadState.NotLoading or LoadState.Error.

A use case could be scrolling to a position after refresh has completed:

override fun onCreate(savedInstanceState: Bundle?) {
...
refreshButton.setOnClickListener {
pagingAdapter.refresh()
lifecycleScope.launch {
// wait for refresh to complete
pagingAdapter.loadStateFlow.awaitNotLoading()
// do work after refresh
recyclerView.scrollToPosition(position)
}
}
}