var isVisible by remember { mutableStateOf(true) }
Column {
Button(onClick = { isVisible = !isVisible }) {
Text("ํ ๊ธ")
}
AnimatedVisibility(visible = isVisible) {
Text("๋ณด์ด๊ฑฐ๋ ์จ๊ฒจ์ง๋ ํ
์คํธ์
๋๋ค.")
}
}
=> isVisible์ ๊ฐ์ด ๋ฐ๋๋ฉด Text์ ๋ฑ์ฅ๊ณผ ์ฌ๋ผ์ง์ด ์ ๋๋ฉ์ด์
์ผ๋ก ์ฒ๋ฆฌ, ๋จ์ํ View๋ฅผ ์ถ๊ฐ&์ ๊ฑฐํ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ๋ถ๋๋ฌ์ด UX๋ฅผ ๋ง๋ค์ด์ค
AnimatedVisibility(
visible = isVisible,
enter = fadeIn() + slideInVertically(),
exit = fadeOut() + slideOutHorizontally()
) {
Text("๋ค์ํ ์ ๋๋ฉ์ด์
์ด ์ ์ฉ๋ ํ
์คํธ")
}
-> ์ง์
์ ์์์ ์ฌ๋ผ์ด๋ + ํ์ด๋ ์ธ
-> ์ดํ ์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ฌ๋ผ์ด๋ + ํ์ด๋ ์์
val slideSpec = tween(
durationMillis = 1000,
easing = FastOutSlowInEasing
)
tween: ์ ํ ์ ๋๋ฉ์ด์
spring: ํ๋ ฅ ์๊ฒ ํ๋ ๋๋
keyframes: ์๊ฐ๋ง๋ค ๊ฐ์ ์๋ ์ง์
easing: ๊ฐ์/๊ฐ์ ๊ณก์ (UI์ ์์ฐ์ค๋ฌ์์ ํฐ ์ํฅ)
val infiniteTransition = rememberInfiniteTransition()
val alpha by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
)
)
=> ๋ฐ๋ณต ์ ๋๋ฉ์ด์
์ ๋ก๋ฉ ์ ๋๋ฉ์ด์
์ด๋ ํธํกํ๋ ๋ฒํผ ํจ๊ณผ ๋ฑ์ ์ ์ฉํ๊ฒ ์ฌ์ฉ
AnimatedVisibility(visible = isVisible) {
Column {
Text("์ฒซ ๋ฒ์งธ", modifier = Modifier.animateEnterExit(
enter = fadeIn(), exit = fadeOut()
))
Text("๋ ๋ฒ์งธ", modifier = Modifier.animateEnterExit(
enter = slideInHorizontally(), exit = slideOutHorizontally()
))
}
}
=> ํ๋์ AnimatedVisibility ์์์๋ ๊ฐ ์์๋ง๋ค ๋ค์ํ ํจ๊ณผ๋ฅผ ๋ฃ์ ์ ์์ด์ ํํ๋ ฅ ์ฆ๊ฐ
var isVisible by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
isVisible = true
}
=> ์ฑ ์์ ์ ๋ก๊ณ , ์ธํธ๋ก ํ
์คํธ ๋ฑ์ ์์ฐ์ค๋ฝ๊ฒ ๋ํ๋ด๋ ๋ฐ ํ์ฉ
Crossfade(targetState = screen) { state ->
when (state) {
"Home" -> HomeScreen()
"Profile" -> ProfileScreen()
}
}
=> ๋ฒํผ ํด๋ฆญ โ ํ โ ํ๋กํ ํ๋ฉด ์ ํ ์ ํ์ด๋ ํจ๊ณผ๋ก ์์ ์ด ๋๊ธฐ์ง ์๋๋ก ๋์์ค
val angle by animateFloatAsState(targetValue = if (clicked) 360f else 0f)
Image(
painter = painterResource(id = R.drawable.logo),
contentDescription = null,
modifier = Modifier.rotate(angle)
)
=> ๋ฒํผ ํด๋ฆญ ์ ์ด๋ฏธ์ง ํ์
=> rotate()์ ์ ๋๋ฉ์ด์
์ํ ๊ฐ์ ๋ฐ์ธ๋ฉํ๋ ๋ฐฉ์
val color by animateColorAsState(targetValue = if (clicked) Color.Red else Color.Blue)
Box(modifier = Modifier.size(100.dp).background(color))
val offset by animateDpAsState(
targetValue = if (isClicked) 200.dp else 0.dp
)
Box(modifier = Modifier.offset(x = offset))
val scale by animateFloatAsState(
targetValue = 1.5f,
animationSpec = spring(dampingRatio = Spring.DampingRatioLowBouncy)
)
Canvas(modifier = Modifier.size(200.dp)) {
drawLine(Color.Black, Offset(0f, 0f), Offset(100f, 100f))
drawRect(Color.Green, Offset(50f, 50f), Size(80f, 80f))
drawCircle(Color.Blue, center = Offset(100f, 100f), radius = 40f)
}
drawLine(
color = Color.Red,
start = Offset(0f, 50f),
end = Offset(200f, 50f),
pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f))
)
val image = ImageBitmap.imageResource(id = R.drawable.sample)
Canvas(modifier = Modifier.size(200.dp)) {
drawImage(image)
}