[Jetpack Compose] 2. Layouts, theming, and animation(4) #Animation

0

Jetpack Compose

목록 보기
8/11
post-thumbnail
post-custom-banner

[Jetpack Compose] 2. Layouts, theming, and animation(4)

📌참고자료

5 quick animations to make your app stand out

📌참고자료

  • when 문으로 화면에 보여질 Composable을 제어하는 경우, AnimatedContent 사용하기
  • AnimatedContent:
    composable that animates its content as it changes based on a target state
@Composable
fun SearchContent(
	tabSelected: CraneScreen
){
	AnimatedContent(
    	targetState = tabSelected
    ){ targetState ->
    	when(targetState){
        	CraneScreen.Fly -> FlySearchContent()
            CraneScreen.Sleep -> SleepSearchContent()
            CraneScreen.Eat -> EatSearchContent()
        }
    }
}
  • By default, the initial content fades out and then the target content fades in
    (= fade through behavior)
    -> transitionSpec 파라미터에 ContentTransform object 넘겨서 transition 커스텀 가능
  • ContentTransform
    • EnterTransitionExitTransitionwith infix function으로 결합하여 설정
    • SizeTransformusing infix function으로 설정
AnimatedContent(
    targetState = count,
    transitionSpec = {
        // Compare the incoming number with the previous number.
        if (targetState > initialState) {
            // If the target number is larger, it slides up and fades in
            // while the initial (smaller) number slides up and fades out.
            slideInVertically { height -> height } + fadeIn() with
                slideOutVertically { height -> -height } + fadeOut()
        } else {
            // If the target number is smaller, it slides down and fades in
            // while the initial number slides down and fades out.
            slideInVertically { height -> -height } + fadeIn() with
                slideOutVertically { height -> height } + fadeOut()
        }.using(
            // Disable clipping since the faded slide-in/out should
            // be displayed out of bounds.
            SizeTransform(clip = false)
        )
    }
) { targetCount ->
    Text(text = "$targetCount")
}

Animation in Compose Cheat Sheet

profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글