Skip to content

Commit

Permalink
Get rid of delay from AnimatedVisibility benchmark (#5199)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjBooms authored Jan 14, 2025
1 parent 403ceb8 commit 19ed537
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package benchmarks.animation

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.Transition
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -11,11 +13,11 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import compose_benchmarks.benchmarks.generated.resources.Res
import compose_benchmarks.benchmarks.generated.resources.compose_multiplatform
import kotlinx.coroutines.delay
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource

Expand All @@ -24,12 +26,17 @@ import org.jetbrains.compose.resources.painterResource
fun AnimatedVisibility() {
MaterialTheme {
var showImage by remember { mutableStateOf(false) }
var transition: Transition<EnterExitState>? = null
LaunchedEffect(showImage) {
delay(200)
do {
withFrameNanos {}
} while (transition?.isRunning == true)

showImage = !showImage
}
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
AnimatedVisibility(showImage) {
transition = this.transition
Image(
painterResource(Res.drawable.compose_multiplatform),
null
Expand Down

0 comments on commit 19ed537

Please sign in to comment.