Since LazyList do not have a proper API to delay s...
# compose-wear
t
Since LazyList do not have a proper API to delay state restoration and the API change for that was refused, the only way for apps to properly restore complex LazyLists position with delayed loading is to swap the state after load is complete.
Copy code
ScreenScaffold(scrollState = if (items == null) emptyState else scalingLazyColumnState) {
        ScalingLazyColumn(columnState = if (items == null) emptyState else scalingLazyColumnState) { ....
The problem with that is that Scaffolds are not updated on scrollstate change due to no restart of the
OnFocusChange
on scrollstate change.
Seems the Wear API does not have a way to restart that part. And since the PR to add official Scaffold will have the same issue with the ScrollInfoProvider switch I post here to anticipate this. https://android-review.googlesource.com/c/platform/frameworks/support/+/3139353 @stevebower
It would be nice if the final API handle this correctly. Workaround with my copy of Horologist Scaffold is in scaffold
Copy code
LaunchedEffect(scrollState) {
        scaffoldState.replaceScreen(key, timeText, scrollState)
    }
And in the state
Copy code
fun replaceScreen(
        key: Any,
        timeText: @Composable (() -> Unit)?,
        scrollState: ScrollableState?,
    ) {
        if (screenContent.any { it.key === key }) {
            screenContent.removeIf { it.key === key }
            screenContent.add(ScreenContent(key, scrollState, timeText))
        }
    }
BTW this is needed, because we must swap the scrollstate also to scaffold due to Wear Review team that would reject the app as the loading screen might be scrollable and so need the scrollbar, but due to the swap of the state in the LazyList the state is not restored and so the scrollbar is not visible.
y
Care to submit a PR.
I hope this API will be in material3, so I'll flag this internally also.
t
This is quite hackish quick workaround. All should run on mainthread so I do not think there's a race risk, but it's real ugly to use a launched effect that only blindly replace and is not focus aware.
y
Ok, I'll take a look this week.
t
This is probably not that important as the LazyList people did not understand the need to have the if inside the lazy and want to have them outside so 2 lazylists, that solve the issue too. For wear a way to reset the focus listener is probably better and useful for more cases.
As usual after sleep mind is clear 🙂 Made https://github.com/google/horologist/pull/2278 with the proper fix.
Well M3 was merged with the issue :(
y
I wouldn't worry about that. It was discussed and deliberate. There is a tracking issue to make the fix. But it was avoided since it would require a lot of approvals on a large API CL, instead of a small bug fix with no API changes.
t
I'm never worried I like copy paste :) But nice to see it was seen.
👍🏻 1