I am facing some issue with paging 3 remote mediator. Everything works fine until I navigate to some other fragment and get back to the initial screen remote mediator will not load any more data than it initially loaded (i.e. it won't make anymore API call). Example:
Fragment A (contains paging adapter) -> Fragment B -> Fragment A
total data size is 100. If I return to fragment A after navigating to some other fragment, remote mediator will only load once. If I scrolled to the last item it doesn't trigger load. On the other hand, if I launch the application and does not navigate to another fragment, remote mediator will work correctly and it will load more data when scrolled to the end of list.
For reference.
This is my Pager called in ViewModel. For reference Fragment A and Fragment B is sharing the viewmodel through activityViewModels
private val _stories = Pager(
config = PagingConfig(pageSize = 10),
remoteMediator = StoryRemoteMediator(storyRepository),
) {
storyRepository.getAllStories()
}.flow
val stories get() = _stories
This is how my Paging Data is consumed in the fragment.
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.stories.collectLatest { pagingData ->
storyListAdapter.submitData(pagingData)
}
}
}