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 {...}
?robercoding
01/19/2023, 3:12 PMThis 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?robercoding
01/19/2023, 3:14 PMI 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?robercoding
01/19/2023, 3:22 PMyProvider = { scroll offset calculated here }
Othman El Jazouli
01/19/2023, 3:28 PMrobercoding
01/19/2023, 3:29 PMMyBox
robercoding
01/19/2023, 3:30 PMMyBox
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
robercoding
01/19/2023, 3:30 PMrobercoding
01/19/2023, 3:31 PMOthman 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}
Othman El Jazouli
01/19/2023, 3:46 PMrobercoding
01/19/2023, 3:46 PMState
? Is a custom class?robercoding
01/19/2023, 3:47 PMdata class CustomClass(val scrollOffset: Float)
Othman El Jazouli
01/19/2023, 3:48 PMOthman El Jazouli
01/19/2023, 3:48 PMrobercoding
01/19/2023, 3:48 PM@Stable
?Othman El Jazouli
01/19/2023, 3:48 PMOthman El Jazouli
01/19/2023, 4:32 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