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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
310
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.5k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
900
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
1
580
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.5k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.6k
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
210
Lessons from Spec-Driven Development
simas
PRO
0
230
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
770
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Producing Creativity
orderedlist
PRO
348
40k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
260
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Visualization
eitanlees
152
17k
Faster Mobile Websites
deanohume
310
32k
Designing for Performance
lara
611
70k
Music & Morning Musume
bryan
47
7.3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Mobile First: as difficult as doing things right
swwweet
225
10k
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Ͱ͋Δɻ