SlideShare a Scribd company logo
1 of 45
😸 Animations with Jetpack Compose
Antoine ROBIEZ
@enthuan
Baptiste CARLIER
@bapness
How to give life to your apps
Animate:
1. Give the appearance of movement using animation
techniques
2. Bring something to life
Jetpack Compose
• Declarative UI
• Kotlin
• Less code
• Compatible
Component = States
View = States
Screen = States
The purr-fect
Application
Jari Hytönen
Visibility Colors Rotation
Live coding
Visibility
AnimatedVisibility(fabExpand) {
Text(
modifier = Modifier.padding(horizontal = 8.dp),
text = "Trier"
)
}
Live coding results
val scaleY by animateFloatAsState(
targetValue = (if (sorted) {
-1f
} else {
1f
}),
animationSpec = tween(durationMillis = 500, easing = FastOutSlowInEasing)
)
Icon(
modifier = Modifier.scale(1f, scaleY),
imageVector = fabIcon,
contentDescription = null
)
Live coding results
AnimatedVisibility(
visible = expandState,
enter = slideInVertically(
initialOffsetY = { fullHeight -> fullHeight * -1 },
animationSpec = tween(durationMillis = 150, easing =
LinearOutSlowInEasing)
),
exit = slideOutVertically(
targetOffsetY = { fullHeight -> (fullHeight * -1) },
animationSpec = tween(durationMillis = 150, easing =
FastOutLinearInEasing)
)
) {
Text(
modifier = Modifier.padding(16.dp),
style = MaterialTheme.typography.bodyMedium,
text = cat.temper
)
}
Live coding results
• Use AnimatedVisibility(visible) to show/hide a
Composable
• Ability to customize enter / exit transitions
• Use AnimatedVisibilityScope with
Modifier.animateEnterExit(), you specify the child
element animation
Visibility
Visibility
Rotation
val arrowRotation by animateFloatAsState(
targetValue = (if (expandState) {
-180f
} else {
0f
}),
animationSpec = tween(durationMillis = 500, easing = FastOutSlowInEasing)
)
Icon(
modifier = Modifier
.padding(16.dp)
.rotate(arrowRotation)
,
imageVector = Icons.Filled.KeyboardArrowUp,
contentDescription = "Back"
)
Live coding results
Visibility
Rotation
Colors
val animationSpec = tween<Color>(400)
val contentColor = animateColorAsState(
targetValue = if (isFav) {
MaterialTheme.colorScheme.onPrimary
} else {
MaterialTheme.colorScheme.onSurface
},
animationSpec = animationSpec
)
val containerColor = animateColorAsState(
targetValue = if (isFav) {
MaterialTheme.colorScheme.primary
} else {
MaterialTheme.colorScheme.surface
},
animationSpec = animationSpec
)
Live coding results
Animate property from a State
• Use animate*AsState() APIs for value-based animation
• The animation is customizable with AnimationSpec
• Available animations:
animateDpAsState()
animateOffsetAsState()
animateFloatAsState()
animateColorAsState()
animateSizeAsState()
animateRectAsState()
animateIntAsState()
Interpolators
Linear Slow-In
Fast-Out
Slow-Out Slow-In-
Slow-Out
Live coding
Lists
Animated
Vector Drawable
ShapeShifter
https://shapeshifter.design/
var atEnd by remember { mutableStateOf(false) }
val fabIcon =
AnimatedImageVector.animatedVectorResource(R.drawable.avd_anim)
Icon(
painter = rememberAnimatedVectorPainter(fabIcon, atEnd),
contentDescription = null
)
Live coding results
Animated Vector Drawable
• Bound to a state (boolean)
• AnimatedImageVector:
✓ AnimatedImageVector.animatedVectorResource
• Painter:
✓ rememberAnimatedVectorPainter(vector, state)
• To trigger the animation, just reverse the state:
✓ state = !state
val onInverseSort = {
sorted = !sorted
coroutineScope.launch {
delay(200)
lazyListState.animateScrollToItem(0)
}
}
LazyColumn(
modifier = Modifier.fillMaxSize().padding(it),
state = lazyListState
) {
items(items = myItems, key = { it.id }) { cat ->
CatView(
modifier = Modifier
.fillMaxWidth()
.animateItemPlacement()
.clickable { onGoDetail(cat.id.toString()) }
.padding(horizontal = 24.dp, vertical = 16.dp),
cat = cat
)
}
}
Live coding results
• LazyItemScope:
✓ animateItemPlacement
• LazyListState:
✓ animateScrollToItem
✓ animateScrollBy
• Goodbye DiffUtils
Animate lists
Live coding
Transitions between screens
With a NavHost based navigation
Transitions
• AnimatedNavHost replaces NavHost
• Same mechanism than XML enter/exit/popEnter/popExit
• Not yet into Compose AndroidX
✓ Use Accompanist library
• Missing : SharedElement between screens
Navigation transitions
val onInverseSort = {
sorted = !sorted
coroutineScope.launch {
delay(200)
lazyListState.animateScrollToItem(0)
}
}
LazyColumn(
modifier = Modifier.fillMaxSize().padding(it),
state = lazyListState
) {
items(items = myItems, key = { it.id }) { cat ->
CatView(
modifier = Modifier
.fillMaxWidth()
.animateItemPlacement()
.clickable { onGoDetail(cat.id.toString()) }
.padding(horizontal = 24.dp, vertical = 16.dp),
cat = cat
)
}
}
Live coding results
Live coding
SplashScreen
Loading
Specifications, loops, transitions
AnimationSpecs allow to define how values should transform:
• tween: animates over the specified duration using an easing curve
• spring: a physics-based animation
• keyframes: based on the snapshot values specified at different timestamps
in the duration of the animation
• repeatable: repeat until it reaches the specified iteration count + a
animation (tween, spring, …)
• infiniteRepeatable: as repeatable, but indefinitely
• snap: immediately switches the value to the end value
Keyframes
val infiniteTransition = rememberInfiniteTransition()
val assRotation by infiniteTransition.animateFloat(
initialValue = -20f,
targetValue = -20f,
animationSpec = infiniteRepeatable(
animation = keyframes {
durationMillis = 1200
-20.0f at 0 with LinearOutSlowInEasing
20f at 600 with LinearOutSlowInEasing
-20f at 1200 with LinearOutSlowInEasing
},
repeatMode = RepeatMode.Restart
)
)
Box(modifier = modifier) {
Image(
painter = painterResource(id = R.drawable.cat_layer_back),
contentDescription = "Twerking cat",
modifier = Modifier.fillMaxSize()
.graphicsLayer {
rotationZ = assRotation
},
contentScale = ContentScale.Fit
)
Image(
painter = painterResource(id = R.drawable.cat_layer_front),
contentDescription = "",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Fit
)
}
Live coding results
Live coding
At launch
LaunchedEffect
val animatable = remember { Animatable(0f) }
LaunchedEffect(Unit) {
delay(800)
animatable.animateTo(targetValue = value, animationSpec = tween(2000))
}
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.SemiBold,
text = label
)
LinearProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.height(8.dp)
.clip(RoundedCornerShape(4.dp)),
progress = animatable.value,
color = color,
trackColor = color.copy(alpha = 0.4f)
)
}
Live coding results
LaunchedEffect
• LaunchedEffect is triggered during the composition
• The animation runs even if the Composable isn’t displayed on
screen
• Be careful with LazyLayout items
➢ LaunchedEffect is called each time the view is displayed
It's easy
Set the right animation,
at the right time
Pay attention to physics
Animated Vector Drawable :
usable ?
useful ?
is it worth it ?
MotionLayout :
MotionLayout :
Animated Vector Drawable : is it worth it ?
usable ?
useful ?
Animated Vector Drawable :
MotionLayout : usable ?
useful ?
is it worth it ?
One screen =
Several components
Several views
Several states
Ask for animated mockups or wireframes
Android community needs you
your client needs you
your final user needs you
Just try it !
https://github.com/enthuan/compose-animations
Antoine ROBIEZ
@enthuan
Baptiste CARLIER
@bapness

