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
790
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
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
390
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
110
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
200
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
110
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
240
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
720
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.7k
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
420
AIが無かった頃の素敵な出会いの話
codmoninc
1
460
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
330
メールのエイリアス機能を履き違えない
isshinfunada
0
240
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
200
Featured
See All Featured
Done Done
chrislema
186
16k
Six Lessons from altMBA
skipperchong
29
4.4k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
640
Docker and Python
trallard
47
4.1k
Chasing Engaging Ingredients in Design
codingconduct
0
270
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
The Cost Of JavaScript in 2023
addyosmani
55
10k
How to train your dragon (web standard)
notwaldorf
97
6.8k
The SEO Collaboration Effect
kristinabergwall1
1
520
Rails Girls Zürich Keynote
gr2m
96
14k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
420
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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Ͱ͋Δɻ