1
1
package benchmarks.animation
2
2
3
3
import androidx.compose.animation.AnimatedVisibility
4
+ import androidx.compose.animation.EnterExitState
5
+ import androidx.compose.animation.core.Transition
4
6
import androidx.compose.foundation.Image
5
7
import androidx.compose.foundation.layout.Column
6
8
import androidx.compose.foundation.layout.fillMaxWidth
@@ -11,11 +13,11 @@ import androidx.compose.runtime.getValue
11
13
import androidx.compose.runtime.mutableStateOf
12
14
import androidx.compose.runtime.remember
13
15
import androidx.compose.runtime.setValue
16
+ import androidx.compose.runtime.withFrameNanos
14
17
import androidx.compose.ui.Alignment
15
18
import androidx.compose.ui.Modifier
16
19
import compose_benchmarks.benchmarks.generated.resources.Res
17
20
import compose_benchmarks.benchmarks.generated.resources.compose_multiplatform
18
- import kotlinx.coroutines.delay
19
21
import org.jetbrains.compose.resources.ExperimentalResourceApi
20
22
import org.jetbrains.compose.resources.painterResource
21
23
@@ -24,12 +26,17 @@ import org.jetbrains.compose.resources.painterResource
24
26
fun AnimatedVisibility () {
25
27
MaterialTheme {
26
28
var showImage by remember { mutableStateOf(false ) }
29
+ var transition: Transition <EnterExitState >? = null
27
30
LaunchedEffect (showImage) {
28
- delay(200 )
31
+ do {
32
+ withFrameNanos {}
33
+ } while (transition?.isRunning == true )
34
+
29
35
showImage = ! showImage
30
36
}
31
37
Column (Modifier .fillMaxWidth(), horizontalAlignment = Alignment .CenterHorizontally ) {
32
38
AnimatedVisibility (showImage) {
39
+ transition = this .transition
33
40
Image (
34
41
painterResource(Res .drawable.compose_multiplatform),
35
42
null
0 commit comments