SlideShare a Scribd company logo
Jetpack Compose
A lightning tour
GDG Auckland - May 2019
Disclaimer
• I’m not an expert on any of this :)

• This is the result of building the sample, exploring source
code and some reading

• Flutter and React devs - feel free to speak up

• Compose is pre-alpha and not ready for production
What is it?
• A “…modern, reactive style UI toolkit for Android, which takes advantage
of Kotlin and integrates seamlessly with the platform and all of your
existing code.”

• Declarative - “Simply describe your UI as a set of composable functions,
and the framework handles UI optimizations under the hood and
automatic updates to the view hierarchy.”

• Inspired by/similar to Flutter, React, Litho

• Way to allow the Android UI Framework to evolve, unbundled from
platform releases

• Create smaller, reusable UI components by composing lower-level UI
components, e.g.:
Composable UI
components
/**
* The Bills card within the Rally Overview screen.
*/
@Composable
fun RallyBillsCard() {
Card(color = cardInternalColor) {
Column {
Padding(padding = 12.dp) {
Column {
Text(text = "Bills", style = +themeTextStyle { subtitle2 })
Text(text = "$1,810.00", style = +themeTextStyle { h1 })
}
}
}
}
}
Counter app
class CounterActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CraneWrapper {
CounterApp()
}
}
}
@Composable
fun CounterApp() {
val counter = +state { 0 }
MaterialTheme {
Button(onClick = { counter.value++ }) {
Text(text = "Counter = ${counter.value}")
}
}
}
}
Q: Wtf is going on here:

val counter = +state { 0 }
@Composable
fun CounterApp() {
val counter = +state { 0 }
MaterialTheme {
Button(onClick = { counter.value++ }) {
Text(text = "Counter = ${counter.value}")
}
}
}
Q: Wtf is going on here:

val counter = +state { 0 }
@Composable
fun CounterApp() {
val result: Effect<State<Int>> = state { 0 }
val counter: State<Int> = +result
MaterialTheme {
Button(onClick = { counter.value++ }) {
Text(text = "Counter = ${counter.value}")
}
}
}
Q: Are components just implemented
with Fragments/Views?
• No*, widgets are just functions that ultimately make
canvas draw calls.
@Composable
fun ColoredRect(brush: Brush, width: Dp? = null, height: Dp? = null) {
Container(width = width, height = height, expanded = true) {
DrawFillRect(brush = brush)
}
}
@Composable
private fun DrawFillRect(brush: Brush) {
Draw { canvas, parentSize ->
val paint = Paint()
brush.applyBrush(paint)
canvas.drawRect(parentSize.toRect(), paint)
}
}
Tangent: KTX tags (?!)
@Composable
fun Draw(
children: @Composable() () -> Unit = {},
@Children(composable = false)
onPaint: DrawScope.(canvas: Canvas, parentSize: PxSize) -> Unit
) {
// Hide the internals of DrawNode
<DrawNode onPaint={ canvas, parentSize ->
DrawScope(this).onPaint(canvas, parentSize)
}>
children()
</DrawNode>
}
Tangent: KTX tags (?!)
Tangent: KTX tags (?!)
@Composable
fun RallyApp() {
val counter = +state { 0 }
RallyTheme {
Scaffold(appBar = { RallyAppBar() }) {
Padding(padding = 16.dp) {
Button(onClick = { counter.value++ }) {
Text(text = "Counter = ${counter.value}",
style = +themeTextStyle { h3 })
}
}
}
}
}
Tangent: KTX tags (?!)
@Composable
fun RallyApp() {
val counter = +state { 0 }
<RallyTheme>
<Scaffold appBar={ <RallyAppBar /> }>
<Padding padding=16.dp>
<Button onClick={ counter.value++ }>
<Text text="Counter = ${counter.value}"
style=+themeTextStyle { h3 } />
</Button>
</Padding>
</Scaffold>
</RallyTheme>
}
Automatic XML -> KTX
conversion
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello world!"/>
</LinearLayout>
Automatic XML -> KTX
conversion
Automatic XML -> KTX
conversion (kinda…)
Q: Are components just implemented
with Fragments/Views?
• No*, widgets are just functions that ultimately make
canvas draw calls.

• *In practise, you need at least one special View:
AndroidCraneView
• Typically you won’t create this directly, but via
CraneWrapper, e.g.:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CraneWrapper {
RallyApp()
}
}
}
Q: How do I check it out?
• Short answer - follow this guide: https://medium.com/
q42-engineering/try-jetpack-compose-today-
a12bda50aed2
Q: How do I check it out?
Longer answer:

• Get a Repo client (Google’s VCS)

• Check out the androidx branch of AOSP (~3GB)

• Run a script to DL/build a custom unstable version of
Android Studio (30min+)

• Play with the sample projects
Further Reading/Watching
• Diving into Jetpack Compose - Thijs Suijten

https://medium.com/q42-engineering/android-jetpack-
compose-895b7fd04bf4

• Android Jetpack Compose Review - Karumi. Mentions some
areas for improvement

