How to avoid empty view in community screen during page loading

Hi @SocialPlus_Support , When we click on Profile or MyFeed or Community page if there is any post items available we are showing an empty view (Your Feed is Empty )for few seconds . If post data is available we don’t want to show the empty view anytime . The issue is that while retrieving data from observable the UI gets updated with empty view and then it gets updated with list of data.
Could you please guide us how can we avoid this empty view. Please refer video.

Video Link:

sample code for updating UI:
fun setupFeedRecyclerview() {
println("second time adapter count " + adapter.itemCount)
adapter.addLoadStateListener { loadStates →
when (val refreshState = loadStates.mediator?.refresh) {
is LoadState.NotLoading → {
if (loadStates.source.refresh is LoadState.NotLoading && loadStates.append.endOfPaginationReached)
{ if(adapter.itemCount < 1 )
{
isFirstLoad = false
binding.emptyViewContainer.visibility = View.VISIBLE
binding.recyclerViewFeed.visibility = View.GONE
handleEmptyState(getEmptyView(getInflater()))
}
else{
binding.emptyViewContainer.removeAllViews()
handleLoadedState(adapter.itemCount)
}
}
binding.progressBar.visibility = View.GONE
}
is LoadState.Error → {
isFirstLoad = false
binding.progressBar.visibility = View.GONE
handleErrorState(AmityError.from(refreshState.error))
}
is LoadState.Loading → {
handleLoadingState()
}
else → {}
}
}
println(“check my data” + adapter.snapshot().items)
binding.recyclerViewFeed.adapter = adapter
binding.recyclerViewFeed.layoutManager = LinearLayoutManager(context)
getItemDecorations().forEach { binding.recyclerViewFeed.addItemDecoration(it) }
binding.recyclerViewFeed.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == SCROLL_STATE_SETTLING) {
getViewModel().sendPendingReactions()
}
}
})
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
if (positionStart == 0) {
binding.recyclerViewFeed.smoothScrollToPosition(0)
}
}
})
// if(adapter.snapshot().items.isEmpty()){
// handleEmptyState(getEmptyView(getInflater()))
// }else{
// binding.emptyViewContainer.removeAllViews()
// handleLoadedState(adapter.itemCount)
// }
}

Hi @IMKalpataru unfortunately, this is by design, I will help share this as a feedback to our engineering team.

Hello @IMKalpataru I’ve just got updated from the team that they already released the enhancement for this empty view issue in our latest uikit version which should be version 2.26.1 :pray:

Yeah, I am using the same version, still I will check and update you @SocialPlus_Support. Thanks

1 Like