Status Update
Comments
ap...@google.com <ap...@google.com> #2
Are you saying that loadState being null is more correct initial state compared to the current
```
CombinedLoadStates(
refresh = InitialLoadStates.refresh,
prepend = InitialLoadStates.prepend,
append = InitialLoadStates.append,
source = InitialLoadStates
)
private val IncompleteLoadState = LoadState.NotLoading(false)
private val InitialLoadStates = LoadStates(
IncompleteLoadState,
IncompleteLoadState,
IncompleteLoadState
)
```
ap...@google.com <ap...@google.com> #3
Ideally we would not pass any initial state because it will always have some case where it is wrong - we should ideally wait for a real event from Paging before sending it downstream to user.
For example the initial state:
CombinedLoadStates(
refresh = InitialLoadStates.refresh,
prepend = InitialLoadStates.prepend,
append = InitialLoadStates.append,
source = InitialLoadStates
)
...will always have null
mediator states, even if they are using RemoteMediator. This can mess up loadstate logic that is waiting for some combination of source + mediator loads to happen. It's easy to filter the initial case, but it gets complicated if they want to switchMap between multiple streams and they all start with this initial state. Or also consider the case when coming from cached state and needing to filter this out... it's bad developer UX.
So we could either set this to nullable to denote "no state" or we could have some constant we use that can be easily filtered out like "BogusLoadState" and then people can do .filter { it !== BogusLoadState }
ap...@google.com <ap...@google.com> #4
Alternatively, if we can read whether we have RemoteMediator
or not, we could try this for initial state which would be a lot more accurate:
private val InitialLoadStates = LoadStates(
LoadState.Loading,
IncompleteLoadState,
IncompleteLoadState
)
CombinedLoadStates(
refresh = InitialLoadStates.refresh,
prepend = InitialLoadStates.prepend,
append = InitialLoadStates.append,
source = InitialLoadStates,
mediatr = ??
)
ap...@google.com <ap...@google.com> #5
Don't you mind trying it out? You are better person for figuring out how to get RemoteMediator from PagingDataDiffer. To be honest I don't even know what RemoteMediator is used for
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit b7f9085d0b13af5a346d0712bbf3bc5a680c2fc9
Author: Sanura N'Jaka <sanura@google.com>
Date: Thu Apr 28 22:10:36 2022
Changing LazyPagingItem's inital LoadState refresh to Loading
Rather than LazyPagingItem having the inital LoadState
refresh being set to LoadState.NotLoading, we want it
to be LoadState.Loading
RelNote: "`LazyPagingItems` now sets the initial
`loadState` to have a `LoadState.Loading` refresh."
Test: lazyPagingInitialLoadState
Fixes: 224855902
Change-Id: I55043244f92c8029e4667df2e23c5813dcf2f729
M paging/paging-compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt
M paging/paging-compose/src/androidTest/java/androidx/paging/compose/LazyPagingItemsTest.kt
ap...@google.com <ap...@google.com> #7
ap...@google.com <ap...@google.com> #8
Is this the same issue reported in
ap...@google.com <ap...@google.com> #9
Is this the same issue reported in
which was set as Won't Fix? Because we did follow the recommendation from there to skip the first state, so we will have to revert that code. https://issuetracker.google.com/issues/190788885
Yes, part of the intention here is that people will no longer need to add this workaround in their code.
ap...@google.com <ap...@google.com> #10
Let's take a search screen example. When the user first enters the search screen, nothing is loading until the user enters its search in the textfield then clicks the search button. Then the state should be Loading.
I guess we should use the workaround provided here
ap...@google.com <ap...@google.com> #11
It might be too late for some people, but if people want to know how to tackle this I've played around with it on a pet project ( didn't test this in a prod environment, so a heads up there ):
@Composable
fun <T : Any> LazyPagingItems<T>.refreshLoadState(): State<LoadState> = produceState<LoadState>(
LoadState.NotLoading(false),
) {
snapshotFlow { loadState }
.drop(1)
.map { it.refresh }
.collect { value = it }
}
ap...@google.com <ap...@google.com> #12
Re
Given the most common use case displays paged data right away, defaulting LoadState to Loading
means the most common use case will not have to drop first LoadState (versus if it were NotLoading).
ap...@google.com <ap...@google.com> #13
I don't get how initial state being anything would affect the use case of displaying paged data right away. Wouldn't the LoadState
change before the user has time to notice?
IMHO, initial state being NotLoading
would be the sanest choice. In the case of waiting before starting to load data, the correct state would be shown to the user and in the case of loading data right away, it would immediately change to Loading
, so the correct state would be shown to the user in this case as well.
ap...@google.com <ap...@google.com> #14
Re collectAsLazyPagingItems
compose launches collection on Pager right away. By the time pager.collectAsLazyPagingItems()
returns, data is loading, so initial Loading
is the correct state.
Initializing with NotLoading
also causes other issues (which is why Paging with Views was also refactored to not initialize with NotLoading):
- For users who rely on first
NotLoading
state as indication of refresh complete, they have to manually filter out the firstNotLoading
- If loading animation (i.e. spinners) are based on LoadStates, you could end up seeing a blank screen --> spinner --> data loaded in, and that is not a good user experience.
ap...@google.com <ap...@google.com> #15
Branch: androidx-main
commit 15804fb6a1c1805305e66d23fc4c5a30cbc28d40
Author: Clara Fok <clarafok@google.com>
Date: Fri Jan 19 13:00:51 2024
Rename NullPaddedList to PlaceholderPaddedList
Test: ANDROIDX_PROJECTS=INFRAROGUE ./gradlew paging:paging-common:allTest
Bug: 315214786
Change-Id: Id699b61a98e81e59c11b78f4d07315717324e33b
M paging/paging-common/src/commonJvmAndroidMain/kotlin/androidx/paging/PagedList.kt
M paging/paging-common/src/commonJvmAndroidMain/kotlin/androidx/paging/PagedStorage.jvm.kt
M paging/paging-common/src/commonMain/kotlin/androidx/paging/PageStore.kt
M paging/paging-common/src/commonMain/kotlin/androidx/paging/PagingDataEvent.kt
M paging/paging-common/src/commonMain/kotlin/androidx/paging/PagingDataPresenter.kt
M paging/paging-common/src/commonMain/kotlin/androidx/paging/PlaceholderPaddedList.kt
M paging/paging-common/src/commonTest/kotlin/androidx/paging/PagingDataPresenterTest.kt
M paging/paging-runtime/src/androidTest/java/androidx/paging/PlaceholderPaddedListDiffHelperTest.kt
M paging/paging-runtime/src/androidTest/java/androidx/paging/PlaceholderPaddedListDiffWithRecyclerViewTest.kt
M paging/paging-runtime/src/main/java/androidx/paging/AsyncPagedListDiffer.kt
M paging/paging-runtime/src/main/java/androidx/paging/PlaceholderPaddedDiffing.md
M paging/paging-runtime/src/main/java/androidx/paging/PlaceholderPaddedListDiffHelper.kt
M paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
ap...@google.com <ap...@google.com> #16
Branch: androidx-main
commit 5c76ff18b0b1f721005807586b1bf136b954f856
Author: Clara Fok <clarafok@google.com>
Date: Thu Jan 18 16:49:49 2024
AsyncPagingDataDiffer LoadState emission to yield if getting item
Paging has existing logic to track if RecyclerView is running layouts and if so, yield before processing PageEvents. This was done by making PagingDataPresenter.collectFrom() yield on main dispatcher before processing Inserts, Drops, and LoadStateUpdates. See
As we move all RV logic out of PagingDataPresenter, we now throttle LoadStateUpdate emissions in AsyncPagingDataDiffer instead. This provides the guarantee that PagingDataAdapter and other RecyclerView.Adapters built on top of AsyncPagingDataDiffer can collect on LoadStateUpdates without crashing RV.
Test: paging.integration-tests.testapp does not crash when displaying header/footers for loadStates
Test: ./gradlew paging:paging-runtime:cC
Bug: 315214786
Change-Id: I7b9be5fc3d0a85a0ff2b3f7671f78626f74a80a1
M paging/paging-common/src/commonMain/kotlin/androidx/paging/PagingDataPresenter.kt
M paging/paging-runtime/src/androidTest/java/androidx/paging/AsyncPagingDataDifferTest.kt
M paging/paging-runtime/src/main/java/androidx/paging/AsyncPagingDataDiffer.kt
Description
Since we only implement the front end for Android, users of paging KMP will need their own custom front end built on top of paging-common for non-Android platforms. Therefore, we should open up paging-common so that external users of Paging KMP can implement their own Paging front end.