Jetpack Composable UI toolkit: Part 1

Yogendra
5 min readMay 24, 2023

--

Overview :

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

Composable :
1. Jetpack Compose is Android’s recommended modern toolkit for building native UI.

2. It simplifies and accelerates UI development on Android.

3. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.

4. You will call composable functions to define what elements you want, and the Compose compiler will do the rest.

5. Easily access the full capabilities of every platform, just like native applications.

Composable UI and programming UI :

Why adopt compose :

  1. Less code ->
  2. Intuitive ->
  3. Accelerate development->
  4. Powerful->
  5. Can add AndroidView between the hierarchy of compose->

Create a composable project in android studio :

Create a sample project from Composable Text :

Follow the link for step by step.

How to convert an existing app into composable :

  1. Add composable dependencies

2. Enable compose in gradle

Compose Vs XML :

  1. APK size

2. Build Time

3. Lines of code

4. Declarative UI >> Src1 Src2

5. Removed boilerplate code (Example : RecyclerView)

A small tour with composable components.

  1. Define a composable function
  2. Define a recomposable function // Dynamic content
  3. Preview your function
  4. RunWithPreview
  5. Using a Column
  6. Configure your layout
  7. Use Material Design >> Color, Typography, Shape
  8. Lists and animations >> LazyColoum, LazyRow
  9. Surface
  10. Modifier

Conclusion :

1. Compose has been a complete redesign of the UI system

2. XML is not deprecated so dont worry.

3. Compose will be the preferred way of dealing with UI same like kotlin overcome with java.

4. Do more practise and try to familiar with components and drive SDKs.

5. As compare result with xml There is no doubt in “Compose is the future of UI development on Android.”

6. Easier to build custom views because of its flexibility

7. Intuitive and faster development

Consider compose in development — Beginner

  1. Create project with android studio.
  2. Familiar with basic views.
  3. Create a counter assignment. (click button to increase/decrease functions)
  4. Create a theme change assignment. (click button change light/dark mode of app)
  5. Display a list of user. (click button change light/dark mode of app)
  6. Enter value in text box and show into next screen
  7. Load Url in webview
  8. Intent : Share Url, Open Url, Open camera and take picture, Open gallery and take list of picture
  9. Read device location and display location on map.

Consider compose in development — Intermediate

APIs :

Get API : Display a user list in read data from API and open new screen once you tap on user list.

Get API + MVVM approach + Glide : Display a user list in read data from API and open new screen once you tap on user list.

Consider compose in development — Advanced

APIs :

Post API + MVVM approach + Dagger : Fill form and send data to

API + MVVM approach + Dagger : Display a user list in read data from API and open new screen once you tap on user list.

Dagger + API + MVVM approach + ROOM API : Display a user list in read data from API and open new screen once you tap on user list.

Test Cases :

Write test cases to validate UIs and functionalities.

Jetpack compos android apps :

Thanks to :

Articles :

Quick start

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

Convert from binding to compose.

https://developer.android.com/jetpack/androidx/releases/compose-compiler

Using Views in Compose:

https://developer.android.com/jetpack/compose/migrate/interoperability-apis/views-in-compose

APK size and build times

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

Jetpack Compose — Before and after

https://medium.com/androiddevelopers/jetpack-compose-before-and-after-8b43ba0b7d4f

Thinking in Compose :

https://developer.android.com/jetpack/compose/mental-model

4 reasons Jetpack Compose is better than XML :

https://medium.com/@cybercoder.naj/4-reasons-jetpack-compose-is-better-than-xml-ac0efd12db28

Tools for Compose

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

Compose previews

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

Navigations

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

Animation:

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

Videos :

Fundamentals of Compose Layouts and Modifiers — MAD Skills

https://www.youtube.com/watch?v=xc8nAcVvpxY&ab_channel=AndroidDevelopers

Lazy layouts in Compose

https://www.youtube.com/watch?v=1ANt65eoNhQ&ab_channel=AndroidDevelopers

Architecture: Handling UI events — MAD Skills

https://www.youtube.com/watch?v=lwGtp0Yr0PE&ab_channel=AndroidDevelopers

Intuitive: Thinking in Compose — MAD Skills

https://www.youtube.com/watch?v=fFLBCgoHHys&ab_channel=AndroidDevelopers

Less code: Composable functions — MAD Skills

https://www.youtube.com/watch?v=4zf30a34OOA&t=3s&ab_channel=AndroidDevelopers

Constraints and modifier order — MAD Skills

https://www.youtube.com/watch?v=OeC5jMV342A&ab_channel=AndroidDevelopers

Jetpack Compose basics code-along

https://www.youtube.com/watch?v=k3jvNqj4m08&ab_channel=AndroidDevelopers

--

--

Yogendra

Principle Software Engineer | Android Development | Sharing knowledge | Blogging | Keep Learning