Skip to content

Commit 19ed537

Browse files
authored
1 parent 403ceb8 commit 19ed537

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

benchmarks/multiplatform/benchmarks/src/commonMain/kotlin/benchmarks/animation/AnimatedVisibility.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package benchmarks.animation
22

33
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.animation.EnterExitState
5+
import androidx.compose.animation.core.Transition
46
import androidx.compose.foundation.Image
57
import androidx.compose.foundation.layout.Column
68
import androidx.compose.foundation.layout.fillMaxWidth
@@ -11,11 +13,11 @@ import androidx.compose.runtime.getValue
1113
import androidx.compose.runtime.mutableStateOf
1214
import androidx.compose.runtime.remember
1315
import androidx.compose.runtime.setValue
16+
import androidx.compose.runtime.withFrameNanos
1417
import androidx.compose.ui.Alignment
1518
import androidx.compose.ui.Modifier
1619
import compose_benchmarks.benchmarks.generated.resources.Res
1720
import compose_benchmarks.benchmarks.generated.resources.compose_multiplatform
18-
import kotlinx.coroutines.delay
1921
import org.jetbrains.compose.resources.ExperimentalResourceApi
2022
import org.jetbrains.compose.resources.painterResource
2123

@@ -24,12 +26,17 @@ import org.jetbrains.compose.resources.painterResource
2426
fun AnimatedVisibility() {
2527
MaterialTheme {
2628
var showImage by remember { mutableStateOf(false) }
29+
var transition: Transition<EnterExitState>? = null
2730
LaunchedEffect(showImage) {
28-
delay(200)
31+
do {
32+
withFrameNanos {}
33+
} while (transition?.isRunning == true)
34+
2935
showImage = !showImage
3036
}
3137
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
3238
AnimatedVisibility(showImage) {
39+
transition = this.transition
3340
Image(
3441
painterResource(Res.drawable.compose_multiplatform),
3542
null

0 commit comments

Comments
 (0)