https://blog.karumi.com/android-jetpack-compose-review/

• Android developers page

https://developer.android.com/jetpack/compose

• Declarative UI Patterns (Google I/O’19)

https://youtu.be/VsStyq4Lzxo
Thank you
Questions, opinions, further thoughts?
Matt Clarke

Twitter: @kiwiandroiddev

More Related Content

PPTX
Jetpack Compose.pptx
PDF
Jetpack Compose a new way to implement UI on Android
PDF
Declarative UIs with Jetpack Compose
PPTX
Android jetpack compose | Declarative UI
PDF
Android Jetpack Compose - Turkey 2021
PDF
Jetpack compose
PDF
Try Jetpack Compose
PDF
Jetpack Compose.pdf
Jetpack Compose.pptx
Jetpack Compose a new way to implement UI on Android
Declarative UIs with Jetpack Compose
Android jetpack compose | Declarative UI
Android Jetpack Compose - Turkey 2021
Jetpack compose
Try Jetpack Compose
Jetpack Compose.pdf

What's hot (20)

PPTX
Kotlin Jetpack Tutorial
PDF
Jetpack Compose a nova forma de implementar UI no Android
PPTX
Kotlin Basics & Introduction to Jetpack Compose.pptx
PDF
Introduction to kotlin
PDF
Jetpack Compose beginner.pdf
PPTX
Jetpack Compose - Android’s modern toolkit for building native UI
PDF
Android Jetpack
PPTX
JS Event Loop
PPTX
Introduction to Kotlin for Android developers
PPTX
React + Redux + TypeScript === ♥
PDF
C# Delegates and Event Handling
PDF
Flask for cs students
PPTX
Kotlin presentation
PPTX
Coroutines in Kotlin
PPTX
reactJS
PDF
Introduction to react native
PDF
Kotlin Coroutines in Practice @ KotlinConf 2018
PDF
Spring Framework - Core
PDF
Flask Introduction - Python Meetup
PDF
Java 8 Lambda Built-in Functional Interfaces
Kotlin Jetpack Tutorial
Jetpack Compose a nova forma de implementar UI no Android
Kotlin Basics & Introduction to Jetpack Compose.pptx
Introduction to kotlin
Jetpack Compose beginner.pdf
Jetpack Compose - Android’s modern toolkit for building native UI
Android Jetpack
JS Event Loop
Introduction to Kotlin for Android developers
React + Redux + TypeScript === ♥
C# Delegates and Event Handling
Flask for cs students
Kotlin presentation
Coroutines in Kotlin
reactJS
Introduction to react native
Kotlin Coroutines in Practice @ KotlinConf 2018
Spring Framework - Core
Flask Introduction - Python Meetup
Java 8 Lambda Built-in Functional Interfaces
Ad

Similar to Jetpack Compose - A Lightning Tour (20)

PDF
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
PPTX
Compose UI
PDF
What's new in android: jetpack compose 2024
PPTX
Compose in Theory
PDF
Mobile Programming - 2 Jetpack Compose
PPTX
Modern app development with Jetpack Compose.pptx
PDF
compose_speaker_session.pdf
PPTX
Compose camp 2.pptx
PDF
Compose Camp Day 3 PPT.pptx.pdf
PDF
Jetpack joyride!
PDF
ANDROID.pdf
PDF
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
PDF
Introduction to React Native Workshop
PDF
Kotlin talk
PDF
Building Modern Apps using Android Architecture Components
PPTX
Compose In Practice
PDF
Jetpack Compose - Hands-on February 2020
PDF
Mobile Programming - 5 Stylling Text and State
PDF
COMPOSE CAMP SESSION 4.pdf
PDF
Android Jetpack - Google IO Extended Singapore 2018
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Compose UI
What's new in android: jetpack compose 2024
Compose in Theory
Mobile Programming - 2 Jetpack Compose
Modern app development with Jetpack Compose.pptx
compose_speaker_session.pdf
Compose camp 2.pptx
Compose Camp Day 3 PPT.pptx.pdf
Jetpack joyride!
ANDROID.pdf
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Introduction to React Native Workshop
Kotlin talk
Building Modern Apps using Android Architecture Components
Compose In Practice
Jetpack Compose - Hands-on February 2020
Mobile Programming - 5 Stylling Text and State
COMPOSE CAMP SESSION 4.pdf
Android Jetpack - Google IO Extended Singapore 2018
Ad

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
top salesforce developer skills in 2025.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
history of c programming in notes for students .pptx
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PPT
Introduction Database Management System for Course Database
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
top salesforce developer skills in 2025.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How Creative Agencies Leverage Project Management Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
history of c programming in notes for students .pptx
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
Introduction Database Management System for Course Database
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Operating system designcfffgfgggggggvggggggggg
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo Companies in India – Driving Business Transformation.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Online Work Permit System for Fast Permit Processing
ISO 45001 Occupational Health and Safety Management System
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

