0

Problem Statement: Using Paging3 library and need to show loading information in header when user swipes to refresh. I followed the sample provided in the here.

Solution: Tried adding refresh header in LoadStateAdapter for with using pagingAdapter.withLoadStateHeaderAndFooter().

messagesRecyclerView.adapter = messagesAdapter.withLoadStateHeaderAndFooter(
                header = MessageHeaderStateAdapter(messagesAdapter),
                footer = MessageLoadStateAdapter()
            )

But it does not shows the header until I swipe it 5-6 times in quick successions.

enter image description here

Footer, on other hand, shows just fine with loading more and error layouts based on LoadState.

Error State

enter image description here

Loading More State

enter image description here

Any pointers as to how this can be achieved are much appreciated.

Harsh Vardhan
  • 675
  • 1
  • 11
  • 24

1 Answers1

0

withLoadStateHeader just returns a ConcatAdapter that listens to PREPEND state. If you want the header to show up during REFRESH you can basically copy the code out of that helper, but instead update LoadStateAdapter based on REFRESH LoadState using a listener on your PagingDataAdapter

val header = MyLoadStateHeader()
adapter.addLoadStateListener { loadStates -> 
    header.loadState = loadStates.refresh 
} 

recyclerView.adapter = ConcatAdapter(header, this)
dlam
  • 3,547
  • 17
  • 20