Jetpack compose

Jetpack compose DEFAULT

New Project and gradle config

Tutorial Part 1 of 3 (an iOS styled Home Screen List).

Jetpack Compose is probably the most significant thing that has happened to Android in ten years, perhaps, as significant as Kotlin, coroutines, and Android Studio based on IntelliJ — this is my humble opinion, of course.

We have already begun using the SwiftUI at work, and we have plans to start using Jetpack Compose as soon as it loses its beta status. Also, even though declarative programming is not a new concept, it has recently shown great benefits, particularly for UI programming, e.g., SwiftUI, Flatter, React, and HTML, of course. So, I was reading the articles, viewing tutorials and talks, for quite a long time, but I couldn’t find time to get my hands dirty to do something useful.

The best way to learn any new technology is to build something, but, I don’t like building the “hello world” apps! I prefer doing something useful, something that solves a problem, at least for me.

Finally, when JC has turned into a beta, during one of the long weekends when the weather has locked us at home and kids preferred to play Minecraft than reading or playing together, I got enough time to begin! And as you know: — “It’s easy to begin and yet impossible to end!”

I decided to make an Android version of my existing iOS app in Compose.

StudyCards — it’s my version of the flashcards for the humans that my kids and I use to memorize things. It’s not a hit on the market yet, but we will see what happens when the Android version is ready.

StudyCards app includes three screens, a few dialogs, animations, input text, text to speech, sharing decks, and one screen of a Watch app.

This tiny app is an ideal candidate to build while learning new technology!

In a few upcoming articles, I will show you how I implemented some UI elements from scratch:

  1. iOS styled List for Homescreen;
  2. Deck of cards for Deck Screen;
  3. Flip and Swipe Card animation and the Drag gesture detector for the Deck of Cards ;

I should warn you that using Compose will turn you into a big fan! And while there are only a few outdated tutorials, a few outdated answers in StackOverflow the documentation and the demo apps are pretty good and helpful. The API is predictable. And the amount of code you need to write to achieve the same functionality as with the old UI framework is astonishingly tiny. Moreover, the Compose preview mode is going to rock your world!

We’re going to make a list widget, with the rows (list items) that have a different shape depending on the number of rows and row location.

Also the list item changes its look for the edit and delete mode like in those previews, see the Figure 2 and Figure 3.

First, let’s make a New Project using the Empty Compose Activity Template. And, let’s update the gradle file to be sure that we’re using the same JC and Kotlin version. Also, we will need this material icon dependency.


To simplify this tutorial I will not use the Jetpack Compose Theme. I will keep the colors and styles values in .

We’re ready to begin! We create a new kotlin file, under the package home. Then we add an enum to describe the row type, and we can create our first Composable function using the Pascal Notation. It accepts everything we need: text for the title and subtitle, current row type, a flag to turn the row into the edit mode, and the action handlers.

In this function, we determine the shape of our row. The top row should have the top left and right corners round, but the bottom corners square. The bottom row is mirroring the top row. The single row has all corners round. The row in the middle is entirely rectangular.

The root element is the vertical container — a Column it works similar to LinearLayout with the Vertical orientation. We need it to show a fine Divider line between multiple rows. But, we’re not going to show the divider not for the bottom item neither for the single one.

Then, the Horizontal container — a Row, it works similar to LinearLayout with the Horizontal orientation. Using the Modifier, we add some padding on the left and right, and make the Row clickable by adding the handler. The row takes up full available Width and the predefined Height, background color, and the determined shape.

The first element in the row from the left is the delete mode button, shown in edit mode, so we shall begin from it. We define an internal state variable to manage the delete mode. And we’re going to render this button only if and . The only function of this button is switching into the . When a state changes, Jetpack Compose re-composes everything below the line where the state is defined — in this case, beginning line 2.

This is how the row looking depending on and states:

The next elements are two nested Columns: the first column takes all available space, while the second, embedded Column contains the Title and Subtitle, adds padding around the text, and tells the Text to begin from Start/Left. Please take a note that these are the only elements we’re going to render without any conditions!

A chevron icon will not be rendered, not in edit nor delete mode.

The last and the rightmost element is a delete button which we’ve discussed earlier. See Figure 3. This element will render only if the condition is true.

That’s all for the ! To see all possible variations in the preview like on Figure 2, all you need to do is add those Composable functions with the annotation.

Before we begin to deal with the List, let’s add a nice looking button which we will use soon. A button with rounded corners, you can see it at the top of Figure 4. Making it composable we will save 20 lines of code, next time we use it.

Now, when we have a composable ready, we can make a widget. This function accepts only four parameters: an edit mode flag, the source of data models, and the click and delete handlers with the Int param to pass the deleted or clicked item index. Also, note that the items are not in a simple list container but a . is a state-aware container that will make the Jetpack Compose framework run the recomposition when we adding or removing items.

Inside the function, the code is pretty straightforward. We have a special case for the single row, and otherwise, we determine the row type and emit the for each item in the list.

