SlideShare a Scribd company logo
Reactive UI in Android
Composing a new UI toolkit (pun intended)
Gil Goldzweig Goldbaum
@GilLongName GilGoldzweig GilGoldzweig
We have cookies!
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in Android
Composing a new UI toolkit (pun intended)
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Jetpack Compose
Our current UI toolkit
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
AOSP View
TextView
Button
ViewGroup
FrameLayout LinearLayout EditText
Button
EditText
Layout XML
Using code
It wasn’t designed for it
android.view.View
android.view.ViewAndroid 1.6
TextViewButton extends
Spinner?
🤔
==
Spinner
Highest quality I found 😕
Android 0.8
Nov 5, 2007
android.view.ViewAndroid 4.2
Min SDK < 17 = No luck
😔
“API design is building future regret”
Chat haase
A fresh start
As part of JetPack family
Jetpack compose
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Declarative UI
● Take data as input
● Emits UI hierarchy when invoked
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Hello: Gil
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Hello: Rachel
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Hello: David
What is Compose?
Compiler plugin Runtime
Compiler plugin
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Composable functions are not
UI elements
Compiler plugin
@Composable
fun Greeting(name: String): Unit {
Text("Hello: $name")
}
What are composable functions?
Composable function
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Composable function
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Greeting
Composable function
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
}
Greeting
Text
Composable function
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
Text("Hello: $name")
}
Greeting
Text
Text
Composable function
Compiler plugin
@Composable
fun Greeting(name: String) {
Text("Hello: $name")
Text("Hello: $name")
}
Instructions tree
Greeting
Text
Text
Compose Runtime
Runtime
Takeaway
(10bis) mobile
app
Runtime
Takeaway
(10bis) mobile
app
Runtime
Compose
Jetnews app
Runtime
Compose
Jetnews app
Compose uses canvas under the
hood
AOSP View
TextView
Button
ViewGroup
FrameLayout EditTextLinearLayout
Button
EditText
Gradle dependency
Compose
Canvas
Surface Text VectorImage
@Composable
fun Button(text, onClick) {
}
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
}
}
Surface
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
}
}
}
Surface
Ripple
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
}
}
}
}
Surface
Ripple
Clickable
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
Container(padding = paddings) {
}
}
}
}
}
Surface
Ripple
Clickable
Container
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
Container(padding = paddings) {
Text(text)
}
}
}
}
}
Surface
Ripple
Clickable
Container
Text
Button
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
Container(padding = paddings) {
Text(text)
}
}
}
}
}
Surface
Ripple
Clickable
Container
Text
ImageButton
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
Container(padding = paddings) {
Image(image)
}
}
}
}
}
Surface
Ripple
Clickable
Container
Image
ImageButton
@Composable
fun Button(text, onClick) {
Surface(shape, color, border, elevation) {
Ripple(color = rippleColor) {
Clickable(onClick = onClick) {
Container(padding = paddings) {
Image(image)
}
}
}
}
}
Surface
Ripple
Clickable
Container
ImageButton
Image
fun Button
Reactive data flow
Reactive data flow
Data
Events
Spinner
Item Clicked
Selection
changed
We get
notified
Item Clicked
We get
notified
UI changes
Selection
updated
UI changes
Change
selection?
Current Compose
Reactive data flow
UIUpdate Data
Change UI
Reactive data flow
UIUpdate Data
✅
✅
Change data
Data changed,
Notifying UI
Reactive data flow
UIUpdate Data
Single source of truth
@Composable
fun Counter() {
}
Reactive data flow
@Composable
fun Counter() {
val count
}
Reactive data flow
@Composable
fun Counter() {
val count = 0
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
}
Reactive data flow
Should be treated
as an “observer”
@Composable
fun Counter() {
val count = state { 0 }
Column {
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
Single source of truth
@Composable
fun Counter() {
val count = state { 0 }
Column {
Text("Counter demo")
Button(text = "Add",
onClick = { count.value++ })
Button(text = "Subtract",
onClick = { count.value-- })
Text("Clicks: ${count.value}")
}
}
Reactive data flow
Jetpack compose
@Model
data class NewsModel(
var title: String,
var auther: String,
var imageUrl: String
)
@Model
@Model
data class NewsModel(
var title: String,
var auther: String,
var imageUrl: String
)
@Model
@Model
data class NewsModel(
var title: String,
var auther: String,
var imageUrl: String
)
data class NewsHolder(var news: List<NewsModel>)
@Model
@Model
data class NewsModel(
var title: String,
var auther: String,
var imageUrl: String
)
@Model
data class NewsHolder(var news: List<NewsModel>)
@Model
@Composable
fun NewsItem(model: NewsModel) {
}
@Model
@Composable
fun NewsItem(model: NewsModel) {
Row {
}
}
@Model
@Composable
fun NewsItem(model: NewsModel) {
Row {
Image(url = model.imageUrl)
}
}
@Model
@Composable
fun NewsItem(model: NewsModel) {
Row {
Image(url = model.imageUrl)
Column {
}
}
}
@Model
@Composable
fun NewsItem(model: NewsModel) {
Row {
Image(url = model.imageUrl)
Column {
Text(model.title)
}
}
}
@Model
@Composable
fun NewsItem(model: NewsModel) {
Row {
Image(url = model.imageUrl)
Column {
Text(model.title)
Text(model.auther, style = TextStyle(Color.Gray))
}
}
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
VerticalScroller {
}
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
VerticalScroller {
Column {
}
}
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
VerticalScroller {
Column {
holder.news.forEach { newsModel ->
}
}
}
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
VerticalScroller {
Column {
holder.news.forEach { newsModel ->
NewsItem(newsModel)
}
}
}
}
@Model
@Composable
fun NewsFeed(holder: NewsHolder) {
VerticalScroller {
Column {
holder.news.forEach { newsModel ->
NewsItem(newsModel)
Divider(height = 1.dp)
}
}
}
}
Jetpack compose
var newsHolder: NewsHolder
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
}
Jetpack compose
var newsHolder: NewsHolder
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
setContent {
}
}
Jetpack compose
var newsHolder: NewsHolder
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
setContent {
NewsFeed(newsHolder)
}
}
UI Repository
Presenter /
ViewModel
Jetpack compose
pullNews
newsPulled
fetchNews
onNewsFetched
override fun onNewsFetched(newsHolder: NewsHolder) {
}
Jetpack compose
override fun onNewsFetched(newsHolder: NewsHolder) {
this.newsHolder = newsHolder
}
Jetpack compose
override fun onUpdate() {
}
Jetpack compose
override fun onUpdate() {
newsHolder.news[0].title = "New title"
}
Jetpack compose
Compose can still work with the current
toolkit
@GenerateView
@Composable
fun NewsItem(model: NewsModel) {
...
}
@GenerateView
@Composable
@GenerateView
fun NewsItem(model: NewsModel) {
...
}
@GenerateView
Final notes
Compose is not
production ready!!!!!!!!!!
Available in Android
studio 4+
Compose’s slack
channel
Questions?
Thank you

More Related Content

PDF
Jetpack Compose a new way to implement UI on Android
PDF
Jetpack Compose - Hands-on February 2020
PDF
Android Jetpack Compose - Turkey 2021
PDF
Jetpack Compose - A Lightning Tour
PDF
Software Language Design & Engineering
PDF
Web 2 | CSS - Cascading Style Sheets
PDF
jQuery Rescue Adventure
PDF
Type safe embedded domain-specific languages
Jetpack Compose a new way to implement UI on Android
Jetpack Compose - Hands-on February 2020
Android Jetpack Compose - Turkey 2021
Jetpack Compose - A Lightning Tour
Software Language Design & Engineering
Web 2 | CSS - Cascading Style Sheets
jQuery Rescue Adventure
Type safe embedded domain-specific languages

What's hot (20)

PPT
J Query Public
PDF
A proper introduction to Elm
PPT
PDF
Html css
PDF
Introduzione JQuery
PDF
CSS3 Refresher
PDF
Ruby sittin' on the Couch
PDF
HTML5 and CSS3 Refresher
PDF
HTML5 Canvas - The Future of Graphics on the Web
PPTX
AngularJS
PPT
ODP
Drupal Best Practices
PPTX
jQuery Data Manipulate API - A source code dissecting journey
PDF
Coffeescript a z
PDF
jQuery - Chapter 4 - DOM Handling
PDF
JDD 2013 JavaFX
PPTX
Dartprogramming
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
PPTX
jQuery, CSS3 and ColdFusion
J Query Public
A proper introduction to Elm
Html css
Introduzione JQuery
CSS3 Refresher
Ruby sittin' on the Couch
HTML5 and CSS3 Refresher
HTML5 Canvas - The Future of Graphics on the Web
AngularJS
Drupal Best Practices
jQuery Data Manipulate API - A source code dissecting journey
Coffeescript a z
jQuery - Chapter 4 - DOM Handling
JDD 2013 JavaFX
Dartprogramming
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
jQuery, CSS3 and ColdFusion
Ad

