ste
09/01/2023, 6:27 PMAnimatedContent
, so that the blue square goes away when pressed, and returns back when the press is released (as shown in the first part of the video).
However, when the press is released before the transition ends, the red square starts animating instead, but it really shouldn't (second part of the video)
Is there a mistake on my side (code in 🧵) or is it a bug?ste
09/01/2023, 6:28 PMvar flag by remember { mutableStateOf(false) }
AnimatedContent(
targetState = flag,
label = "",
transitionSpec = {
if (false isTransitioningTo true) {
ContentTransform(
targetContentEnter = EnterTransition.None,
initialContentExit = slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Start, animationSpec = tween(durationMillis = 500)),
targetContentZIndex = -1.0f,
sizeTransform = SizeTransform(clip = false)
)
} else {
ContentTransform(
targetContentEnter = slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.End),
initialContentExit = ExitTransition.Hold,
targetContentZIndex = 0.0f,
sizeTransform = SizeTransform(clip = false)
)
}
},
modifier = Modifier
.pointerInput(Unit) {
detectTapGestures(onPress = {
flag = true
tryAwaitRelease()
flag = false
})
}
.fillMaxSize()
) { flag ->
Spacer(
modifier = Modifier
.wrapContentSize(Alignment.Center)
.size(256.dp)
.background(if (flag) Color.Red else Color.Blue)
)
}
ste
09/01/2023, 6:30 PMslideOutOfContainer
, but the initialContent
is attached to false
, which renders the blue squareDoris Liu
09/01/2023, 6:53 PMste
09/02/2023, 2:07 PMAnimatedContent
bug I reported a month ago: https://issuetracker.google.comh/issues/294408579Doris Liu
09/05/2023, 5:35 PMste
06/08/2024, 12:02 PMvar i by remember { mutableIntStateOf(0) }
AnimatedContent(
targetState = i,
label = "",
transitionSpec = {
val direction = AnimatedContentTransitionScope.SlideDirection.Down
val animationSpec = tween<IntOffset>(durationMillis = 1000)
slideIntoContainer(direction, animationSpec) togetherWith
slideOutOfContainer(direction, animationSpec)
},
modifier = Modifier
.clickable { i = (i + 1) % 3 }
.fillMaxSize()
) { i ->
Spacer(
modifier = Modifier
.fillMaxSize()
.background(when (i) {
0 -> Color.Red
1 -> Color.Blue
2 -> Color.Green
else -> TODO()
})
)
}
ste
06/08/2024, 12:03 PMDoris Liu
06/11/2024, 7:18 PMste
06/12/2024, 8:07 PMModifier.fillMaxSize()
)...
I attached four contiguous frames of the recording (45ms difference in between):
First frame: green in sliding from top, blue is sliding to bottom; the next state request (red) is about to get dispatched;
Second frame: green is advanced by the expected distance, but blue is already disappeared (background visible);
Third frame: red is just visible at the top, green is advanced by a big distance (background visible);
Four frame: red is still at the top, green is advanced by a big distance again (background visible).
Of course I don't know whether this is "unfixable" or whatever, it just doesn't look good 😅 - it really seems the transitions go "out of sync"