Chris Johnson
10/25/2021, 3:54 PMModifier.offset
causes recomposition infinitely when I'm not touching the screen? I'm using it together with animateIntOffset
+ user scroll.
Code in 🧵Chris Johnson
10/25/2021, 3:54 PMvar fingerUp by rememberSaveable { mutableStateOf(true) }
val offsetY = rememberSaveable { mutableStateOf(0f) }
val extraLayoutHeight = rememberSaveable { mutableStateOf(0) }
val snapTransition = updateTransition(targetState = fingerUp, label = "")
val snapOffset by snapTransition.animateIntOffset(label = "", transitionSpec = { tween(if (fingerUp) 200 else 0) }) {
if (it) {
if (uiState.progress <= .5f) {
IntOffset(0, 0)
} else {
IntOffset(0, extraLayoutHeight.value)
}
} else {
IntOffset(0, offsetY.value.toInt())
}
}
Column(
modifier = Modifier
.fillMaxWidth()
.offset { snapOffset }
Chris Johnson
10/25/2021, 3:57 PMDoris Liu
10/25/2021, 6:40 PMuiState.progress
change when you see recomposition? Reading that state in animation will recompose the animation whenever uiState.progress
is changed, even though the use of the value is more coarse grained/threshold based.
If you could post a minimal repro case, I'm happy to help investigate. 🙂Chris Johnson
10/25/2021, 6:53 PMpointerInput
and detectVerticalDragGestures
and set the progress in there, but this is causing an infinite recomposition cycle even with my fingers off the screen. I can try and setup a sample project if you give me a couple hours! 🙂Chris Johnson
10/25/2021, 6:55 PMDoris Liu
10/25/2021, 7:04 PMChris Johnson
10/25/2021, 7:06 PMChris Johnson
10/25/2021, 8:56 PMDoris Liu
10/25/2021, 8:57 PMChris Johnson
10/26/2021, 7:01 PMModifier.offset
is getting hit on recomposition though since the only thing I change is the text. Here's the project if you wanna take a look! If you have any suggestions they'd be greatly appreciated 🙇
https://github.com/cj1098/dragSampleDoris Liu
10/26/2021, 8:09 PMuiState
. Since the uiState
gets updated every second with the ticker, therefore animation recomposes when the value of uiState
changes. My local logging is showing recomposition ~once per second. That's what we expected. 🙂
For your particular use case, it'd be easier to manage the motion handoff from gesture to animation using an Animatable
. You could fire up the animation in onDragEnd
, as opposed to managing it separately in a state-based animation. You might find the "Gesture Animation" section in this codelab helpful: https://developer.android.com/codelabs/jetpack-compose-animation#7Chris Johnson
10/26/2021, 8:20 PMAnimatable
yet so I'm excited to explore that! I didn't know that it would cause recomposition of the animation if the value being read inside the animation wasn't getting changed. I think the only value was uiState.bottomNavScrollProgress
and that got changed once in onDragEnd.
So if an animation is reading a value from a snapshot state, it doesn't matter if that particular value it was reading changed or not, it will recompose because the value of uiState
changes?Doris Liu
10/26/2021, 9:37 PMSo if an animation is reading a value from a snapshot state, it doesn't matter if that particular value it was reading changed or not, it will recompose because the value ofThe animation is effectively readingchanges?uiState
foo.bar
, if foo
gets updated to a new instance, animation would have to recompose to read from the new foo for foo.bar
. If the value of foo.bar
didn't change and the animation isn't running, the animation value should remain the same. This means whoever reads animation value won't be recomposed. 🙂Chris Johnson
10/26/2021, 9:43 PMAnimatable
now :)Chris Johnson
11/04/2021, 6:41 PMGeorge Mount
11/04/2021, 7:40 PMGeorge Mount
11/04/2021, 7:45 PMLazyColumn {
repeat(100) {
item {
Button(onClick = {}) {
Text("Hello $it This is a nice button, eh?")
}
}
}
}
Do you think it is a problem with FAB?Chris Johnson
11/04/2021, 7:52 PMdetectVerticalDragGestures
instead of handling things manually via awaitPointerEventScope
+ verticalDrag
Chris Johnson
11/04/2021, 7:52 PMModifier.clickable
Chris Johnson
11/04/2021, 8:20 PMGeorge Mount
11/04/2021, 8:56 PMdetectVerticalDragGestures()
to see if it is doing something different than your implementation.Chris Johnson
11/04/2021, 9:02 PM