SlideShare a Scribd company logo
1 of 48
Download to read offline
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

More Related Content

What's hot

Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdfSumirVats
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdfAayushmaAgrawal
 
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 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
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
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
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
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
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized projectFabio Collini
 
MVVM with SwiftUI and Combine
MVVM with SwiftUI and CombineMVVM with SwiftUI and Combine
MVVM with SwiftUI and CombineTai Lun Tseng
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation MobileAcademy
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 

What's hot (20)

Jetpack Compose.pdf
Jetpack Compose.pdfJetpack Compose.pdf
Jetpack Compose.pdf
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
 
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 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
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
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...
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
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
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized project
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
MVVM with SwiftUI and Combine
MVVM with SwiftUI and CombineMVVM with SwiftUI and Combine
MVVM with SwiftUI and Combine
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
React hooks
React hooksReact hooks
React hooks
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 

Similar to 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
 
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
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 

Similar to 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
 
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
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 

More from 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
 

More from 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
 

Recently uploaded

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
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
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
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
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
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 

Recently uploaded (7)

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
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
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
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
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
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 

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