Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 109ad29

Browse files
committed
Added AnimatedVisibilityExample.kt to MotionCompose
1 parent 95cd0cc commit 109ad29

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

MotionCompose/app/src/main/java/com/example/android/compose/motion/demo/Demo.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.example.android.compose.motion.demo.fadethrough.FadeThroughDemo
2222
import com.example.android.compose.motion.demo.loading.LoadingDemo
2323
import com.example.android.compose.motion.demo.sharedaxis.SharedAxisDemo
2424
import com.example.android.compose.motion.demo.sharedtransform.SharedTransformDemo
25+
import com.example.android.compose.motion.demo.visibility.AnimatedVisibilityExample
2526

2627
enum class Demo(
2728
val title: String,
@@ -82,7 +83,14 @@ enum class Demo(
8283
),
8384
content = { SharedAxisDemo() }
8485
),
85-
86+
AnimatedVisibility(
87+
title = "Layout > Animating a view's visibility",
88+
description = """
89+
Animating the views visibility from visible to invisible
90+
""".trimIndent(),
91+
apis = listOf("AnimatedVisibility"),
92+
content = { AnimatedVisibilityExample() }
93+
),
8694
Loading(
8795
title = "List > Loading",
8896
description = """
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.example.android.compose.motion.demo.visibility
2+
3+
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.animation.fadeIn
5+
import androidx.compose.animation.fadeOut
6+
import androidx.compose.foundation.Image
7+
import androidx.compose.foundation.layout.Box
8+
import androidx.compose.foundation.layout.fillMaxSize
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.size
11+
import androidx.compose.foundation.shape.RoundedCornerShape
12+
import androidx.compose.material3.Button
13+
import androidx.compose.material3.Text
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.getValue
16+
import androidx.compose.runtime.mutableStateOf
17+
import androidx.compose.runtime.remember
18+
import androidx.compose.runtime.setValue
19+
import androidx.compose.ui.Alignment
20+
import androidx.compose.ui.Modifier
21+
import androidx.compose.ui.draw.clip
22+
import androidx.compose.ui.layout.ContentScale
23+
import androidx.compose.ui.res.painterResource
24+
import androidx.compose.ui.tooling.preview.Preview
25+
import androidx.compose.ui.unit.dp
26+
import com.example.android.compose.motion.demo.CheeseImages
27+
28+
@Preview
29+
@Composable
30+
fun AnimatedVisibilityExample() {
31+
var visible by remember {
32+
mutableStateOf(true)
33+
}
34+
Box(modifier = Modifier.fillMaxSize()) {
35+
AnimatedVisibility(visible,
36+
modifier = Modifier.align(Alignment.Center),
37+
enter = fadeIn(),
38+
exit = fadeOut()
39+
) {
40+
Image(
41+
painter = painterResource(id = CheeseImages[0]),
42+
contentDescription = "Cheese",
43+
modifier = Modifier
44+
.size(256.dp, 192.dp)
45+
.clip(shape = RoundedCornerShape(16.dp)),
46+
contentScale = ContentScale.Crop
47+
)
48+
}
49+
Button(
50+
onClick = { visible = !visible },
51+
modifier = Modifier
52+
.align(Alignment.BottomCenter)
53+
.padding(64.dp)
54+
) {
55+
Text(text = "TOGGLE VISIBILITY")
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)