PRESENTED AT: International Women's Day 2022 at GDG Bonny Island
https://gdg.community.dev/events/details/google-gdg-bonny-island-presents-international-womens-day-2022/
DATE: March 12, 2022
TIME: 7:00 > 20 min
DESCRIPTION:
MORE TALKS & ARTICLES FROM ME: https://cupsofcode.com/talks/
Aida IssayevaSenior Software EngineerGetting startedwith Animations inJetpack Compose
View Slide
What is JetpackCompose?
“Jetpack Composeis Android’s moderntoolkit for buildingnative UI.”https://developer.android.com/jetpack/compose/why-adopt https://developer.android.com/codelabs/jetpack-compose-animation#0
Introduction toAnimation API
Benefits1. Highly Customizable2. Interruptible and Continuous3. Extensive tooling
Low-Level APIHigh-Level API
High-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfade
High-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeval show = remember {mutableStateOf(false)}AnimatedVisibility(visible = show.value){ProgressNotPerfection()}Button(onClick = {show.value = !show.value})
High-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeval years = remember {mutableStateOf(2019)}AnimatedContent(targetState = years.value){ targetYear ->ProgressNotPerfection(targetYear)}Button(onClick = {years.value++}
High-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeval years = remember {mutableStateOf(2019)}Crossfade(targetState = years.value) {targetYear ->ProgressNotPerfection(targetYear)}Button(onClick = {years.value++}
High-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeval isProgress = remember {mutableStateOf(true)}val text = if(isProgress.value) {"#ProgressNotPerfection"} else { "IWD'22" }Box(modifier = Modifier.animateContentSize().clickable {isProgress.value = !isProgress.value}) {ProgressNotPerfection(text)
Low-LevelAPIHigh-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeanimate*AsState rememberInfiniteTransition updateTransition
val isProgress = remember {mutableStateOf(true)}val color by animateColorAsState(targetValue = if (isProgress.value) {Color.Blue} else {Color.Red})Box(modifier = Modifier.background(color = color).clickable {isProgress.value = !isProgress.value})Low-LevelAPIanimate*AsState rememberInfiniteTransition updateTransition
Low-LevelAPIanimate*AsState rememberInfiniteTransition updateTransitionval infiniteTransition =rememberInfiniteTransition()val alpha = infiniteTransition.animateFloat(initialValue = 0f,targetValue = 1f,animationSpec = infiniteRepeatable(animation = tween(durationMillis =1000),repeatMode = RepeatMode.Reverse))Box(modifier = Modifier.alpha(alpha = alpha.value))
Low-LevelAPIanimate*AsState rememberInfiniteTransition updateTransitionval transition = updateTransition(targetState = isProgress.value)val offsetY = transition.animateDp(label ="offsetY") { targetState ->when (targetState) {true -> 10.dpelse -> 60.dp}}. . .Box(modifier = Modifier.offset(y = offsetY.value).alpha(alpha = alpha.value).border(width = borderWidth.value).clickable {isProgress.value = !isProgress.value }
Low-LevelAPIHigh-LevelAPIAnimatedVisibilityAnimatedContentanimateContentSizeCrossfadeanimate*AsState rememberInfiniteTransition updateTransitionAnimatableAnimationStateAnimation
Where to go fromhere?
Official Guide to JetpackCompose Animationhttps://android-developers.googleblog.com/2021/05/whats-new-in-jetpack.html
Thank you@aida_isay