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
800
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
930
自作アプリのアイコンを作った話
aosa4054
0
260
Other Decks in Programming
See All in Programming
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
2
340
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
400
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1.7k
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
140
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
680
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
160
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
140
typoなんかねぇよ
raspython3
0
660
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
AIエージェント時代のコードレビューを設計する
nogu66
6
2.5k
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Rails Girls Zürich Keynote
gr2m
96
14k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
230
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
220
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
590
Building Applications with DynamoDB
mza
96
7.2k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
470
Ruling the World: When Life Gets Gamed
codingconduct
0
320
The World Runs on Bad Software
bkeepers
PRO
72
12k
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Ͱ͋Δɻ