Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List blinking when I restore state in fragment #167

Open
artemkamko opened this issue May 12, 2021 · 7 comments
Open

List blinking when I restore state in fragment #167

artemkamko opened this issue May 12, 2021 · 7 comments

Comments

@artemkamko
Copy link

artemkamko commented May 12, 2021

I have two fragments and bottom navigation. Every fragment contain list with paging. I use RemoteMediator to get data from api.
If I use launch in fragment then I always recreate list if I navigate between first and second fragment.

lifecycleScope.launch {
            viewModel.items.collectLatest {
                adapter?.submitData(it)
            }
        }

If I use launchWhenCreated or launchWhenStarted then list save it state, but when I navigate between first and second fragment it show blank list for maybe 1 second and it's create visual blinking.
How can I save paging 3 list state and show list immediately on fragment created?

@artemkamko
Copy link
Author

It's also behave the save way as launchWhenCreated or launchWhenStarted if I use something like CoroutineScope(Dispatchers.IO).launch or any other dispatcher

@tunjid
Copy link
Contributor

tunjid commented Jun 30, 2021

@artemkamko I believe you want to use the cacheIn method. You will need to use this with a coroutineScope that is not affected by the onPause and onResume Fragment lifecycles, so most likely a viewModelScope.

If you are still experiencing issues, please file a bug on the paging issue tracker, as github issues are specifically for the codelab.

@tunjid tunjid closed this as completed Jun 30, 2021
@artemkamko
Copy link
Author

@tunjid Thanks for the answer. I did use cacheIn method in my viewModel where I store flow, but it's not help.
Ok I'll post the issue on the issue tracker

@tunjid tunjid reopened this Jul 1, 2021
@tunjid
Copy link
Contributor

tunjid commented Jul 1, 2021

@artemkamko hi again, I took another look and you're right. The issue seems to be because even through the remote mediator is not loading, it doesn't mean that the pager has fetched data from the db. So the list is made visible, the old list is shown, diff util calculates the change, removes the old items, then puts the new items in.

I'll try experimenting with a debounce on the adapter.loadStateFlow instead of adapter.addLoadStateListener to see if there's anything to help mitigate this, and also check for more simpler ways.

I reopened the issue as its very easy to repro with the codelab, so I'll keep updating you as I find out more details.

@artemkamko
Copy link
Author

@tunjid Ok, thanks

@artemkamko
Copy link
Author

artemkamko commented Sep 2, 2021

@tunjid Hi, do you have any progress in this issue?

@RafaelAmoMoralDev
Copy link

Hi @tunjid and @artemkamko, any news about this? I am experiencing (maybe) the same issue.

I have a bottom navigation view and two fragments in the navigation, both contain shared items so if, in the first fragment, I updated an item and then changed the fragment to the second one the list blinks. If I don't update the item the blink is not produced. Think that when the pagingSourceFactory invalidates is when the blink is produced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants