Jetpack Composeのイマ,プロダクション導入への道
by
CyberAgent
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Ӭ Ұഅ 2019 ৽ଔೖࣾ גࣜձࣾλοϓϧ iOS ΤϯδχΞ / SRE νʔϜ @kazumanagano @kazuma_nagano
Slide 2
Slide 2 text
ಞ࢙ 2019 ৽ଔೖࣾ גࣜձࣾCyberZ Next Experts (Android) 2019 ະ౿εʔύʔΫϦΤʔλ @at_sushi_at @Mori-Atsushi
Slide 3
Slide 3 text
Kotlin CoroutinesͱJetpack Compose https://at-sushi.work/blog/35/ https://at-sushi.work/blog/51/ https://zenn.dev/at_sushi_at/books/edf63219adfc31 https://developers.cyberagent.co.jp/blog/archives/33059/
Slide 4
Slide 4 text
OPENREC.tv • ߴը࣭͔ͭۀք࠷ߴਫ४ͷ ԆͳϥΠϒ৴ • αϒεΫ / PPV • ԻָϥΠϒ ήʔϜ࣮گϓϨΠಈըָ͕͠ΊΔ ϥΠϒಈըϓϥοτϑΥʔϜ
Slide 5
Slide 5 text
OPENREC.tvͷJetpack Composeಋೖ࣮ 10ը໘ΛશҠߦ ίϯϙʔωϯτΛҠߦ ৽ػೳComposeͰ ଞ̑ը໘
Slide 6
Slide 6 text
ࠓճͷΰʔϧ Jetpack ComposeΛ ϓϩμΫγϣϯಋೖͯ͠Έͨ͘ͳΔ
Slide 7
Slide 7 text
1.Jetpack ComposeͷϝϦοτ 2.ϓϩμΫγϣϯಋೖͷ3ͭͷํ๏ 3.ར༻্ͷ՝ͱͦͷղܾํ๏
Slide 8
Slide 8 text
1. Jetpack Composeͷ ϝϦοτ
Slide 9
Slide 9 text
Jetpack Composeͱ Android͚ͷ৽͍͠UIϑϨʔϜϫʔΫ • AndroidొޙɼॳΊͯͷUIϑϨʔϜϫʔΫ৽ • શʹ1͔Β࠶ઃܭ • 2019ͷGoogle I/Oʹͯൃද • 20217݄ʹstable ը૾ग़యɿhttps://developer.android.com/jetpack/compose
Slide 10
Slide 10 text
໋ྩతUIͱએݴతUI Jetpack Composeͷ࠷େͷར ໋ྩతUI એݴతUI আΛΕΔͱ EmptyͷUI͕ͬͯ͠·͏ Կ࣮ߦͯ͠ ಉ݁͡Ռ͕ಘΒΕΔ
Slide 11
Slide 11 text
ΑΓચ࿅͞ΕͨએݴతUI React, Flutterͷڭ܇Λܦͯ ฦΓͷͳ͍ ίϯϙʔωϯτ ॊೈͳhooks పఈతͳΩϟογϯά ෳࡶͳ͕݅ॻ͖͍͢ ίϯϙʔωϯτ݅ࣜʹ ΤϑΣΫτ͕ॻ͚Δ มߋͷͳ͍ΞΠςϜ ߋ৽͞Εͳ͍
Slide 12
Slide 12 text
ύϑΥʔϚϯεͷվળ ϨΠΞταΠζͷܭଌํ๏Λ৽ Android View Jetpack Compose ViewGroup View1 View2 ᶃ measure() ᶄ measure() ᶅ measure() ᶆmeasure() ᶇ measure() ࢠΛԿܭଌ͢Δ߹͕͋Δ Composable ࢠComposable ࢠComposable ᶃ measure() ᶄ measure() ᶅ measure() ඞͣҰͷΈ͔͠ܭଌ͞Εͳ͍
Slide 13
Slide 13 text
ϥΠϒϥϦͰͷఏڙ • OSͷߋ৽ʹӨڹ͠ͳ͍ʢAndroid 5͔Βར༻Մೳʣ • ߋ৽ͷԸܙΛ͙͢ʹಘΒΕΔ ϝϦοτ σϝϦοτ • ΞϓϦͷαΠζ͕ංେԽ͢ΔՄೳੑ͕͋Δ → ViewͷϥΠϒϥϦΛΘͳ͚Εখ͘͞ͳΔ(※1) • ىಈ͕͘ͳΔ → ϕʔεϥΠϯ ϓϩϑΝΠϧͰվળ͢Δ͔(※2) ※1ɿhttps://developer.android.com/jetpack/compose/ergonomics?hl=ja#apk-size ※2 : https://android-developers-jp.googleblog.com/2022/03/improving-app-performance-with-baseline.html
Slide 14
Slide 14 text
2. ϓϩμΫγϣϯಋೖͷ 3ͭͷํ๏
Slide 15
Slide 15 text
ϓϩμΫγϣϯಋೖͷલʹ OPENREC.tvͰͷϑϩʔ ௐࠪͱݕূΛ͢Δ 20215݄ Jetpack Composeθϛͷ։࢝ / ใऩूͱใڞ༗ 20214݄ σόοά༻πʔϧʢUI CatalogʣͰͷࢼݧӡ༻։࢝ 202112݄ ؆୯ͳϦετը໘ΛҠߦɼຊ൪ಋೖ 20222݄ ৽ػೳΛϑϧComposeͰϦϦʔε ݱࡏ ComposeΛੵۃར༻ / ਵ࣌Android View͔ΒҠߦ
Slide 16
Slide 16 text
ํ๏1. ը໘୯ҐͰҠߦ͢Δ • େม͕ͩ୯७ͰޮՌత • ViewModelΛͬͨਪΞʔΩςΫνϟͰ͋Εɼ UIͷҠߦͷΈͰࡁΉ
Slide 17
Slide 17 text
ํ๏1. ը໘୯ҐͰҠߦ͢Δ 1. ViewModelͷLiveDataΛ StateFlowʹ͢ʢΦϓγϣϯʣ • LiveDataͰಈ࡞͢Δ͕StateFlowͷํ͕૬ੑ͕ྑ͍ ʢՃͷϥΠϒϥϦ͕͍Βͳ͍ʣ • ࠓޙLiveDataΛΘͳ͍ͷͰ͋Ε͜ͷλΠϛϯάͰҠߦͯ͠ྑ͍͔ UI͔ΒͷೖྗϝιουͰ
Slide 18
Slide 18 text
ํ๏1. ը໘୯ҐͰҠߦ͢Δ 2. Jetpack ComposeͰUIΛॻ͘ • ͜͜શʹStatelessʹ͠ɼStateͷ༰Λඳը͢Δ͜ͱʹઐ೦͢Δ ը໘˓˓PageͰ໋໊ ϖʔδ͝ͱʹStateΛ༻ҙ
Slide 19
Slide 19 text
3. UIͱ݁߹͢Δ • StatelessͱStatefullͷίϯϙʔωϯτ͚Δ ○○Coordinatorͱ໋໊ ํ๏1. ը໘୯ҐͰҠߦ͢Δ
Slide 20
Slide 20 text
ํ๏1. ը໘୯ҐͰҠߦ͢Δ 4. Activity / Fragment͔Βݺͼग़͢ Activity Fragment setContentΛݺͼग़͢ ComposeViewΛ͏
Slide 21
Slide 21 text
ؾΛ͚ͭͨϙΠϯτ • ViewModelҎԼͷΞʔΩςΫνϟม͑ͳ͍ MVIFluxͷํ͕૬ੑ͕ྑ͍Մೳੑ͋Δ͕ɼ طଘͷViewModelͷ··ʹͨ͠ ແཧʹಉ࣌ʹมߋ͠Α͏ͱ͢Δͱ࠳ં͢ΔՄೳੑ͕͋ͬͨͨΊ • ViewModelΛࠩ͠ସ͑Մೳʹ͠ͳ͍ ϓϨϏϡʔςετʹstatelessίϯϙʔωϯτΛ͏ ํ๏1. ը໘୯ҐͰҠߦ͢Δ
Slide 22
Slide 22 text
ํ๏2. খ͞ͳίϯϙʔωϯτΛॻ͖͑Δ ComposeViewΛ͏ xmlͷComposeViewΛ্ॻ͖͢Δ xml Activity
Slide 23
Slide 23 text
ํ๏2. খ͞ͳίϯϙʔωϯτ Λॻ͖͑Δ xml͔Βݺͼग़ͤΔΑ͏ʹ͢Δ FrameLayoutͷCustomView
Slide 24
Slide 24 text
ҠߦͷϙΠϯτ • ComposableΛ࠶ར༻ՄೳͳܗͰอ࣋͢Δ ը໘શମΛComposeҠߦ͢Δ͜ͱΛఆͯ͠ߏங͓ͯ͘͠ Composeʹঢ়ଶΛ࣋ͨͤͳ͍ • Android Viewͱͷ૬ੑ͕ѱ͍έʔε͕͋Δ Nested Scroll͕͏·͘ಈ͔ͳ͍ʢcompose 1.1ʣ ఘΊͯAndroid ViewΛ͏ඞཁ͕ग़ͯ͘Δ ํ๏2. খ͞ͳίϯϙʔωϯτ Λॻ͖͑Δ
Slide 25
Slide 25 text
ํ๏3. RecyclerViewͷηϧ ΛComposeԽ͢Δ • ํ๏2ͱ΄ͱΜͲಉ͡ • ը໘શମҠߦʹܨ͛͘͢ɼݸਓతʹ͓͢͢Ί • EpoxygroupieͰར༻Մೳ
Slide 26
Slide 26 text
ҙ • compose 1.1Ͱηϧ͕࠶ར༻͞Εͳ͍ͷͰεΫϩʔϧ ͷύϑΥʔϚϯε͕མͪΔՄೳੑ͕͋Δ • compose 1.2Ͱղফ͞ΕΔ༧ఆ ํ๏3. RecyclerViewͷηϧ ΛComposeԽ͢Δ
Slide 27
Slide 27 text
3. ར༻্ͷ՝ͱ ͦͷղܾํ๏
Slide 28
Slide 28 text
՝1. ಉ͡ίϯϙʔωϯτͰඍົʹڍಈ͕ҟͳΔ SwipeRefreshLayout ϦϑϨογϡऴྃ࣌ͷΞχϝʔγϣϯ͕ҟͳΔ ͦͷͰফ͑Δ ͱͷҐஔʹΔ
Slide 29
Slide 29 text
TabLayout + Pager Ξχϝʔγϣϯ͕ҟͳΔ Ϧοϓϧ͕ԁ Ϧοϓϧ͕࢛֯ ΠϯσΟέʔλʔͷΞχϝʔγϣϯͳ͠ ΠϯσΟέʔλʔͷΞχϝʔγϣϯ͋Γ ՝1. ಉ͡ίϯϙʔωϯτͰඍົʹڍಈ͕ҟͳΔ
Slide 30
Slide 30 text
՝1. ಉ͡ίϯϙʔωϯτ Ͱඍົʹڍಈ͕ҟͳΔ ରԠҊ • ࣗ࡞ͯ͠߹ΘͤΔ Jetpack ComposeίϯϙʔωϯτΛൺֱత࡞Γ͍͢ ͦΕͰίετ͔͔Δ • ࠩΛೝΊͯͦͷ··͏ • AndroidViewΛ͏ ॴʹΑͬͯcomposeͱ૬ޓӡ༻͕Ͱ͖ͳ͍έʔε
Slide 31
Slide 31 text
՝2. recomposeͷ੍ • ༧ظͤͣύϑΥʔϚϯε͕ѱԽ͢Δέʔε͕͋Δ υϥοάεΫϩʔϧ / Ξχϝʔγϣϯ • େମෆཁͳrecomposeʢ࠶ߏʣ͕ ൣғͰൃੜ͍ͯ͠Δ
Slide 32
Slide 32 text
recomposeΛܭଌ͢Δ ϩάΛࠐΉ ModifierͰՄࢹԽ RecomposeHighlighterɿhttps://github.com/android/snippets/blob/master/compose/recomposehighlighter/src/main/java/com/example/android/compose/recomposehighlighter/RecomposeHighlighter.kt recomposeͰ౮
Slide 33
Slide 33 text
ϨΠΞτΠϯεϖΫλ Compose 1.2 + Android Studio Dolphin recompose εΩοϓ͞Εͨ
Slide 34
Slide 34 text
ղܾํ๏1. ComposableΛ skippableʹ͢Δ શͯͷҾʹมߋ͕ͳ͍ͱ Έͳ͞ΕΕεΩοϓ͞ΕΔ εΩοϓ͞Εͳ͍Ϋϥε • List<*>, Set<*> • Throwable, Date • શͯͷinterface • composeΛ͍ͬͯͳ͍ϞδϡʔϧϥΠϒϥϦͷΫϥε
Slide 35
Slide 35 text
উखʹมߋ͞Εͳ͍͜ͱΛ໌ࣔ ෦ʹState͕͋Δ߹ @StableΛ͏ ղܾํ๏1. ComposableΛ skippableʹ͢Δ
Slide 36
Slide 36 text
ղܾํ๏2. StateͷࢹॴΛม͑Δ Ҿ͕value recompose! recompose! value͕ݺΕͨՕॴͰrecompose͕͞ΕΔ Before After ͜͜ͰvalueΛࢹ ͜͜ͰStateͷ·· ͜͜ͰvalueΛࢹ recompose!
Slide 37
Slide 37 text
՝2. recomposeͷ੍ • جຊrecomposeͷൃੜΛҙࣝ͢Δඞཁͳ͍ • ࠷ॳ͔Β࠷దԽ͢Δͷɼίʔυͷݟ௨͕͠ ѱԽͨ͠ΓɼແବͳίετʹͳΓ͍͢ • ύϑΥʔϚϯεͷ͕ੜͨ͡ࡍʹɼ ܭଌ͠ͳ͕ΒղফΛࢦ͢ ૣ͗͢Δ࠷దԽΛߦΘͳ͍
Slide 38
Slide 38 text
·ͱΊ 1.Jetpack ComposeͷϝϦοτ એݴతUI / ύϑΥʔϚϯε / OSඇґଘ 2.ϓϩμΫγϣϯಋೖͷ3ͭͷํ๏ ը໘ͰҠߦ͢Δ / ίϯϙʔωϯτͷҠߦ / RecyclerViewͷηϧҠߦ 3.ར༻্ͷ՝ͱͦͷղܾํ๏ ίϯϙʔωϯτͷࠩ / recomposeͷ੍