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
67
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
10
Now In Android
bkinya
1
35
Introduction to Kotlin
bkinya
0
15
Ask Me Anything With Droid Pwani
bkinya
0
48
Modifiers: The secret sauce of Jetpack Compose
bkinya
0
200
Android Development in 2023
bkinya
0
56
Navigation in Jetpack Compose
bkinya
0
100
Architecting Compose UI, A Deep Dive
bkinya
0
90
Handling State in Jetpack Compose
bkinya
0
95
Other Decks in Technology
See All in Technology
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
730
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
590
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
990
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Producing Creativity
orderedlist
PRO
341
39k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Writing Fast Ruby
sferik
627
61k
Automating Front-end Workflow
addyosmani
1366
200k
Docker and Python
trallard
40
3.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Building Applications with DynamoDB
mza
90
6.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Building an army of robots
kneath
302
43k
The Pragmatic Product Professional
lauravandoore
31
6.3k
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!