Slide 1

Slide 1 text

Jetpack Compose: The new Way of Building Android UI Umar Saidu Auna Software Engineer, gidimo, A tech community organizer. Kano @umarauna

Slide 2

Slide 2 text

Challenges

Slide 3

Slide 3 text

Challenges findViewById() – XML data binding and view binding APIs are showing signs of ageing RecyclerView View Class keeps getting bigger and bigger ...

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Jetpack Compose

Slide 6

Slide 6 text

Jetpack Compose Modern toolkit for building native Android UI. Jetpack Compose simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Inspired by 1. React 2. Litho 3. Vue.js 4. Flutter ... but it’s written completely in Kotlin and is fully compatible with the existing Android view system.

Slide 10

Slide 10 text

Declarative UI

Slide 11

Slide 11 text

Declarative UI Declarative UI is a UI that’s designed in a declarative way. You describe what it should be like.

Slide 12

Slide 12 text

Declarative This pattern is an emerging trend that allows the developers to design the user interface based on the data received. This is the most common paradigm; it involves having a separate prototype/model of the application’s UI. Imperative

Slide 13

Slide 13 text

Declarative This design paradigm makes use of one programming language to create an entire application. A good example is XML layouts in Android. We design the widgets and components which are then rendered for the user to see and interact with. Imperative

Slide 14

Slide 14 text

Declarative This on the other hand focuses on the what This design focuses on the how rather than the what Imperative

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

“Everything is a function”

Slide 18

Slide 18 text

Compose Everywhere View/XML -> UI as Objects Compose -> UI as Function

Slide 19

Slide 19 text

Goal ● Simplify ● Less code ● Fix what’s broken

Slide 20

Slide 20 text

Components ● Layouts ○ Column ○ Row ○ Flex(column/row) ○ Box(similar to Framelayout) ○ ConstraintLayout(almost done)

Slide 21

Slide 21 text

Components ● Built-in Components ○ Button ○ Text ○ Checkbox ○ Navigation Drawer ○ Navigation Bar ○ Checkbox ○ AppBar

Slide 22

Slide 22 text

Components ● Custom View ○ Draw ○ Layout

Slide 23

Slide 23 text

Getting Started

Slide 24

Slide 24 text

New Project

Slide 25

Slide 25 text

Existing Project(gradle:app)

Slide 26

Slide 26 text

Existing Project(gradle:module)

Slide 27

Slide 27 text

Jetpack Compose Basics

Slide 28

Slide 28 text

Compose function ● Regular function annotated with @Composable. ● Enables your function to call other @Composable functions within it.

Slide 29

Slide 29 text

Compose in Android app ● Use setContent to define layout ● Call composable function instead of XML file

Slide 30

Slide 30 text

Compose in Android app ● Use setContent to define layout ● Call composable function instead of XML file

Slide 31

Slide 31 text

Preview Change with @Preview ● Prepare Android Studio 4.0 Preview ● Set Preview Content with @Preview annotation. ● Build Project.

Slide 32

Slide 32 text

Live Preview in Android Studio

Slide 33

Slide 33 text

Modifiers ● Are used to modify the composable UI elements for example adding margin, padding or defining the width and height. ● Available modifiers are:background(), clickable, scrollable, draggable, swipeable, width(), height(), size(), padding() . . . . .

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

3 2 1

Slide 37

Slide 37 text

Compose in Kotlin Mix Compose UI with any Kotlin function, example: for loop

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

LAzy COlumn A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It’s similar to a Recyclerview in the classic Android View system.

Slide 40

Slide 40 text

@Composable fun Planets(planets: List) { // A surface container using the 'background' color from the theme Surface(color = MaterialTheme .colors.background) { Column() { Text( text = stringResource (R.string.planets), style = MaterialTheme .typography.h4, modifier = Modifier.padding(10.dp) ) val planet = planets.maxByOrNull { it.moon } Text( text = getGreetingMessage (planet), style = MaterialTheme .typography.h6, modifier = Modifier.padding(10.dp) ) LazyColumn() { items(planets) { planet -> PlanetImageList (planet) } } } } }

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Getting interesting right?

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Codelabs • goo.gle/compose-pathway • goo.gle/compose-samples • goo.gle/compose-docs • goo.gle/compose-slack • goo.gle/compose-feedback • https://developer.android.com/jetpack/compose/tutorial • https://foso.github.io/Jetpack-Compose-Playground/material/button/

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Thank you. Kano @umarauna