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

Commit 6cc920e

Browse files
authored
Merge pull request #93 from android/riggaroo/animatedvisibility
Added AnimatedVisibilityExample.kt to MotionCompose
2 parents 95cd0cc + 16f583d commit 6cc920e

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-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,73 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.android.compose.motion.demo.visibility
17+
18+
import androidx.compose.animation.AnimatedVisibility
19+
import androidx.compose.animation.fadeIn
20+
import androidx.compose.animation.fadeOut
21+
import androidx.compose.foundation.Image
22+
import androidx.compose.foundation.layout.Box
23+
import androidx.compose.foundation.layout.fillMaxSize
24+
import androidx.compose.foundation.layout.padding
25+
import androidx.compose.foundation.layout.size
26+
import androidx.compose.foundation.shape.RoundedCornerShape
27+
import androidx.compose.material3.Button
28+
import androidx.compose.material3.Text
29+
import androidx.compose.runtime.Composable
30+
import androidx.compose.runtime.getValue
31+
import androidx.compose.runtime.mutableStateOf
32+
import androidx.compose.runtime.remember
33+
import androidx.compose.runtime.setValue
34+
import androidx.compose.ui.Alignment
35+
import androidx.compose.ui.Modifier
36+
import androidx.compose.ui.draw.clip
37+
import androidx.compose.ui.layout.ContentScale
38+
import androidx.compose.ui.res.painterResource
39+
import androidx.compose.ui.tooling.preview.Preview
40+
import androidx.compose.ui.unit.dp
41+
import com.example.android.compose.motion.demo.CheeseImages
42+
43+
@Preview
44+
@Composable
45+
fun AnimatedVisibilityExample() {
46+
var visible by remember {
47+
mutableStateOf(true)
48+
}
49+
Box(modifier = Modifier.fillMaxSize()) {
50+
AnimatedVisibility(visible,
51+
modifier = Modifier.align(Alignment.Center),
52+
enter = fadeIn(),
53+
exit = fadeOut()
54+
) {
55+
Image(
56+
painter = painterResource(id = CheeseImages[0]),
57+
contentDescription = "Cheese",
58+
modifier = Modifier
59+
.size(256.dp, 192.dp)
60+
.clip(shape = RoundedCornerShape(16.dp)),
61+
contentScale = ContentScale.Crop
62+
)
63+
}
64+
Button(
65+
onClick = { visible = !visible },
66+
modifier = Modifier
67+
.align(Alignment.BottomCenter)
68+
.padding(64.dp)
69+
) {
70+
Text(text = "TOGGLE VISIBILITY")
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)