Othman El Jazouli
01/19/2023, 3:09 PM@Composable
fun MyBox(yProvider: () -> Float){
Box(
modifier = Modifier
.fillMaxSize()
.graphicsLayer {
translationY = yProvider()
}
.background(
color = Color(0XFF123456),
shape = RoundedCornerShape(
topStart = 16.dp,
topEnd = 16.dp
)
)
){...} // even with no content, same result
}
call
MyBox(
yProvider = { scroll offset calculated here }
)
robercoding
01/19/2023, 3:12 PM{...}
?
And what happens if you comment all the lines that are inside {...}
?This composable pretty much wrapping the content that is below a collapsable header
Othman El Jazouli
01/19/2023, 3:13 PMrobercoding
01/19/2023, 3:13 PMColor(0XFAFAIOS)
that way, what if you set Color.Red
or empty background?I can see in recomposition count that it is recomposing every time the header is showing or collapsing during scrollSo it's recomposing outside of
MyBox
composable?Othman El Jazouli
01/19/2023, 3:16 PMrobercoding
01/19/2023, 3:20 PMOthman El Jazouli
01/19/2023, 3:21 PMrobercoding
01/19/2023, 3:22 PMyProvider
🤔
Are you using some unstable type or?yProvider = { scroll offset calculated here }
Othman El Jazouli
01/19/2023, 3:28 PMrobercoding
01/19/2023, 3:29 PMMyBox
MyBox
Whatever you're doing - accessing a property - is considered reading and since you're using lambda to defer the operation, all of this is happening inside MyBox
Othman El Jazouli
01/19/2023, 3:33 PMrobercoding
01/19/2023, 3:36 PMOthman El Jazouli
01/19/2023, 3:46 PMobject : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
to save the offset and using it to update the translationY
,
and the yProvider is
yProvider = {-state.scrollOffset + headerHeight}
robercoding
01/19/2023, 3:46 PMState
? Is a custom class?data class CustomClass(val scrollOffset: Float)
Othman El Jazouli
01/19/2023, 3:48 PMrobercoding
01/19/2023, 3:48 PM@Stable
?Othman El Jazouli
01/19/2023, 3:48 PMrobercoding
01/19/2023, 4:36 PMStylianos Gakis
01/19/2023, 9:58 PMIm just having trouble understanding why reading it “somewhere else” would affect recomposing MyBoxIf I understood correctly what you are not sure about there, I would very strongly recommended to reading this https://dev.to/zachklipp/scoped-recomposition-jetpack-compose-what-happens-when-state-changes-l78