Jetpack Compose’s approach for recycler view that’s able to render many items looks elegant. In order to be able to recycle the invisible items we need to slightly update the previous code. We can easily achieve this by using the . As you can see, the only differences are the LazyColumn instead of Column, and the HomeListItems nested in the additional container, an for the single row, and for the rest. These containers are similar to in the word.

Now, let’s add a preview and run it in Live Preview. You can see the in action at Figure 4.

With Jetpack Compose, it is much easier to build UI than it used to be on Android: no layouts, no bindings, no need to extend your custom elements of a or a ! Moreover, we don’t have to launch the app in Emulator or Device to check any small change. The Preview tool lets us see and test the changes almost instantly!

In the upcoming article, we will build the Deck of Cards (Figure 5) with the swipe and flip animation. Please stay tuned!


Compose for

Compose for Desktop

Fast reactive desktop UIs for Kotlin, based on Google's modern toolkit and brought to you by JetBrains.

Compose for Desktop simplifies and accelerates UI development for desktop applications, and allows extensive UI code sharing between Android and desktop applications. Currently in alpha.

Explore on GitHub

Fast reactive desktop UIs for Kotlin, based on Google's modern toolkit and brought to you by JetBrains.

Compose for Desktop simplifies and accelerates UI development for desktop applications, and allows extensive UI code sharing between Android and desktop applications. Currently in alpha.

Explore on GitHub

Build better desktop apps

Compose for Desktop provides a declarative and reactive approach to creating user interfaces with Kotlin. Combine composable functions to build your user interface, and enjoy full tooling support from your IDE and build system – no XML or templating language required.

Compose for Desktop targets the JVM, and supports high-performance, hardware-accelerated UI rendering on all major desktop platforms (macOS, Windows, and Linux/x64) by leveraging the powerful native Skia graphics library.





Hardware accelerated rendering with Skia.

Powerful text rendering and layout for many languages.

Desktop extensions for menus, keyboard shortcuts, window manipulation, notification management, and more.

Excellent AWT and Swing interoperability.

Code sharing with Jetpack Compose Android applications via Kotlin Multiplatform.

Android Compose compatibility at the UI element level.

Support for creating standalone application bundles.

See all features

Get started with Compose for Desktop

Work through our tutorials to learn about the features Compose for Desktop has to offer.

Start tutorial here

In this tutorial we will see how to create a simple desktop UI application using Compose for Desktop.

View tutorial

Image viewer application

An example of an image gallery showing images from a remote server, using Compose for Desktop and Android.

Explore app

Issue browser example

GitHub issues viewer example written with Compose for Desktop.

Explore app

Please note that Compose for Desktop is currently in early alpha development stage and may not be fit for production applications.

Example application

This cross-platform file viewer application is developed with Compose for Desktop. It manifests most elements typically found in a desktop application:

  • File tree navigation
  • Multiline text with formatting
  • Scrollbars

Explore the source code on GitHub.

Example application
  1. Weaver 330c
  2. Inkjet printer ebay
  3. Civil protector fuses
  4. New good morning
  5. Fridge 26 cubic feet

Jetpack Compose Samples


A sample blog post viewer that demonstrates the use of Compose with a typical Material app and real-world architecture.

• Medium complexity
• Varied UI
• Light & dark themes
• Resource loading
• UI Testing

> Browse

Jetnews sample demo

A sample chat app that focuses on UI state patterns and text input.

• Low complexity
• Simple Material Design theme (Light & dark)
• Resource loading
• Back button handling
• Integration with Architecture Components: Navigation, Fragments, LiveData, ViewModel
• Animation
• UI Testing

> Browse

Jetchat sample demo

A sample survey app that showcases text input, validation and UI state management in Compose.

• Low complexity
• and form validation
• Snackbar implementation
• Element reusability and styling
• Various form elements

> Browse

Jetsurvey sample demo

Jetsnack is a sample snack ordering app built with Compose.

• Medium complexity
• Custom design system
• Custom layouts
• Animation

> Browse

Jetsnack sample demo

A sample podcast app that features a full-featured, Redux-style architecture and showcases dynamic themes.

• Advanced sample
• Dynamic theming using podcast artwork
• Image fetching
• support
• Coroutines
• Local storage with Room

> Browse

Jetcaster sample demo

A Compose implementation of the Rally Material study, a financial app that focuses on data, charts, reusability and animations.

• Low complexity
• Material theming with a dark-only theme
• Custom layouts and reusable elements
• Charts and tables
• Animations
• Screenshot tests

> Browse

Rally sample demo

A Compose implementation of the Crane Material study, a travel app that uses Material Design components and Material Theming to create a personalized, on-brand experience.

• Medium complexity
• Draggable UI elements
• Android Views inside Compose
• UI state handling
• UI Tests

> Browse

Crane sample demo

A Compose implementation of the Owl Material study. The Owl brand uses bold color, shape, and typography to express its brand attributes: energy, daring, and fun.

• Medium complexity
• Material theming & light/dark themes
• Custom layout
• Animation

> Browse

Owl sample demo
Jetpack Compose: Animation


Compose jetpack


Jetpack Compose basics - Workshop


You will also like:


152 153 154 155 156