Jetpack Compose - A Lightning Tour

  • 1. Jetpack Compose A lightning tour GDG Auckland - May 2019
  • 2. Disclaimer • I’m not an expert on any of this :) • This is the result of building the sample, exploring source code and some reading • Flutter and React devs - feel free to speak up • Compose is pre-alpha and not ready for production
  • 3. What is it? • A “…modern, reactive style UI toolkit for Android, which takes advantage of Kotlin and integrates seamlessly with the platform and all of your existing code.” • Declarative - “Simply describe your UI as a set of composable functions, and the framework handles UI optimizations under the hood and automatic updates to the view hierarchy.” • Inspired by/similar to Flutter, React, Litho • Way to allow the Android UI Framework to evolve, unbundled from platform releases • Create smaller, reusable UI components by composing lower-level UI components, e.g.:
  • 4. Composable UI components /** * The Bills card within the Rally Overview screen. */ @Composable fun RallyBillsCard() { Card(color = cardInternalColor) { Column { Padding(padding = 12.dp) { Column { Text(text = "Bills", style = +themeTextStyle { subtitle2 }) Text(text = "$1,810.00", style = +themeTextStyle { h1 }) } } } } }
  • 5. Counter app class CounterActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CraneWrapper { CounterApp() } } } @Composable fun CounterApp() { val counter = +state { 0 } MaterialTheme { Button(onClick = { counter.value++ }) { Text(text = "Counter = ${counter.value}") } } } }
  • 6. Q: Wtf is going on here:
 val counter = +state { 0 } @Composable fun CounterApp() { val counter = +state { 0 } MaterialTheme { Button(onClick = { counter.value++ }) { Text(text = "Counter = ${counter.value}") } } }
  • 7. Q: Wtf is going on here:
 val counter = +state { 0 } @Composable fun CounterApp() { val result: Effect<State<Int>> = state { 0 } val counter: State<Int> = +result MaterialTheme { Button(onClick = { counter.value++ }) { Text(text = "Counter = ${counter.value}") } } }
  • 8. Q: Are components just implemented with Fragments/Views? • No*, widgets are just functions that ultimately make canvas draw calls.
  • 9. @Composable fun ColoredRect(brush: Brush, width: Dp? = null, height: Dp? = null) { Container(width = width, height = height, expanded = true) { DrawFillRect(brush = brush) } } @Composable private fun DrawFillRect(brush: Brush) { Draw { canvas, parentSize -> val paint = Paint() brush.applyBrush(paint) canvas.drawRect(parentSize.toRect(), paint) } }
  • 10. Tangent: KTX tags (?!) @Composable fun Draw( children: @Composable() () -> Unit = {}, @Children(composable = false) onPaint: DrawScope.(canvas: Canvas, parentSize: PxSize) -> Unit ) { // Hide the internals of DrawNode <DrawNode onPaint={ canvas, parentSize -> DrawScope(this).onPaint(canvas, parentSize) }> children() </DrawNode> }
  • 12. Tangent: KTX tags (?!) @Composable fun RallyApp() { val counter = +state { 0 } RallyTheme { Scaffold(appBar = { RallyAppBar() }) { Padding(padding = 16.dp) { Button(onClick = { counter.value++ }) { Text(text = "Counter = ${counter.value}", style = +themeTextStyle { h3 }) } } } } }
  • 13. Tangent: KTX tags (?!) @Composable fun RallyApp() { val counter = +state { 0 } <RallyTheme> <Scaffold appBar={ <RallyAppBar /> }> <Padding padding=16.dp> <Button onClick={ counter.value++ }> <Text text="Counter = ${counter.value}" style=+themeTextStyle { h3 } /> </Button> </Padding> </Scaffold> </RallyTheme> }
  • 14. Automatic XML -> KTX conversion <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello world!"/> </LinearLayout>
  • 15. Automatic XML -> KTX conversion
  • 16. Automatic XML -> KTX conversion (kinda…)
  • 17. Q: Are components just implemented with Fragments/Views? • No*, widgets are just functions that ultimately make canvas draw calls. • *In practise, you need at least one special View: AndroidCraneView • Typically you won’t create this directly, but via CraneWrapper, e.g.: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CraneWrapper { RallyApp() } } }
  • 18. Q: How do I check it out? • Short answer - follow this guide: https://medium.com/ q42-engineering/try-jetpack-compose-today- a12bda50aed2
  • 19. Q: How do I check it out? Longer answer: • Get a Repo client (Google’s VCS) • Check out the androidx branch of AOSP (~3GB) • Run a script to DL/build a custom unstable version of Android Studio (30min+) • Play with the sample projects
  • 20. Further Reading/Watching • Diving into Jetpack Compose - Thijs Suijten
 https://medium.com/q42-engineering/android-jetpack- compose-895b7fd04bf4 • Android Jetpack Compose Review - Karumi. Mentions some areas for improvement
 https://blog.karumi.com/android-jetpack-compose-review/ • Android developers page
 https://developer.android.com/jetpack/compose • Declarative UI Patterns (Google I/O’19)
 https://youtu.be/VsStyq4Lzxo
  • 21. Thank you Questions, opinions, further thoughts? Matt Clarke
 Twitter: @kiwiandroiddev