More Related Content

What's hot

Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Roman Elizarov
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascriptEman Mohamed
 
Android kotlin coroutines
Android kotlin coroutinesAndroid kotlin coroutines
Android kotlin coroutinesBipin Vayalu
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency InjectionNir Kaufman
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftCommit University
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced RoutingLaurent Duveau
 
Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6AIMDek Technologies
 
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4hackers.com
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
Android Accessibility - The missing manual
Android Accessibility - The missing manualAndroid Accessibility - The missing manual
Android Accessibility - The missing manualTed Drake
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 

What's hot (20)

Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Api security
Api security Api security
Api security
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascript
 
Android kotlin coroutines
Android kotlin coroutinesAndroid kotlin coroutines
Android kotlin coroutines
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
 
Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6Creating custom Validators on Reactive Forms using Angular 6
Creating custom Validators on Reactive Forms using Angular 6
 
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Android Accessibility - The missing manual
Android Accessibility - The missing manualAndroid Accessibility - The missing manual
Android Accessibility - The missing manual
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 

Similar to Animations avec Compose : rendez vos apps chat-oyantes

Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphicsroxlu
 
SwiftUI Animation - The basic overview
SwiftUI Animation - The basic overviewSwiftUI Animation - The basic overview
SwiftUI Animation - The basic overviewWannitaTolaema
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCsStandford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs彼得潘 Pan
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on AndroidPavlo Dudka
 
Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy ValuesJuriy Zaytsev
 
