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
39
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
Now In Android
bkinya
1
12
Introduction to Kotlin
bkinya
0
12
Ask Me Anything With Droid Pwani
bkinya
0
24
Modifiers: The secret sauce of Jetpack Compose
bkinya
0
120
Android Development in 2023
bkinya
0
40
Navigation in Jetpack Compose
bkinya
0
86
Architecting Compose UI, A Deep Dive
bkinya
0
73
Handling State in Jetpack Compose
bkinya
0
88
Getting Started: Jetpack Compose Layouts
bkinya
0
85
Other Decks in Technology
See All in Technology
【SORACOM UG 東海】あらゆるモノがつながる社会へ、IoT と SORACOM
soracom
PRO
1
130
How to do well in consulting–Balkan Ruby 2024
irinanazarova
0
110
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
2.1k
Cloud Service Mesh に触れ合う
phaya72
1
110
ServiceNow Now Platform 最新版Washington, D.C.リリース
manarobot
0
100
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
2
280
The AI Revolution Will Not Be Monopolized: Behind the scenes
inesmontani
PRO
1
150
Azureの基本的な権限管理の勉強会
yhana
1
1.9k
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
150
家族アルバム みてねにおけるGrafana活用術 / Grafana Meetup Japan Vol.1 LT
isaoshimizu
1
890
アクセス制御にまつわる改善 / Improving access control
itkq
0
580
本当のAWS基礎
toru_kubota
1
590
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
33
6k
Infographics Made Easy
chrislema
238
18k
A Modern Web Designer's Workflow
chriscoyier
689
190k
YesSQL, Process and Tooling at Scale
rocio
165
13k
Become a Pro
speakerdeck
PRO
12
4.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
6
1.3k
The Pragmatic Product Professional
lauravandoore
26
5.8k
A Philosophy of Restraint
colly
197
16k
Thoughts on Productivity
jonyablonski
59
3.8k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
Building Better People: How to give real-time feedback that sticks.
wjessup
356
18k
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!