AnimatedVisibility, AnimatedContent 등 이미 애니메이션이 포함되어 있는 컴포저블이다. 여기에 가면 예시 동작을 볼 수 있다.
AnimatedVisibility
AnimatedContent
Crossfade
animteContentSize
Modifier 속성 중 하나로 컴포저블의 크기가 변경될 때 애니메이션 적용
Box(
modifier = Modifier
.background(colorBlue)
.animateContentSize()
)
AnimatedVectorDrawable
val alpha: Float by animateFloatAsState(if (enabled) 1f else 0.5f)
val transition = updateTransition(currentState, label = "box state")
val rect by transition.animateRect(label = "rectangle") { state ->
when (state) {
BoxState.Collapsed -> Rect(0f, 0f, 100f, 100f)
BoxState.Expanded -> Rect(100f, 100f, 300f, 300f)
}
}
val borderWidth by transition.animateDp(label = "border width") { state ->
when (state) {
BoxState.Collapsed -> 1.dp
BoxState.Expanded -> 0.dp
}
}
val infiniteTransition = rememberInfiniteTransition()
val color by infiniteTransition.animateColor(
initialValue = Color.Red,
targetValue = Color.Green,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
rememberInfiniteTransition()을 선언하고 infiniteRepeatable을 사용해서 반복한다.
여기에 실제로 각 값들이 어떻게 동작하는 지 잘 나와있다.