Model View Intent on Android
Model View Intent on AndroidModel View Intent on Android
Model View Intent on AndroidCody Engel
 
Animate The Web With Ember.js - Jessica Jordan
Animate The Web With Ember.js - Jessica JordanAnimate The Web With Ember.js - Jessica Jordan
Animate The Web With Ember.js - Jessica JordanJessica Jordan
 
Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Pedro Veloso
 
JavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesJavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesStephen Chin
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxFlutter Agency
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin MulletsJames Ward
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"Austin Zheng
 

Similar to Animations avec Compose : rendez vos apps chat-oyantes (20)

Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
SwiftUI Animation - The basic overview
SwiftUI Animation - The basic overviewSwiftUI Animation - The basic overview
SwiftUI Animation - The basic overview
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCsStandford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on Android
 
Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy Values
 
Model View Intent on Android
Model View Intent on AndroidModel View Intent on Android
Model View Intent on Android
 
Animate The Web With Ember.js - Jessica Jordan
Animate The Web With Ember.js - Jessica JordanAnimate The Web With Ember.js - Jessica Jordan
Animate The Web With Ember.js - Jessica Jordan
 
Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020Jetpack Compose - Hands-on February 2020
Jetpack Compose - Hands-on February 2020
 
JavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesJavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative Languages
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptx
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin Mullets
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 

