Is there any change in Compose 1.10 alpha 2 that c...
# compose
t
Is there any change in Compose 1.10 alpha 2 that could explain a change in handling derivedState ? (See thread)
The following code
Copy code
@Composable
fun NestedScrollStateHandler(navigator: BottomSheetNavigator, scrollState: ScrollState?, disableDragToDismiss: Boolean) {
    val nestedScrollDisabled by remember(scrollState, disableDragToDismiss) {
        derivedStateOf {
            disableDragToDismiss || (scrollState?.canScrollBackward == true)
        }
    }
    SideEffect {
        navigator.disableNestedScroll(nestedScrollDisabled)
    }
    DisposableEffect(navigator) {
        onDispose { navigator.disableNestedScroll(false) }
    }
}
No more works as the
nestedScrollDisabled
is no more updated after a change of the
canScrollBackward
value.
w
I'm not sure about the bug, but is your
derivedStateOf
even necessary here?
canScrollBackward
is already derived, so you're not saving yourself any updates by re-wrapping it.
t
Yes it's actually not needed, this is very old code to workaround some bottomsheets bugs, so the fix to this case is easy. But this is still a change of behavior that might have impacts on parts way harder to spot :(
not like this 2
z
i don't think that has anything to do with derived state, that code probably only ever worked by accident anyway since you're not reading
nestedScrollDisabled
inside any kind of snapshot-state-restartable function. If it worked it must have been because
NestedScrollStateHandler
just happened to recompose when
canScrollBackward
changed
I would probably write that like
Copy code
@Composable
fun NestedScrollStateHandler(navigator: BottomSheetNavigator, scrollState: ScrollState?, disableDragToDismiss: Boolean) {
    LaunchedEffect(scrollState, disableDragToDismiss) {
        try {
            snapshotFlow { 
                disableDragToDismiss || (scrollState?.canScrollBackward == true)
            }.collect {
              navigator.disableNestedScroll(it)
            }
        } finally {
            navigator.disableNestedScroll(false)
        }
    }
}
t
Thanks, the code worked for 18 months and every single version of Compose / Kotlin during that period 😞 The only change made except the Compose bump is no more setting an M3 background in the Composable that calls it. I'll fix the code and hope there's no other places that will be impacted. Do I remember wrong that there was a lint check for state not read that should maybe have flagged this ?
z
I’m not aware of a lint check like that. It is probably not feasible to do since knowing what’s a state read can potentially require full program analysis.
👍 1