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
LazyVerticalGridに学ぶ 非スクローラブルなグリッドの作り方
Search
aosa4054
November 17, 2021
Programming
780
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LazyVerticalGridに学ぶ 非スクローラブルなグリッドの作り方
aosa4054
November 17, 2021
More Decks by aosa4054
See All by aosa4054
Now in Android Overview
aosa4054
1
1.5k
実用 Picture in Picture
aosa4054
2
920
自作アプリのアイコンを作った話
aosa4054
0
250
Other Decks in Programming
See All in Programming
Google Apps Script で Ruby を動かす
kawahara
0
110
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
3
250
霧の中の代数的エフェクト
funnyycat
1
440
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
560
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
170
Foundation Models frameworkで画像分析
ryodeveloper
1
160
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
160
メールのエイリアス機能を履き違えない
isshinfunada
0
140
えっ!!コードを読まずに開発を!?
hananouchi
0
280
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
720
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
430
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.4k
Featured
See All Featured
For a Future-Friendly Web
brad_frost
183
10k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Producing Creativity
orderedlist
PRO
348
40k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
We Have a Design System, Now What?
morganepeng
55
8.2k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
190
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
530
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Transcript
LazyVerticalGridʹֶͿ ඇεΫϩʔϥϒϧͳάϦου ͷ࡞Γํ potatotips #76 Shota Ara
LazyVerticalGrid • Jetpack Composeʹͯར༻Ͱ͖Δ άϦουදࣔͷComposable • σϑΥϧτͰεΫϩʔϧʹରԠ
LazyVerticalGridͷ͍ʹ͘͞ • ൃද࣌ʢ2021/11/17ʣͰExperimental • LazyVerticalGridࣗମ͕εΫϩʔϥϒϧͳComposableͰ͋Δ
LazyVerticalGridͷ ͍ʹ͘͞ LazyVerticalGridࣗମ͕εΫϩʔϧ ՄೳͳͷͰɺ ϦετͷҰ෦͕άϦου ͳUIͷදݱ͕Ͱ͖ͳ͍ɻ
LazyVerticalGridΛࢀߟʹComposableΛ࡞Δ • Experimentalͱ͍͑ެࣜͷࢀߟ࣮͕͋Δɻ • ComposableͳͲஔ͖͑Մೳͳؔʹ͓͚ͯ͠ ͠StableͳAPI͕Ճ͞Εͨͱ͖ͦΕΛஔ͖͑Δ͚ͩͰྑ͍ɻ
LazyVerticalGridͷ෦ॲཧ
LazyVerticalGridͷ෦ॲཧ val rows = (scope.totalSize + nColumns - 1) /
nColumns LazyColumn( /* modifierpaddingͳͲ֎෦͔Β͖ͯͨ͠ͷΛόέπϦϨʔ */ ) { items(rows) { rowIndex -> Row { for (columnIndex in 0 until nColumns) { /* ֤ΞΠςϜͷComposableΛݺͼग़͠ */ } } } }
LazyVerticalGridͷ෦ॲཧ val rows = (scope.totalSize + nColumns - 1) /
nColumns LazyColumn( /* modifierpaddingͳͲ֎෦͔Β͖ͯͨ͠ͷΛόέπϦϨʔ */ ) { items(rows) { rowIndex -> Row { for (columnIndex in 0 until nColumns) { /* ֤ΞΠςϜͷComposableΛݺͼग़͠ */ } } } } ͞ΕͨΞΠςϜͷαΠζͱΧϥϜ͔Β ߦΛܭࢉ͢Δ
LazyVerticalGridͷ෦ॲཧ val rows = (scope.totalSize + nColumns - 1) /
nColumns LazyColumn( /* modifierpaddingͳͲ֎෦͔Β͖ͯͨ͠ͷΛόέπϦϨʔ */ ) { items(rows) { rowIndex -> Row { for (columnIndex in 0 until nColumns) { /* ֤ΞΠςϜͷComposableΛݺͼग़͠ */ } } } } ෦ͰLazyColumnΛ͍࣋ͬͯΔ ʹ εΫϩʔϧͰ͖Δਖ਼ମ
LazyVerticalGridͷ෦ॲཧ val rows = (scope.totalSize + nColumns - 1) /
nColumns LazyColumn( /* modifierpaddingͳͲ֎෦͔Β͖ͯͨ͠ͷΛόέπϦϨʔ */ ) { items(rows) { rowIndex -> Row { for (columnIndex in 0 until nColumns) { /* ֤ΞΠςϜͷComposableΛݺͼग़͠ */ } } } } ҰߦҰߦΛRowʹͯ͠itemsͰ ͦΕΛॎʹੵΜͰߦ͘ॲཧ
͜ΕΛࢀߟʹ…
LazyVerticalGridΛࢀߟʹͨ͠ඇεΫϩʔϧ൛ val rows = (items.size + columns - 1) /
columns Column( /* modifierpaddingͳͲ֎෦͔Β͖ͯͨ͠ͷΛόέπϦϨʔ */ ) { for (rowIndex in 0..rows) { Row { for (columnIndex in 0 until nColumns) { /* ֤ΞΠςϜͷComposableΛݺͼग़͠ */ } } } }
αϯϓϧ࣮ LazyColumn { item { NonScrollableGrid( column = 3, items
= myItems ) { /* ֤ΞΠςϜͷComposable */ } } }
LazyColumn { item { NonScrollableGrid( column = 3, items
= (0..1000).toList() ) { /* ֤ΞΠςϜͷComposable */ Log.d(“@@@”, “$it”) } } }
LazyColumn { item { NonScrollableGrid( column = 3, items
= (0..1000).toList() ) { /* ֤ΞΠςϜͷComposable */ Log.d(“@@@”, “$it”) } } } 0…1000😇
LazyColumn { item { NonScrollableGrid( column = 3, items
= (0..1000).toList() ) { /* ֤ΞΠςϜͷComposable */ Log.d(“@@@”, “$it”) } } } item͕composableؔ ݺͼग़͠ͷ୯Ґ
վળ
fun <T> LazyListScope.gridItems( columns: Int, items: List<T>, gridItem: @Composable (T)
-> Unit ) { val rows = (items.size + columns - 1) / columns items(rows) { rowIndex -> Row { for (columnIndex in 0 until nColumns) { val itemIndex = rowIndex * columns + columnIndex if (itemIndex < items.size) { Box( modifier = Modifier.weight(1f, fill = true), propagateMinConstraints = true ) { gridItem.invoke(items[itemIndex]) } } else { Spacer(Modifier.weight(1f, fill = true)) } } } } }
LazyColumn { gridItems( column = 3, items = (0..1000).toList()
) { /* ֤ΞΠςϜͷComposable */ Log.d(“@@@”, “$it”) } }
LazyColumn { gridItems( column = 3, items = (0..1000).toList()
) { /* ֤ΞΠςϜͷComposable */ Log.d(“@@@”, “$it”) } } 0…24
·ͱΊ
·ͱΊ • Jetpack ComposeʹάϦουஔͷComposable͕༻ҙͯ͋͠Δɻ • ͍ͨͩ͠ʹ͍͘໘ɻ • ෦ίʔυൺֱతγϯϓϧͳͷͰ͜ΕΛࢀߟʹܨ͗ͷ࣮͕Մೳɻ • LazyColumnͷඳըͷ୯Ґ֤itemͰ͋Δɻ