Similar to Reactive UI in android - Gil Goldzweig Goldbaum, 10bis (20)

PDF
Declarative UIs with Jetpack Compose
PDF
compose_speaker_session.pdf
PPTX
JavaScript Objects and OOP Programming with JavaScript
PDF
Android DataBinding (ViewModel, UI Modularization and Testing)
PDF
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
PDF
mobl
PDF
Violet Peña - Storybook: A React Tool For Your Whole Team
PDF
Reactive Programming in the Browser feat. Scala.js and Rx
DOCX
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
PDF
PDF
MOPCON 2014 - Best software architecture in app development
PDF
mobl presentation @ IHomer
PPTX
Compose camp 2.pptx
PPTX
Day3.pptx
PDF
The Ring programming language version 1.5.1 book - Part 41 of 180
PPT
Scripting languages
KEY
Scala on Your Phone
PPTX
Kotlin Mullets
PDF
The Ring programming language version 1.4 book - Part 12 of 30
PDF
Connect.js - Exploring React.Native
Declarative UIs with Jetpack Compose
compose_speaker_session.pdf
JavaScript Objects and OOP Programming with JavaScript
Android DataBinding (ViewModel, UI Modularization and Testing)
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
mobl
Violet Peña - Storybook: A React Tool For Your Whole Team
Reactive Programming in the Browser feat. Scala.js and Rx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
MOPCON 2014 - Best software architecture in app development
mobl presentation @ IHomer
Compose camp 2.pptx
Day3.pptx
The Ring programming language version 1.5.1 book - Part 41 of 180
Scripting languages
Scala on Your Phone
Kotlin Mullets
The Ring programming language version 1.4 book - Part 12 of 30
Connect.js - Exploring React.Native
Ad

More from DroidConTLV (20)

PDF
Mobile Development in the Information Age - Yossi Elkrief, Nike
PDF
Doing work in the background - Darryn Campbell, Zebra Technologies
PDF
No more video loss - Alex Rivkin, Motorola Solutions
PDF
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
PDF
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
PDF
MVVM In real life - Lea Cohen Tannoudji, Lightricks
PDF
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
PDF
Building Apps with Flutter - Hillel Coren, Invoice Ninja
PDF
New Android Project: The Most Important Decisions - Vasiliy Zukanov
PDF
Designing a Design System - Shai Mishali, Gett
PDF
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
PDF
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
PDF
Flutter State Management - Moti Bartov, Tikal
PDF
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
PDF
DroidconTLV 2019
PDF
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
PDF
Introduction to React Native - Lev Vidrak, Wix
PDF
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
PDF
Educating your app – adding ML edge to your apps - Maoz Tamir
PDF
Constraint-ly motion - making your app dance - John Hoford, Google
Mobile Development in the Information Age - Yossi Elkrief, Nike
Doing work in the background - Darryn Campbell, Zebra Technologies
No more video loss - Alex Rivkin, Motorola Solutions
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
MVVM In real life - Lea Cohen Tannoudji, Lightricks
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Building Apps with Flutter - Hillel Coren, Invoice Ninja
New Android Project: The Most Important Decisions - Vasiliy Zukanov
Designing a Design System - Shai Mishali, Gett
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Flutter State Management - Moti Bartov, Tikal
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidconTLV 2019
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Introduction to React Native - Lev Vidrak, Wix
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Educating your app – adding ML edge to your apps - Maoz Tamir
Constraint-ly motion - making your app dance - John Hoford, Google

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
PPT
Teaching material agriculture food technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
Teaching material agriculture food technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)

Reactive UI in android - Gil Goldzweig Goldbaum, 10bis