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
Jetpack Compose どうなの?
Search
Yuki Anzai
November 15, 2019
Technology
7
3.9k
Jetpack Compose どうなの?
Android Dev Summit 2019 Extended Tokyo #gdgtokyo
https://gdg-tokyo.connpass.com/event/152665/
Yuki Anzai
November 15, 2019
Tweet
Share
More Decks by Yuki Anzai
See All by Yuki Anzai
Android Studio Otter の最新 Gemini 機能 / Latest Gemini features in Android Studio Otter
yanzm
0
890
Devin で iOS の PR から Android のコードを生成する / Generate Android code from iOS PR using Devin
yanzm
0
200
AI ツールを活用したコードリーディング - Android の公式サンプル Now in Android のソースコードを読んでみよう - / Code reading with AI tools
yanzm
1
220
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
2.5k
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
350
Android Studio の 新しいAI機能を試してみよう / Try out the new AI features in Android Studio
yanzm
0
420
What’s new in Android development tools
yanzm
0
960
Google I/O 2025 Keynote & Developer Keynote Overview
yanzm
0
200
Coding Agent を使って Android アプリを作ってみる / Let's try using coding agent for Android app development
yanzm
0
220
Other Decks in Technology
See All in Technology
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
200
Agile Leadership Summit Keynote 2026
m_seki
1
650
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
350
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
180
OpenShiftでllm-dを動かそう!
jpishikawa
0
130
プロダクト成長を支える開発基盤とスケールに伴う課題
yuu26
4
1.4k
OCI Database Management サービス詳細
oracle4engineer
PRO
1
7.4k
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
480
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
590
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
450
Featured
See All Featured
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
The agentic SEO stack - context over prompts
schlessera
0
640
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
150
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Tell your own story through comics
letsgokoyo
1
810
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
330
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
78
Unsuck your backbone
ammeep
671
58k
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Transcript
Jetpack Compose どうなの? Yuki Anzai (@yanzm) at Android Dev Summit
2019 報告会
Yuki Anzai • Google Developer Expert for Android • Twitter
: @yanzm
None
Jetpack Compose ってなに? • Android の UI を作るための(モダンな)ツールキット • Kotlin
• minSdkVersion = 21 • 既存のコード(View, XMLで構成されるUI)と混ぜて使える
Jetpack Compose がやりたいこと • もっとシンプルにしたい • 今までの⽅法だと、⼊⼒⽂字列でフィルタリングできるリストを作るの にたくさんコード書かないといけない • private
な API に開発者が依存せざるを得ない状況をやめたい • Material + animations な UI にしたい
Jetpack Compose がやりたいこと • single source of truth がやりたい •
CheckBox が持つ状態(isChecked)と Model が持つ状態 (isFavorite)どっちが正しいの?問題 • reactive UI がやりたい • single source of truth である Model が変わったら、⾃動で UI が変わ るようにしたい
Jetpack Compose がやりたいこと • UI パーツの再利⽤性を⾼めたい • ⼩さくて特定の役割にフォーカスした Composableを組み合わせて UI
を作る
What's new for Jetpack Compose • セッション • 「What's New
in Jetpack Compose 」 • https://www.youtube.com/watch?v=dtm2h-_sNDQ • 「Understanding Compose」 • https://www.youtube.com/watch?v=Q9MtlmmN4Q0
What's new for Jetpack Compose • Developer Preview : 0.1.0-dev02
• Android Studio 4.0 Canary 1 から簡単に試せるようになった • Not ready for production!!!!!(製品で使える段階じゃない、使うな、危 険) • 来年 beta が出るというアナウンス
None
Jetpack Compose を試す • Android Studio 4.0 Canary 3 をインストールする
• [Start a new Android Studio project] - [Empty Compose Activity]
プレビュー
Composable function • fun に @Composable をつける → Composable function
@Composable fun Greeting(name: String) { Text(text = "Hello $name!") }
Composable function • fun に @Composable をつける → Composable function
• Composable function は Composable function からしか呼べない @Composable fun Greeting(name: String) { Text(text = "Hello $name!") } library で⽤意されている Composable function
Composable function • fun に @Composable をつける → Composable function
• Composable function は Composable function からしか呼べない • UI Components = Composable functions のこと @Composable fun Greeting(name: String) { Text(text = "Hello $name!") }
@Composable fun MyList() { VerticalScroller { Column(crossAxisSize = LayoutSize.Expand) {
for (i in 0 until 20) { ListItem(text = "item : $i") } } } }
プレビュー • Composable function に @Preview をつける @Preview @Composable fun
DefaultPreview() { Greeting("Android") }
プレビュー • Composable function に @Preview をつける • 引数なし @Preview
@Composable fun DefaultPreview() { Greeting("Android") }
プレビュー • Composable function に @Preview をつける • 引数なし •
コードを変更したら Build Refresh で更新 @Preview @Composable fun DefaultPreview() { Greeting("Android") }
@Model • single source of truth • プロパティとして値(状態)を持つ • class
に @Model をつけると Observable な機能が追加される • Composable function は参照している @Model の可変プロパティを⾃動 で subscribeし、値が変わったら⾃動で recompose する(Composable function が再度呼ばれる) @Model class FavoriteState( var isFavorite: Boolean = false )
val names = listOf("Donuts", "Eclair", "Froyo") @Model class NameState(var value:
String = "") @Composable fun RandomName() { val nameState = NameState() Column { Text(text = "Hello ${nameState.value}!") Button( onClick = { nameState.value = names.random() }, text = "next" ) } }
val names = listOf("Donuts", "Eclair", "Froyo") @Model class NameState(var value:
String = "") @Composable fun RandomName() { val nameState = NameState() Column { Text(text = "Hello ${nameState.value}!") Button( onClick = { nameState.value = names.random() }, text = "next" ) } }
val names = listOf("Donuts", "Eclair", "Froyo") @Model class NameState(var value:
String = "") @Composable fun RandomName() { val nameState = NameState() Column { Text(text = "Hello ${nameState.value}!") Button( onClick = { nameState.value = names.random() }, text = "next" ) } }
val names = listOf("Donuts", "Eclair", "Froyo") @Model class NameState(var value:
String = "") @Composable fun RandomName() { val nameState = NameState() Column { Text(text = "Hello ${nameState.value}!") Button( onClick = { nameState.value = names.random() }, text = "next" ) } } recompose
val names = listOf("Donuts", "Eclair", "Froyo") @Composable fun RandomName() {
val nameState = +state { "" } Column { Text(text = "Hello ${nameState.value}!") Button( onClick = { nameState.value = names.random() }, text = "next" ) } } @Model class State<T>(value: T)
どんな UI Components がある? • androidx.ui:ui-layout:$version • レイアウト関係 • androidx.ui:ui-material:$version
• Material Design 関係 • ConstraintLayout 今作ってる最中です Jetnews サンプルを⾒るとよい
MaterialTheme { Column { Text("Hello Android") Button("button") Button("button", style =
OutlinedButtonStyle()) Checkbox(true, {}) RadioGroup(listOf("Donuts", "Eclair", "Froyo"), "Donuts", {}) Switch(true, {}) val vector = +vectorResource(R.drawable.ic_android_black_24dp) Container(width = 24.dp, height = 24.dp) { DrawVector(vector) } val image = +imageResource(R.drawable.yanzm) SimpleImage(image) } }
Custom View を作るには? • Draw と Layout を使う @Composable fun
DrawBox() { val paint = Paint() paint.color = Color.Blue paint.style = PaintingStyle.fill Draw { canvas: Canvas, _: PxSize -> val size = 200.dp.value val offset = 20.dp.value val radius = Radius.circular(20.dp.value) val rect = RRect(offset, offset, size + offset, size + offset, radius) canvas.drawRRect(rect, paint) } }
Custom View を作るには? • Draw と Layout を使う @Composable fun
Stack( children: @Composable() () -> Unit ) { Layout(children) { measurables, constraints -> val placeables = measurables.map { it.measure(constraints) } val maxWidth = placeables.map {it.width.value}.max()!!.ipx val maxHeight = placeables.map { it.height.value }.max()!!.ipx layout(maxWidth, maxHeight) { placeables.forEach { it.place(0.ipx, 0.ipx) } } } }
Custom View を作るには? • Draw と Layout を使う Stack {
DrawBox() Text("Donuts", style = TextStyle(Color.LightGray, 30.sp)) }
既存の View と使うには • Compose UI を既存の UI で使う :
@GenerateView (予定) • まだない • 既存の UI を Compose UI で使う • 特に情報なし
Jetpack Compose やるべき? • Layout XML はオワコンですか? • 既存の UI
の作り⽅が廃⽌されるわけではない • Java → Kotlin のように⼀部分だけ導⼊できるようにしていく • 今から試しておくべき? • チームは API への意⾒を求めているのでフィードバックがあればぜひ
Resources
Portal site • https://developer.android.com/jetpack/compose
Codelab • https://codelabs.developers.google.com/codelabs/jetpack- compose-basics
Sample • https://github.com/ android/compose-samples/ tree/master/JetNews • Android Studio で [Import
Sample...] - [Jetnews sample]
まとめ • Android Studio 4.0 Canary で Jetpack Compose を簡単に試せるように
なった • 来年 beta が出る • まだまだ製品で使えるような段階ではない • まずは試してみよう!