I have a ListAdapter implementation of a very basic title-subtitle info items. When I update items or clear the list using submitList(items), the changes are applied and everything works normally.
But, if the RecyclerView is hidden, ListAdapter refreshes the items only when I make RecyclerView visible again. This causes a half-second blink between old and new items.
Here's a pseudo-code version1 of what I am doing:
suspend fun fetchItems() {
adapter.submitList(null)
showLoadingIndicator(); hideRecyclerView() // View.GONE
val result = api.fetchItems() // coroutine
adapter.submitList(result.items)
hideLoadingIndicator(); showRecyclerView()
}
If I don't update RecyclerView's visibility, there's no blink or transition between items. I can see that the items are cleared and then, after some time, they are shown.
If I hide RecyclerView for the duration of API call, it feels like adapter.submitList(null) didn't work. When API returns result, old data is shown for half a second, then gets switched with the data from the API.
Why is this happening? I guess it might be a performance improvement to not update Views when they are View.GONE.
How can I make it so that it doesn't blink like that?
1 I am using LiveData and MVVM to update UI and ListAdapter.