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
800
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
88
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
2.2k
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
320
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
株式会社ビザスク_AI__Engineering_Summit_Tokyo_2025_登壇資料.pdf
eikohashiba
1
120
MySQLのSpatial(GIS)機能をもっと充実させたい ~ MyNA望年会2025LT
sakaik
0
150
戰略轉變:從建構 AI 代理人到發展可擴展的技能生態系統
appleboy
0
110
ハッカソンから社内プロダクトへ AIエージェント ko☆shi 開発で学んだ4つの重要要素
leveragestech
0
300
100以上の新規コネクタ提供を可能にしたアーキテクチャ
ooyukioo
0
280
Identity Management for Agentic AI 解説
fujie
0
500
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
2.5k
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
140
Cloud WAN MCP Serverから考える新しいネットワーク運用 / 20251228 Masaki Okuda
shift_evolve
PRO
0
120
Agent Skillsがハーネスの垣根を超える日
gotalab555
6
4.7k
ActiveJobUpdates
igaiga
1
330
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
280
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
6.7k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
23
Site-Speed That Sticks
csswizardry
13
1k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
96
Building Adaptive Systems
keathley
44
2.9k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
0
32
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
270
Digital Ethics as a Driver of Design Innovation
axbom
PRO
0
130
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
130
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 が出る • まだまだ製品で使えるような段階ではない • まずは試してみよう!