Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Modifiers in Compose
Search
Beatrice Kinya
November 12, 2023
Technology
0
62
Modifiers in Compose
Did you know the order of modifiers matter? And much more.
Beatrice Kinya
November 12, 2023
Tweet
Share
More Decks by Beatrice Kinya
See All by Beatrice Kinya
Event driven approach: Make your app more predictable, maintainable and easier to debug
bkinya
0
9
Now In Android
bkinya
1
33
Introduction to Kotlin
bkinya
0
15
Ask Me Anything With Droid Pwani
bkinya
0
45
Modifiers: The secret sauce of Jetpack Compose
bkinya
0
180
Android Development in 2023
bkinya
0
52
Navigation in Jetpack Compose
bkinya
0
100
Architecting Compose UI, A Deep Dive
bkinya
0
85
Handling State in Jetpack Compose
bkinya
0
93
Other Decks in Technology
See All in Technology
Binary Authorizationと友達になろう / Let's be friends with Binary Authorization
iselegant
2
140
Azure SQL Database Hyperscale HA レプリカの監視
sansantech
PRO
0
220
LLMに日本語テキストを学習させる意義
ksaito
13
3.6k
四国クラウドお遍路 2024 in 高知 オープニング
yukataoka
0
160
Eventual Detection Engineering
ken5scal
0
1.1k
Envoy External AuthZとgRPC Extensionを利用した「頑張らない」Microservices認証認可基盤
andoshin11
0
210
技術ブログや登壇資料を秒で作るコツ伝授します
minorun365
PRO
23
5.1k
四国のあのイベントの〇〇システムを45日間で構築した話 / cloudohenro2024_tachibana
biatunky
0
280
Swift Testingのconfirmationを コードリーディング/Dive into Swift Testing confirmation
laprasdrum
1
140
waitany と waitall を作った話
mrkn
0
120
なぜクラウドサービスで Web コンソールを提供するのか
shuta13
4
2k
スーパーマリオRPGのリメイク版の変更点からみるUX
nishiharatsubasa
1
300
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
25
2k
Learning to Love Humans: Emotional Interface Design
aarron
270
40k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
Practical Orchestrator
shlominoach
185
10k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
29
2.6k
Gamification - CAS2011
davidbonilla
79
4.9k
Docker and Python
trallard
39
3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
22
3.9k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Unsuck your backbone
ammeep
667
57k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.2k
Transcript
Beatrice Kinya GDE for Android | Android Engineer Also, I
create content @ Droicon Academy Pro Hiker| Mountaineer… Twitter: @B__Kinya LinkedIn: Beatrice Kinya
Modifiers Jetpack Compose
Modifiers - Allow you to tweak appearance and behaviour of
composables. Image( modifier = Modifier .padding(16.dp) .offset {...} .background(color = …) .anchoredDraggable(state, …), )
Chaining Modifiers What will the following code produce? Image( modifier
= Modifier .padding(16.dp) .background(color = …) .anchoredDraggable(state, …) .offset {... }, ) A
Chaining Modifiers What will the following code produce? Image( modifier
= Modifier .padding(16.dp) .background(color = …) .anchoredDraggable(state, …) .offset {... }, ) B
Chaining Modifiers - If you chain multiple modifiers, the modifier
wraps the rest of the chain and the layout node within.
Chaining Modifiers
Constraints
Constraints - Constraints are passed down from parent to child
in a UI tree. - Constraints determine the maximum and minimum bounds for a node’s width and height.
Constraints Box(modifier = modifier.size(300.dp)) { Image( modifier = Modifier .padding(16.dp)
.size(90.dp) …, ) }
None
None
None
Constraints: This won’t work Box(modifier = modifier.width(300.dp)) { Image( modifier
= Modifier .fillMaxWidth() .padding(16.dp), … ) } Image( modifier = Modifier .fillMaxWidth() .size(90.dp), … )
None
None
None
Constraints: This won’t work Box(modifier = modifier.width(300.dp)) { Image( modifier
= Modifier .fillMaxWidth() .padding(16.dp), … ) }
None
Modifiers that affect constraints - size - width and height
- sizeIn - requiredSize
Always provide a modifier parameter
@Composable fun VersionImage( modifier: Modifier = Modifier ) { Box(modifier
= modifier) { Image( painter = painterResource(id = R.drawable.android_14_preview), contentDescription = null) } }
@Composable fun DraggableSample( modifier: Modifier = Modifier ) { Box(modifier
= modifier) { VersionImage( modifier = Modifier .size(200.dp) .padding(16.dp) .anchoredDraggable(state, orientation = Orientation.Horizontal) .offset {... }, ) } } A
@Composable fun Sample2( modifier: Modifier = Modifier, ) { Box(modifier
= modifier.background(color = lightGreen)) { VersionImage( modifier = Modifier .fillMaxWidth() .padding(16.dp), ) } } B
Resources - Docs: Constraints and Modifiers: https://developer.android.com/jetpack/compose/layouts/constraints-modifiers - Always provide
a modifier parameter: https://chrisbanes.me/posts/always-provide-a-modifier/ - Twitter compose rules: https://twitter.github.io/compose-rules/rules/#modifiers
Thank you!