$30 off During Our Annual Pro Sale. View Details »
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
770
Devin で iOS の PR から Android のコードを生成する / Generate Android code from iOS PR using Devin
yanzm
0
180
AI ツールを活用したコードリーディング - Android の公式サンプル Now in Android のソースコードを読んでみよう - / Code reading with AI tools
yanzm
1
85
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
2.2k
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
310
Android Studio の 新しいAI機能を試してみよう / Try out the new AI features in Android Studio
yanzm
0
400
What’s new in Android development tools
yanzm
0
930
Google I/O 2025 Keynote & Developer Keynote Overview
yanzm
0
180
Coding Agent を使って Android アプリを作ってみる / Let's try using coding agent for Android app development
yanzm
0
210
Other Decks in Technology
See All in Technology
AWS re:Invent 2025~初参加の成果と学び~
kubomasataka
0
180
株式会社ビザスク_AI__Engineering_Summit_Tokyo_2025_登壇資料.pdf
eikohashiba
1
110
シニアソフトウェアエンジニアになるためには
kworkdev
PRO
3
270
Building Serverless AI Memory with Mastra × AWS
vvatanabe
0
480
『君の名は』と聞く君の名は。 / Your name, you who asks for mine.
nttcom
1
110
Connection-based OAuthから学ぶOAuth for AI Agents
flatt_security
0
350
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
アラフォーおじさん、はじめてre:Inventに行く / A 40-Something Guy’s First re:Invent Adventure
kaminashi
0
130
ソフトウェアエンジニアとAIエンジニアの役割分担についてのある事例
kworkdev
PRO
0
210
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
3.6k
TED_modeki_共創ラボ_20251203.pdf
iotcomjpadmin
0
140
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
170
Featured
See All Featured
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
90
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
750
KATA
mclloyd
PRO
33
15k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
26
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
280
Paper Plane (Part 1)
katiecoart
PRO
0
1.9k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
65
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
65
35k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Building Adaptive Systems
keathley
44
2.9k
The Pragmatic Product Professional
lauravandoore
37
7.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 が出る • まだまだ製品で使えるような段階ではない • まずは試してみよう!