SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
Declarative UIs with
Jetpack @Compose
Ramon Ribeiro Rabello
about.me/ramonrabello
Ramon Rabello
Android Developer
Motivation
The reasons behind Compose
Past mistakes - “API design is
building future regret”
~Chet Haase
View.java - The “God View” legacy
Weird inheritance
public class Button extends TextView {
Old View namings
public class Spinner extends AbsSpinner {
Old View namings
public class Spinner extends AbsSpinner {
DropDown
Old View namings
public class Spinner extends AbsSpinner {
ComboBox
Simplify building UI
Building UI is boilerplate
MyCustomView.[kt | java]
my_custom_view.xml
attrs.xml
style.xml
Building UI is boilerplate
MyCustomView.[kt | java]
my_custom_view.xml
attrs.xml
style.xml
Building UI is boilerplate
MyCustomView.[kt | java]
my_custom_view.xml
attrs.xml
style.xml
Building UI is boilerplate
MyCustomView.[kt | java]
my_custom_view.xml
attrs.xml
style.xml
Presentation architectures
Presentation Architectures
MVC
MVP
MVVM
MVI
Presentation Architectures Data Flow questions
- What is the source of truth?
Presentation Architectures Data Flow questions
- What is the source of truth?
- Who is the owner?
Presentation Architectures Data Flow questions
- What is the source of truth?
- Who is the owner?
- Who can change it?
Spinner: the weirdest case
public class MainActivity extends AppCompatActivity
implements Spinner.OnItemChangedListener {
What is the source of truth?
Who is the owner?
Who can change it?
onItemStateChanged() will be called after the event has happened
It turns out that android.widget
mixes state ownership and event
handling concepts
New UI toolkit goals
- Unbundled from platform releases (AndroidX)
- Fewer technology stack flowcharts (Custom View? Fragment?)
- Distinguish state ownership and event handling
- Write less code
What about building UI as simple as printing lines?
fun main(){
println("Hello Jetpack Compose")
}
Jetpack Compose
goes on stage
Introducing Jetpack Compose
What is Compose?
- Unbundled new set of UI widgets
- Inspired by React, Litho, Vue.js, Flutter
- A Kotlin compiler plugin
- Fully compatible with existing app code
- Experimental (0.1.0-dev02) - ** not ready for production yet **
Jetpack Compose Principles
UI as a function
@Composable
fun Hello(name: String){
Text(“Hello $name”)
}
Qualifier for Composables
Intercept and recompose the UI
tree
UI as a function (List of Composables)
@Composable
fun Trendings(newsList: List<News>){
for (news in newsList) {
NewsCard(news)
}
}
UI as a function (Dynamic composables)
@Composable
fun Trendings(news: List<News>){
if (news.isEmpty()) {
Text("You have no news today.")
} else {
NewsCard(news)
}
}
Composable building blocks
@Composable
fun Counter(model: CounterModel){
CounterTitle(model)
CounterContent(model)
CounterButtons(model)
}
@Composable
fun CounterHeader(model: CounterModel)
@Composable
fun CounterContent(model: CounterModel)
@Composable
fun CounterButtons(model: CounterModel)
Reactive UI upon model changes
@Composable
fun Counter(){
val model = CounterModel()
Column { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
@Model
data class CounterModel(var value: Int = 0) {
fun increment() = value++
}
Indicates that composable updates
upon model changes
Top-down Data Flow
DataEvent
Top-down Data Flow
@Composable
fun Counter(model: CounterModel){
Column { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
@Model
data class CounterModel(var value: Int = 0) {
fun increment() = value++
}
Data
Top-down Data Flow
@Composable
fun Counter(model: CounterModel){
Column { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
@Model
data class CounterModel(var value: Int = 0) {
fun increment() = value++
}
Data
Top-down Data Flow
@Composable
fun Counter(model: CounterModel){
Column { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
@Model
data class CounterModel(var value: Int = 0) {
fun increment() = value++
}
Data
Top-down Data Flow
@Composable
fun Counter(model: CounterModel){
Column { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
@Model
data class CounterModel(var value: Int = 0) {
fun increment() = value++
}
Event
Getting Started
Download Android Studio
3.5+
(Gradle dependencies)
AS 4.0 Canary 1
(Built-in Compose Support)
UPDATE:
Add compose dev preview dependencies
def compose_version = '0.1.0-dev02'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
implementation "androidx.compose:compose-runtime:$compose_version"
kapt "androidx.compose:compose-compiler:$compose_version"
implementation "androidx.ui:ui-layout:$compose_version"
implementation "androidx.ui:ui-android-text:$compose_version"
Add compose dev preview dependencies
def compose_version = '0.1.0-dev02'
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
implementation "androidx.compose:compose-runtime:$compose_version"
kapt "androidx.compose:compose-compiler:$compose_version"
implementation "androidx.ui:ui-layout:$compose_version"
implementation "androidx.ui:ui-android-text:$compose_version"
AS 4.0 Canary 1 - Create Composable Activity
Create a @Composable
@Composable
fun Counter() = MaterialTheme {
val model = CounterModel()
Row { Button(“Count”, onClick = { model.increment() }) }
Text(“Counter: ${model.value}”)
}
Add a @Model to represent the composable state
@Model
data class CounterModel(var value: Int = 0) {
fun hitCount() = value++
}
Enclose root composable inside setContent{ }
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { Counter() }
}
}
Demo
What’s Next?
Learn more about Jetpack Compose
Learn more about Jetpack Compose
Jetpack Compose | Android Developers
Playing with Jetpack Compose dev preview
Diving into Jetpack Compose - Q42 Engineering - Medium
Declarative UI Patterns - Google I/O 2019
Android Jetpack Compose Review - Karumi Blog
https://www.github.com/ramonrabello/Compose-Counter
Thank you!
about.me/ramonrabello

Weitere ähnliche Inhalte

Was ist angesagt?

Jetpack compose
Jetpack composeJetpack compose
Jetpack composeLutasLin
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptxGDSCVJTI
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIGilang Ramadhan
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdfSumirVats
 
Jetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidJetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidNelson Glauber Leal
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack Tudor Sirbu
 
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...JassGroup TICS
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaJAX London
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftCommit University
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUIBongwon Lee
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room LibraryReinvently
 

Was ist angesagt? (20)

Jetpack compose
Jetpack composeJetpack compose
Jetpack compose
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UI
 
Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdf
 
Jetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidJetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no Android
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack
 
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Kotlin Multiplatform
Kotlin MultiplatformKotlin Multiplatform
Kotlin Multiplatform
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Android MVVM
Android MVVMAndroid MVVM
Android MVVM
 
React Native
React NativeReact Native
React Native
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
 

Ähnlich wie Declarative UIs with Jetpack Compose

Android DataBinding (ViewModel, UI Modularization and Testing)
Android DataBinding (ViewModel, UI Modularization and Testing)Android DataBinding (ViewModel, UI Modularization and Testing)
Android DataBinding (ViewModel, UI Modularization and Testing)Yongjun Kim
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RPaul Richards
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)Andrey Volobuev
 
How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builderMaurizio Vitale
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentanistar sung
 
Linguistic Abstraction for the Web
Linguistic Abstraction for the WebLinguistic Abstraction for the Web
Linguistic Abstraction for the WebEelco Visser
 
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan s.r.o.
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisDroidConTLV
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)Beau Lebens
 

Ähnlich wie Declarative UIs with Jetpack Compose (20)

mobl
moblmobl
mobl
 
Android DataBinding (ViewModel, UI Modularization and Testing)
Android DataBinding (ViewModel, UI Modularization and Testing)Android DataBinding (ViewModel, UI Modularization and Testing)
Android DataBinding (ViewModel, UI Modularization and Testing)
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in R
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)
 
shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
 
How to create an Angular builder
How to create an Angular builderHow to create an Angular builder
How to create an Angular builder
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
Linguistic Abstraction for the Web
Linguistic Abstraction for the WebLinguistic Abstraction for the Web
Linguistic Abstraction for the Web
 
SCALA - Functional domain
SCALA -  Functional domainSCALA -  Functional domain
SCALA - Functional domain
 
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 

Mehr von Ramon Ribeiro Rabello

Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondRamon Ribeiro Rabello
 
Create Modern Apps with Android Jetpack
Create Modern Apps with Android JetpackCreate Modern Apps with Android Jetpack
Create Modern Apps with Android JetpackRamon Ribeiro Rabello
 
Ninja Productivity in Android Studio
Ninja Productivity in Android StudioNinja Productivity in Android Studio
Ninja Productivity in Android StudioRamon Ribeiro Rabello
 
Produtividade ninja com android studio
Produtividade ninja com android studioProdutividade ninja com android studio
Produtividade ninja com android studioRamon Ribeiro Rabello
 
Automatize seus testes de UI com a Espresso!
Automatize seus testes de UI com a Espresso!Automatize seus testes de UI com a Espresso!
Automatize seus testes de UI com a Espresso!Ramon Ribeiro Rabello
 
Os caminhos da Agilidade em Empresa Pública
Os caminhos da Agilidade em Empresa PúblicaOs caminhos da Agilidade em Empresa Pública
Os caminhos da Agilidade em Empresa PúblicaRamon Ribeiro Rabello
 
Making your app see with Mobile Vision API
Making your app see with Mobile Vision APIMaking your app see with Mobile Vision API
Making your app see with Mobile Vision APIRamon Ribeiro Rabello
 
Inovar em tempos de crise? Yes, We Can!
Inovar em tempos de crise?  Yes, We Can!Inovar em tempos de crise?  Yes, We Can!
Inovar em tempos de crise? Yes, We Can!Ramon Ribeiro Rabello
 
Android Wear: Estendendo sua app para relógios inteligentes
Android Wear: Estendendo sua app para relógios inteligentesAndroid Wear: Estendendo sua app para relógios inteligentes
Android Wear: Estendendo sua app para relógios inteligentesRamon Ribeiro Rabello
 
O caminho de um desenvolvedor android
O caminho de um desenvolvedor androidO caminho de um desenvolvedor android
O caminho de um desenvolvedor androidRamon Ribeiro Rabello
 
Workshop Android em Ambientes de Integração
Workshop Android em Ambientes de IntegraçãoWorkshop Android em Ambientes de Integração
Workshop Android em Ambientes de IntegraçãoRamon Ribeiro Rabello
 
De idealista à empreendedor - como desenvolver aplicações em android que conq...
De idealista à empreendedor - como desenvolver aplicações em android que conq...De idealista à empreendedor - como desenvolver aplicações em android que conq...
De idealista à empreendedor - como desenvolver aplicações em android que conq...Ramon Ribeiro Rabello
 
Agora é Android, Tá Safo? - #tasafoemacaocastanhal
Agora é Android, Tá Safo? - #tasafoemacaocastanhalAgora é Android, Tá Safo? - #tasafoemacaocastanhal
Agora é Android, Tá Safo? - #tasafoemacaocastanhalRamon Ribeiro Rabello
 

Mehr von Ramon Ribeiro Rabello (20)

Android Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyondAndroid Jetpack + Coroutines: To infinity and beyond
Android Jetpack + Coroutines: To infinity and beyond
 
Create Modern Apps with Android Jetpack
Create Modern Apps with Android JetpackCreate Modern Apps with Android Jetpack
Create Modern Apps with Android Jetpack
 
Cultura de testes em times mobile
Cultura de testes em times mobileCultura de testes em times mobile
Cultura de testes em times mobile
 
Ninja Productivity in Android Studio
Ninja Productivity in Android StudioNinja Productivity in Android Studio
Ninja Productivity in Android Studio
 
Produtividade ninja com android studio
Produtividade ninja com android studioProdutividade ninja com android studio
Produtividade ninja com android studio
 
Automatize seus testes de UI com a Espresso!
Automatize seus testes de UI com a Espresso!Automatize seus testes de UI com a Espresso!
Automatize seus testes de UI com a Espresso!
 
Os caminhos da Agilidade em Empresa Pública
Os caminhos da Agilidade em Empresa PúblicaOs caminhos da Agilidade em Empresa Pública
Os caminhos da Agilidade em Empresa Pública
 
Making your app see with Mobile Vision API
Making your app see with Mobile Vision APIMaking your app see with Mobile Vision API
Making your app see with Mobile Vision API
 
Inovar em tempos de crise? Yes, We Can!
Inovar em tempos de crise?  Yes, We Can!Inovar em tempos de crise?  Yes, We Can!
Inovar em tempos de crise? Yes, We Can!
 
O ecossistema android
O ecossistema androidO ecossistema android
O ecossistema android
 
Android Marshmallow na prática
Android Marshmallow na práticaAndroid Marshmallow na prática
Android Marshmallow na prática
 
Android Wear: Estendendo sua app para relógios inteligentes
Android Wear: Estendendo sua app para relógios inteligentesAndroid Wear: Estendendo sua app para relógios inteligentes
Android Wear: Estendendo sua app para relógios inteligentes
 
Introdução ao Android Studio
Introdução ao Android StudioIntrodução ao Android Studio
Introdução ao Android Studio
 
O caminho de um desenvolvedor android
O caminho de um desenvolvedor androidO caminho de um desenvolvedor android
O caminho de um desenvolvedor android
 
Criando Apps Sociais em Android
Criando Apps Sociais em AndroidCriando Apps Sociais em Android
Criando Apps Sociais em Android
 
Porque Aprender Android
Porque Aprender AndroidPorque Aprender Android
Porque Aprender Android
 
Workshop Android em Ambientes de Integração
Workshop Android em Ambientes de IntegraçãoWorkshop Android em Ambientes de Integração
Workshop Android em Ambientes de Integração
 
De idealista à empreendedor - como desenvolver aplicações em android que conq...
De idealista à empreendedor - como desenvolver aplicações em android que conq...De idealista à empreendedor - como desenvolver aplicações em android que conq...
De idealista à empreendedor - como desenvolver aplicações em android que conq...
 
Desenvolvimento Web para Android
Desenvolvimento Web para AndroidDesenvolvimento Web para Android
Desenvolvimento Web para Android
 
Agora é Android, Tá Safo? - #tasafoemacaocastanhal
Agora é Android, Tá Safo? - #tasafoemacaocastanhalAgora é Android, Tá Safo? - #tasafoemacaocastanhal
Agora é Android, Tá Safo? - #tasafoemacaocastanhal
 

Kürzlich hochgeladen

Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfCWS Technology
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Servicenishacall1
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 

Kürzlich hochgeladen (6)

Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 

Declarative UIs with Jetpack Compose

  • 1. Declarative UIs with Jetpack @Compose Ramon Ribeiro Rabello
  • 4. Past mistakes - “API design is building future regret” ~Chet Haase
  • 5. View.java - The “God View” legacy
  • 6. Weird inheritance public class Button extends TextView {
  • 7. Old View namings public class Spinner extends AbsSpinner {
  • 8. Old View namings public class Spinner extends AbsSpinner { DropDown
  • 9. Old View namings public class Spinner extends AbsSpinner { ComboBox
  • 11. Building UI is boilerplate MyCustomView.[kt | java] my_custom_view.xml attrs.xml style.xml
  • 12. Building UI is boilerplate MyCustomView.[kt | java] my_custom_view.xml attrs.xml style.xml
  • 13. Building UI is boilerplate MyCustomView.[kt | java] my_custom_view.xml attrs.xml style.xml
  • 14. Building UI is boilerplate MyCustomView.[kt | java] my_custom_view.xml attrs.xml style.xml
  • 17. Presentation Architectures Data Flow questions - What is the source of truth?
  • 18. Presentation Architectures Data Flow questions - What is the source of truth? - Who is the owner?
  • 19. Presentation Architectures Data Flow questions - What is the source of truth? - Who is the owner? - Who can change it?
  • 20. Spinner: the weirdest case public class MainActivity extends AppCompatActivity implements Spinner.OnItemChangedListener { What is the source of truth? Who is the owner? Who can change it? onItemStateChanged() will be called after the event has happened
  • 21. It turns out that android.widget mixes state ownership and event handling concepts
  • 22. New UI toolkit goals - Unbundled from platform releases (AndroidX) - Fewer technology stack flowcharts (Custom View? Fragment?) - Distinguish state ownership and event handling - Write less code
  • 23. What about building UI as simple as printing lines? fun main(){ println("Hello Jetpack Compose") }
  • 24. Jetpack Compose goes on stage Introducing Jetpack Compose
  • 25. What is Compose? - Unbundled new set of UI widgets - Inspired by React, Litho, Vue.js, Flutter - A Kotlin compiler plugin - Fully compatible with existing app code - Experimental (0.1.0-dev02) - ** not ready for production yet **
  • 27. UI as a function @Composable fun Hello(name: String){ Text(“Hello $name”) } Qualifier for Composables Intercept and recompose the UI tree
  • 28. UI as a function (List of Composables) @Composable fun Trendings(newsList: List<News>){ for (news in newsList) { NewsCard(news) } }
  • 29. UI as a function (Dynamic composables) @Composable fun Trendings(news: List<News>){ if (news.isEmpty()) { Text("You have no news today.") } else { NewsCard(news) } }
  • 30. Composable building blocks @Composable fun Counter(model: CounterModel){ CounterTitle(model) CounterContent(model) CounterButtons(model) } @Composable fun CounterHeader(model: CounterModel) @Composable fun CounterContent(model: CounterModel) @Composable fun CounterButtons(model: CounterModel)
  • 31. Reactive UI upon model changes @Composable fun Counter(){ val model = CounterModel() Column { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) } @Model data class CounterModel(var value: Int = 0) { fun increment() = value++ } Indicates that composable updates upon model changes
  • 33. Top-down Data Flow @Composable fun Counter(model: CounterModel){ Column { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) } @Model data class CounterModel(var value: Int = 0) { fun increment() = value++ } Data
  • 34. Top-down Data Flow @Composable fun Counter(model: CounterModel){ Column { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) } @Model data class CounterModel(var value: Int = 0) { fun increment() = value++ } Data
  • 35. Top-down Data Flow @Composable fun Counter(model: CounterModel){ Column { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) } @Model data class CounterModel(var value: Int = 0) { fun increment() = value++ } Data
  • 36. Top-down Data Flow @Composable fun Counter(model: CounterModel){ Column { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) } @Model data class CounterModel(var value: Int = 0) { fun increment() = value++ } Event
  • 38. Download Android Studio 3.5+ (Gradle dependencies) AS 4.0 Canary 1 (Built-in Compose Support) UPDATE:
  • 39. Add compose dev preview dependencies def compose_version = '0.1.0-dev02' implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50" implementation "androidx.compose:compose-runtime:$compose_version" kapt "androidx.compose:compose-compiler:$compose_version" implementation "androidx.ui:ui-layout:$compose_version" implementation "androidx.ui:ui-android-text:$compose_version"
  • 40. Add compose dev preview dependencies def compose_version = '0.1.0-dev02' implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50" implementation "androidx.compose:compose-runtime:$compose_version" kapt "androidx.compose:compose-compiler:$compose_version" implementation "androidx.ui:ui-layout:$compose_version" implementation "androidx.ui:ui-android-text:$compose_version"
  • 41. AS 4.0 Canary 1 - Create Composable Activity
  • 42. Create a @Composable @Composable fun Counter() = MaterialTheme { val model = CounterModel() Row { Button(“Count”, onClick = { model.increment() }) } Text(“Counter: ${model.value}”) }
  • 43. Add a @Model to represent the composable state @Model data class CounterModel(var value: Int = 0) { fun hitCount() = value++ }
  • 44. Enclose root composable inside setContent{ } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Counter() } } }
  • 45. Demo
  • 46. What’s Next? Learn more about Jetpack Compose
  • 47. Learn more about Jetpack Compose Jetpack Compose | Android Developers Playing with Jetpack Compose dev preview Diving into Jetpack Compose - Q42 Engineering - Medium Declarative UI Patterns - Google I/O 2019 Android Jetpack Compose Review - Karumi Blog https://www.github.com/ramonrabello/Compose-Counter