Animations avec Compose : rendez vos apps chat-oyantes

  • 1. 😸 Animations with Jetpack Compose Antoine ROBIEZ @enthuan Baptiste CARLIER @bapness How to give life to your apps
  • 2. Animate: 1. Give the appearance of movement using animation techniques 2. Bring something to life
  • 3. Jetpack Compose • Declarative UI • Kotlin • Less code • Compatible
  • 10. AnimatedVisibility(fabExpand) { Text( modifier = Modifier.padding(horizontal = 8.dp), text = "Trier" ) } Live coding results
  • 11. val scaleY by animateFloatAsState( targetValue = (if (sorted) { -1f } else { 1f }), animationSpec = tween(durationMillis = 500, easing = FastOutSlowInEasing) ) Icon( modifier = Modifier.scale(1f, scaleY), imageVector = fabIcon, contentDescription = null ) Live coding results
  • 12. AnimatedVisibility( visible = expandState, enter = slideInVertically( initialOffsetY = { fullHeight -> fullHeight * -1 }, animationSpec = tween(durationMillis = 150, easing = LinearOutSlowInEasing) ), exit = slideOutVertically( targetOffsetY = { fullHeight -> (fullHeight * -1) }, animationSpec = tween(durationMillis = 150, easing = FastOutLinearInEasing) ) ) { Text( modifier = Modifier.padding(16.dp), style = MaterialTheme.typography.bodyMedium, text = cat.temper ) } Live coding results
  • 13. • Use AnimatedVisibility(visible) to show/hide a Composable • Ability to customize enter / exit transitions • Use AnimatedVisibilityScope with Modifier.animateEnterExit(), you specify the child element animation Visibility
  • 15. val arrowRotation by animateFloatAsState( targetValue = (if (expandState) { -180f } else { 0f }), animationSpec = tween(durationMillis = 500, easing = FastOutSlowInEasing) ) Icon( modifier = Modifier .padding(16.dp) .rotate(arrowRotation) , imageVector = Icons.Filled.KeyboardArrowUp, contentDescription = "Back" ) Live coding results
  • 17. val animationSpec = tween<Color>(400) val contentColor = animateColorAsState( targetValue = if (isFav) { MaterialTheme.colorScheme.onPrimary } else { MaterialTheme.colorScheme.onSurface }, animationSpec = animationSpec ) val containerColor = animateColorAsState( targetValue = if (isFav) { MaterialTheme.colorScheme.primary } else { MaterialTheme.colorScheme.surface }, animationSpec = animationSpec ) Live coding results
  • 18. Animate property from a State • Use animate*AsState() APIs for value-based animation • The animation is customizable with AnimationSpec • Available animations: animateDpAsState() animateOffsetAsState() animateFloatAsState() animateColorAsState() animateSizeAsState() animateRectAsState() animateIntAsState()
  • 22. var atEnd by remember { mutableStateOf(false) } val fabIcon = AnimatedImageVector.animatedVectorResource(R.drawable.avd_anim) Icon( painter = rememberAnimatedVectorPainter(fabIcon, atEnd), contentDescription = null ) Live coding results
  • 23. Animated Vector Drawable • Bound to a state (boolean) • AnimatedImageVector: ✓ AnimatedImageVector.animatedVectorResource • Painter: ✓ rememberAnimatedVectorPainter(vector, state) • To trigger the animation, just reverse the state: ✓ state = !state
  • 24. val onInverseSort = { sorted = !sorted coroutineScope.launch { delay(200) lazyListState.animateScrollToItem(0) } } LazyColumn( modifier = Modifier.fillMaxSize().padding(it), state = lazyListState ) { items(items = myItems, key = { it.id }) { cat -> CatView( modifier = Modifier .fillMaxWidth() .animateItemPlacement() .clickable { onGoDetail(cat.id.toString()) } .padding(horizontal = 24.dp, vertical = 16.dp), cat = cat ) } } Live coding results
  • 25. • LazyItemScope: ✓ animateItemPlacement • LazyListState: ✓ animateScrollToItem ✓ animateScrollBy • Goodbye DiffUtils Animate lists
  • 26. Live coding Transitions between screens With a NavHost based navigation
  • 28. • AnimatedNavHost replaces NavHost • Same mechanism than XML enter/exit/popEnter/popExit • Not yet into Compose AndroidX ✓ Use Accompanist library • Missing : SharedElement between screens Navigation transitions
  • 29. val onInverseSort = { sorted = !sorted coroutineScope.launch { delay(200) lazyListState.animateScrollToItem(0) } } LazyColumn( modifier = Modifier.fillMaxSize().padding(it), state = lazyListState ) { items(items = myItems, key = { it.id }) { cat -> CatView( modifier = Modifier .fillMaxWidth() .animateItemPlacement() .clickable { onGoDetail(cat.id.toString()) } .padding(horizontal = 24.dp, vertical = 16.dp), cat = cat ) } } Live coding results
  • 31.
  • 32. Specifications, loops, transitions AnimationSpecs allow to define how values should transform: • tween: animates over the specified duration using an easing curve • spring: a physics-based animation • keyframes: based on the snapshot values specified at different timestamps in the duration of the animation • repeatable: repeat until it reaches the specified iteration count + a animation (tween, spring, …) • infiniteRepeatable: as repeatable, but indefinitely • snap: immediately switches the value to the end value
  • 34. val infiniteTransition = rememberInfiniteTransition() val assRotation by infiniteTransition.animateFloat( initialValue = -20f, targetValue = -20f, animationSpec = infiniteRepeatable( animation = keyframes { durationMillis = 1200 -20.0f at 0 with LinearOutSlowInEasing 20f at 600 with LinearOutSlowInEasing -20f at 1200 with LinearOutSlowInEasing }, repeatMode = RepeatMode.Restart ) ) Box(modifier = modifier) { Image( painter = painterResource(id = R.drawable.cat_layer_back), contentDescription = "Twerking cat", modifier = Modifier.fillMaxSize() .graphicsLayer { rotationZ = assRotation }, contentScale = ContentScale.Fit ) Image( painter = painterResource(id = R.drawable.cat_layer_front), contentDescription = "", modifier = Modifier.fillMaxSize(), contentScale = ContentScale.Fit ) } Live coding results
  • 37. val animatable = remember { Animatable(0f) } LaunchedEffect(Unit) { delay(800) animatable.animateTo(targetValue = value, animationSpec = tween(2000)) } Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.SemiBold, text = label ) LinearProgressIndicator( modifier = Modifier .fillMaxWidth() .height(8.dp) .clip(RoundedCornerShape(4.dp)), progress = animatable.value, color = color, trackColor = color.copy(alpha = 0.4f) ) } Live coding results
  • 38. LaunchedEffect • LaunchedEffect is triggered during the composition • The animation runs even if the Composable isn’t displayed on screen • Be careful with LazyLayout items ➢ LaunchedEffect is called each time the view is displayed
  • 39. It's easy Set the right animation, at the right time Pay attention to physics
  • 40. Animated Vector Drawable : usable ? useful ? is it worth it ? MotionLayout :
  • 41. MotionLayout : Animated Vector Drawable : is it worth it ? usable ? useful ?
  • 42. Animated Vector Drawable : MotionLayout : usable ? useful ? is it worth it ?
  • 43. One screen = Several components Several views Several states Ask for animated mockups or wireframes
  • 44. Android community needs you your client needs you your final user needs you Just try it !

Editor's Notes

  1. ARO Concernant les animated vector drawable, c’est un peu étrange mais ça reste dans la logique compose. On doit avoir un état (eh oui encore) lié à l’animated Vector Drawable, récupérer la resource. Préparer un painter qui va bien sur etre remembered entre les compositions et le passer en attribut d’une image. Pour déclencher l’animation, on inversera simplement le booléen (au clic ou autre)