SlideShare une entreprise Scribd logo
1  sur  62
GDG Taichung
UI新時代
Jetpack Compose
En-Ping Hsieh
2019 | Confidential and Proprietary GDG Taichung
Agenda
什麼是 Compose
Compose 想要解決什麼問題?
Jetpack Compose & Android Studio 4.2
示範
注意事項
參考資料
GDG Taichung
什麼是Compose
GDG Taichung
用Kotlin寫UI
GDG Taichung
GDG Taichung
只需要給 function 加上 @Composable,
就可以使用各式各樣的Composable元件,如Text、
Divider、Image、Card、Column、Row...
GDG Taichung
沒有淚類別,沒有傷害
GDG Taichung
一個稍微複雜的Layout長怎樣呢?
GDG Taichung
CardView
Linear Layout
ImageView
Text View
GDG Taichung
如果需求是:
如果有副標題就顯示,沒有就不顯示。
GDG Taichung
GDG Taichung
你可能會疑問
難道不需要初始化TextView的Visibility屬性嗎?
GDG Taichung
Composable function (UI) 不存在狀態,
而是作為資料的一種變換。
𝒇( )→Data UI
GDG Taichung
想像一個沒有狀態的Checkbox
GDG Taichung
GDG Taichung
但完全沒有狀態,也很不方便。
GDG Taichung
GDG Taichung
Compose想要解決什麼問題?
GDG Taichung
UI Toolkit 應該提供什麼能力?
GDG Taichung
根據給定的資料定義畫面該呈現什麼
畫面該如何反應事件改變
根據當前畫面狀態去調整?
GDG Taichung
根據給定的資料定義畫面該呈現什麼
畫面該如何反應事件改變
根據當前畫面狀態去調整?
GDG Taichung
Compose是一套Declarative UI toolkit
GDG Taichung
Declarative vs. Imperative
GDG Taichung
告訴Compose希望怎樣的畫面(What)
但交給Compose去決定如何達成(How)
GDG Taichung
為何Composable元件沒有狀態?
GDG Taichung
如無必要,勿增實體
Entities should not be multiplied unnecessarily
Ockham's Razor
GDG Taichung
Single Source of Truth (SSOT)
GDG Taichung
當資料來源發生變動時,
調用所有需要更新的Composable來重新建構UI,
此過程稱作Recompose 。
GDG Taichung
資料更新
資料 事件
點擊
GDG Taichung
資料總是由上而下傳遞,事件總是由下向上委派
(Lambda)
GDG Taichung
Compose是一套用Kotlin Code開發UI的工具
GDG Taichung
Jetpack Compose & Android
Studio
० 屬於Jetpack的一部分,免除UI元件Patch太慢的問題
० 元件不再具備狀態,可達成Single Source of Truth
० 全部Kotlin,不再使用findViewById,也不需要為Custom widget 設置style.xml
、color.xml和layout.xml,增加元件的內聚性,提高重構的可能性。
० 支援Material Design
० 可即時預覽多種螢幕畫面,還可進行互動(Android Studio 4.2 Canary)
GDG Taichung
多種畫面預覽
通過@Preview 標籤即可不同螢幕尺寸、文字尺寸、深色模式即時預覽。
GDG Taichung
測試畫面互動
畫面不僅可以預覽,還可以進行一定程度的互動,你可以測試你的動畫效果。
GDG Taichung
用Compose建構畫面
GDG Taichung
GDG Taichung
GDG Taichung
新Constraint Layout
GDG Taichung
GDG Taichung
GDG Taichung
重構一下
GDG Taichung
GDG Taichung
加入style和padding
GDG Taichung
GDG Taichung
Animation
GDG Taichung
GDG Taichung
GDG Taichung
GDG Taichung
新RecyclerView
AdapterList
GDG Taichung
GDG Taichung
GDG Taichung
互動一下
GDG Taichung
GDG Taichung
測試呢?
GDG Taichung
GDG Taichung
GDG Taichung
之前辛辛苦苦做好的UI都要重來嗎?
GDG Taichung
GDG Taichung
我想踹踹Compose,要注意什麼?
GDG Taichung
注意事項
० 屬於開發階段(0.1.0-dev13),請勿使用於正式產品
仍然有許多bug,像是preview經常無法正確生成,需要refresh,或是互動點擊
區域跑版。
० Android Studio 4.2+(Canary)
० Android SDK 21+
० Testing only for AndroidTest
https://mvnrepository.com/artifact/androidx.ui/ui-test
GDG Taichung
參考資料
० Code Lab
https://codelabs.developers.google.com/codelabs/jetpack-compose-basics/#0
० Tutorial
https://developer.android.com/jetpack/compose/tutorial
० Sample Repo
JetNews
https://github.com/android/compose-samples/tree/master/JetNews
० Speech
Jetpack Compose
https://www.youtube.com/watch?v=U5BwfqBpiWU
Declarative UI patterns (Google I/O'19)
https://www.youtube.com/watch?v=VsStyq4Lzxo
What's New in Jetpack Compose (Android Dev Summit '19)
https://www.youtube.com/watch?v=dtm2h-_sNDQ
Understanding Compose (Android Dev Summit '19)
https://www.youtube.com/watch?v=Q9MtlmmN4Q0
GDG Taichung
FAQ

Contenu connexe

Tendances

Gstreamer: an Overview
Gstreamer: an OverviewGstreamer: an Overview
Gstreamer: an OverviewRodrigo Costa
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh KhetanRajesh Khetan
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration libraryClaus Ibsen
 
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...GeoSolutions
 
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」VirtualTech Japan Inc.
 
用 Kotlin 做自動化工具
用 Kotlin 做自動化工具用 Kotlin 做自動化工具
用 Kotlin 做自動化工具Shengyou Fan
 
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9Keopx
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...Fwdays
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Opersys inc.
 
웹 프로그래밍 팀프로젝트 최종발표
웹 프로그래밍 팀프로젝트 최종발표웹 프로그래밍 팀프로젝트 최종발표
웹 프로그래밍 팀프로젝트 최종발표Seong Heum Park
 
오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGISJungHwan Yun
 
Introduction To PostGIS
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGISmleslie
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in androidHaifeng Li
 
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and BeforeUsage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and BeforeYoshi Shih-Chieh Huang
 
Customising QGroundControl
Customising QGroundControlCustomising QGroundControl
Customising QGroundControlGodfrey Nolan
 

Tendances (20)

Gstreamer: an Overview
Gstreamer: an OverviewGstreamer: an Overview
Gstreamer: an Overview
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh Khetan
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Lista de Raciones
Lista de RacionesLista de Raciones
Lista de Raciones
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration library
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Cuda tutorial
Cuda tutorialCuda tutorial
Cuda tutorial
 
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...Enterprise class deployment  for GeoServer and GeoWebcache Optimizing perform...
Enterprise class deployment for GeoServer and GeoWebcache Optimizing perform...
 
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
 
用 Kotlin 做自動化工具
用 Kotlin 做自動化工具用 Kotlin 做自動化工具
用 Kotlin 做自動化工具
 
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9
[DrupalCampSpain2022] Introducción al desarrollo de módulos en Drupal 9
 
Gradle布教活動
Gradle布教活動Gradle布教活動
Gradle布教活動
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
웹 프로그래밍 팀프로젝트 최종발표
웹 프로그래밍 팀프로젝트 최종발표웹 프로그래밍 팀프로젝트 최종발표
웹 프로그래밍 팀프로젝트 최종발표
 
오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS
 
Introduction To PostGIS
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGIS
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and BeforeUsage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
Usage and Comparisons of Control Group in Android AOSP: Marshmallow and Before
 
Customising QGroundControl
Customising QGroundControlCustomising QGroundControl
Customising QGroundControl
 

Android Jetpack Compose 簡介