๐Ÿš€ This project contains various examples that show how you would do things the "Jetpack Compose" way

Overview

Learn Jetpack Compose By Example

Android CI Compose Version Android Weekly

Feature Image

Over the course of the last few years Android development has gone through significant changes in how we structure our apps, the language we use for development, the tooling & libraries that help us speed up our development and the improvements in testing our apps. What had not changed in all these years is the Android UI toolkit. This changes with Jetpack Compose that aims to re-imagine what Android UI development would look like using declarative programming principles. It is heavily influenced by existing web and mobile frameworks such as React, Litho, Vue & Flutter and would be a paradigm shift in Android UI development as we know it.

This repository aims to show the Jetpack Compose way of building common Android UI that we are accustomed to building.

Talks

I've also used the examples listed in this repo and given talks at conferences. If video is your preferred medium of learning, you can head to the links below

360|AnDev 2020: Learning Jetpack Compose By Example Video| Slides

Android Summit 2020: Learn Jetpack Compose By Example v2 Slides

Setup

To try out this sample app, you need to at least use the latest version of Android Studio. This project has been tested against Android Studio Artic Fox. You can download it here. In general, Jetpack Compose requires you to use the Canary version of Android Studio.

Examples

Each example is meant to be self contained and tries to explain all the concepts that its using with comments. Compose also comes with this nifty feature that lets you preview each component in the IntelliJ IDE itself. To do so, go to any of the examples and then click on the preview button in the top right corner. This is possible if your @Composable component has a corresponding @Preview method associated with it. Look at the examples below for all this to make a bit more sense.

Jetpack Compose Preview Functionality

General

Example Preview
How do I display text on the screen using Jetpack Compose?
How do I make a view clickable and do actions when clicked?
How do I add padding around a view?
How do I add an offset to a layout?
How do I enforce a layout to have a fixed aspect ratio?
How do I add a background color to any section of the screen?
Example 1
Example 2

How do I get FrameLayout like functionality to stack views on top of one another?
How do I do animation in Jetpack Compose?
Example: Rotation Animation
Example: Color Change Animation


How do styles & themes work in Jetpack Compose?
How do I add dark mode capability to my app?

State Management

Example Preview
How do I store state information in Jetpack Compose?
How do I retain state across process death & activity recreation(like orientation changes)?
How do I use LiveData/ViewModels with Jetpack Compose?
How do I use Coroutine Flow to update my components/views with Jetpack Compose?
How do you launch a Coroutine inside a Composable?
How do you do side-effects in Jetpack Compose?
How do you handle back press in Jetpack Compose?

Material Design

Example Preview
How do I add a Material Design Card?
How do I display a linear progress bar?
What about a circular progress bar?
How do I add a Snackbar?
How to add a Material Design Slider?
How to configure a two/three state checkbox?
How do I add a radio button group?
How do I add a Floating Action Button to my screen?
How do I create a Bottom App Bar?
How do I add a drawer to my screen?
How do I add Ripple effect to a view?
How do I add a Button to my screen?
How do I display an alert dialog/popup modal?
How do I make Material Filter Chips that overflow to multiple rows?
How do I add a shadow around my view?

Text

Example Preview
How do I style & customize my text?
How do you take text input from a user in Jetpack Compose?
How can I use a custom text style for a text input?
How can I change the keyboard type to accept numbers?
How can I create a Search bar?
How can I apply a visual transformation to an input text?
How can I provide a hint for the text input field?
Is there filled text field as per Material Design specification?
How do I animate parts of my text?
How do I describe parts of my text to be replaced by alternate views?

Images

Example Preview
How do I display an image in Jetpack Compose?
How to load an image from the resource folder?
How to make an image view with rounded corners?
How to load an image over the network using Picasso?
How to load an image over the network using Glide?

Lists

Example Preview
How do I display a list in my app?
Is there a RecyclerView equivalent?
How can I have a grid layout?
How can I build a horizontally scrollable carousel?
How can I add animations for insertion/deletion of a list item?

Flexible Layouts

Example Preview
How do I align the baseline of two views?

What's the layout weight equivalent in Jetpack Compose?
Example with equal weights
Example with unequal weights

How do I auto arrange my views similar to FlexBox?
Add space between views
Evenly distribute space
Add space around the views
Tightly packed centering of views
How do I use constraint layouts?
How do I use guidelines with constraint layouts?
How do I add barriers when using constraint layouts?
How do I add bias when using constraint layouts?

Custom Views

Example Preview
How do I draw using a canvas?
Example of a measuring scale component
How do I make a view zoomable?
How do I detect touch events in a custom view?

Interoperability

Example Preview
How can I use Jetpack Compose components inside existing screens?

Testing

Example Preview
How do I write a simple UI Test in Jetpack Compose?
How do I test "Composables"?

Credits

Author: Vinay Gaba ([email protected])

Follow me on Twitter Follow me on LinkedIn

License

Copyright 2020 Vinay Gaba

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • library is to old !!

    library is to old !!

    Dear Sir

    this demo project use compose library is to old

    when i upgrade to

    compose_version = '1.0.0-beta04' <-- now 1.0.0-beta04/1.0.0-beta05/1.0.0-beta06

    i get error !!

    SimpleTextActivity.kt: (29, 9): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: internal fun ViewGroup.setContent(parent: CompositionContext, content: () -> Unit): Composition defined in androidx.compose.ui.platform

    opened by CMingTseng 8
  • what happens when you update to 1.0.0-rc01 ??

    what happens when you update to 1.0.0-rc01 ??

    I'm a bit confused.

    A lot of stuff is now breaking including: TransitionDefinition

    "Unresolved reference: TransitionDefinition"

    I can build 1.0.0-rc01 under Kotlin 1.5.10 only.

    opened by mcorbridge 5
  • ImageWithRoundedCorners not loading however same using visible in layout inspector.

    ImageWithRoundedCorners not loading however same using visible in layout inspector.

    https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/a44eb99d13516a98ecb3d5f07eff00c6d50d7106/app/src/main/java/com/example/jetpackcompose/image/ImageActivity.kt#L123

    device-2020-04-10-112520 Screenshot from 2020-04-10 11-26-09

    opened by mwshubham 5
  • Add example about beautiful ui

    Add example about beautiful ui

    I donโ€™t seem to find the following API, if you can add an example it is very cool dude!

    1. How to create a shadow with color
    2. Blur the widgets or background, just like android Blurkit, flutter BackdropFilter
    opened by chachako 3
  • Update dependencies

    Update dependencies

    This pull request aims to update this project in terms of dependencies to support the latest stable versions that are available.

    The only exception is the usage of the latest version for androidx.compose:compose (1.2.0-rc01). The reason for that were build issues based on a previous Kotlin plugin. The problems occurred for Kotlin version 1.6.10 that were the highest supported version by the last stable compose library 1.1.0.

    opened by TheElementNrOne 1
  • Build is failing because of detekt

    Build is failing because of detekt

    The build is failing with the following error.

    Could not HEAD 'https://dl.bintray.com/kotlin/kotlin-eap/io/gitlab/arturbosch/detekt/io.gitlab.arturbosch.detekt.gradle.plugin/1.7.4/io.gitlab.arturbosch.detekt.gradle.plugin-1.7.4.pom'. Received status code 502 from server: Bad Gateway

    opened by 5AbhishekSaxena 1
  • unstable version of the Kotlin compiler

    unstable version of the Kotlin compiler

    Class 'androidx.compose.foundation.layout.Arrangement' is compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler

    Make sure this is included in build.gradle

    android { // other options

    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true  // <- THIS!
    }
    
    // more options
    

    }

    opened by mcorbridge 1
  • An example of using Flow

    An example of using Flow

    If you have the time it would nice to add an example of using Flow with Compose.

    Dev11 API Changes Added an adapter for Flow. Example of the usage: val value by flow.collectAsState() (If2198, b/153375923)

    Thanks! You Rock Hard! ~Ash

    example request 
    opened by ashrafi 1
  • Snackbar link is wrong in readme

    Snackbar link is wrong in readme

    Snackbar link points to this link which is for MaterialCircularProgressIndicatorComponent

    https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/master/app/src/main/java/com/example/jetpackcompose/material/MaterialActivity.kt#L323

    bug 
    opened by jitinsharma 1
  • The counter text isn't visible in StateActivity due to a platform bug in dev08

    The counter text isn't visible in StateActivity due to a platform bug in dev08

    The issue is related to using a composable with elevation. It causes the composables around it that don't have an elevation to not be visible.

    https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/master/app/src/main/java/com/example/jetpackcompose/state/StateActivity.kt

    https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/blob/a44eb99d13516a98ecb3d5f07eff00c6d50d7106/app/src/main/java/com/example/jetpackcompose/image/ImageActivity.kt#L273

    bug good first issue 
    opened by vinaygaba 1
  • Loading Images

    Loading Images

    Dear Sir

    very thx your upgrade compose library

    now i use vinay-latest-compose branch

    &

    i PR for you

    https://github.com/vinaygaba/Learn-Jetpack-Compose-By-Example/pull/90

    __ Loading Images can add use "accompanist-coil " ??

    https://google.github.io/accompanist/coil/

    https://betterprogramming.pub/how-to-use-coil-kotlins-native-image-loader-d6715dda7d26

    implementation "com.google.accompanist:accompanist-appcompat-theme:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-coil:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-flowlayout:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-glide:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-imageloading-core:$compose_accompanist_version"
    
    implementation "com.google.accompanist:accompanist-insets:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-insets-ui:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-pager-indicators:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-pager:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-placeholder:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-placeholder-material:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-swiperefresh:$compose_accompanist_version"
    implementation "com.google.accompanist:accompanist-systemuicontroller:$compose_accompanist_version"
    
    THX
    
    opened by CMingTseng 0
  • try upgrade the demo project compose version to  beta or stable

    try upgrade the demo project compose version to beta or stable

    as commit log

    i try let this demo project run at low version android studio/idea

    and

    upgrade compose library version to beta

    but now

    lost some class

    like:

    androidx.compose.animation.core.*

    THX

    opened by CMingTseng 0
  • Replace FlowRow example

    Replace FlowRow example

    The FlowRow composable has been deprecated without direct replacement. The example using it should be removed or replaced by an equivalent implementation.

    opened by Namnodorel 0
Owner
Vinay Gaba
Google Developer Expert for Android Tech Lead @airbnb ๐Ÿ  Previously @Snapchat ๐Ÿ‘ป @spotify ๐ŸŽต @Deloitte ๐Ÿคต
Vinay Gaba
Jetpack-compose-animations-examples - Cool animations implemented with Jetpack compose

Jetpack-compose-animations-examples This repository consists of 4 animations: St

Canopas Software 180 Jan 2, 2023
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Md. Mahmudul Hasan Shohag 186 Jan 1, 2023
Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuation of the Readme file. ๐Ÿชž

Parallax Examples : Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuatio

Nisa EfendioฤŸlu 5 Jul 29, 2022
Sample repo that demonstrates various options for testing Jetpack Compose applications.

Composing With Confidence This is the sample repository for the Composing With Confidence presentation from Droidcon NYC in 2022. If you run the sampl

Adam McNeilly 9 Dec 2, 2022
This repo contains components built with Jetpack Compose for the Microsoft Surface Duo.

Surface Duo Jetpack Compose SDK This repo contains components built with Jetpack Compose for the Microsoft Surface Duo and other large screen and fold

Microsoft 53 Dec 9, 2022
Jetpack Compose Text composable to show html text from resources

HtmlText Current Compose Version: 1.0.3 Compose HtmlText Text composable to show html text from resources Add to your project Add actual HtmlText libr

Alexander Karkossa 57 Dec 23, 2022
A Clean Architecture App to show use of multi module architecture in a Jetpack Compose

Nextflix-Composable A Clean Architecture App to show use of multi-module-archite

Talha FakฤฑoฤŸlu 196 Dec 19, 2022
Icontent - Jetpack Compose component to show all random content sended by Inmersoft guide backend

icontent IContent is a library that allows loading audio visual content generica

Orlando Novas Rodriguez 3 Nov 3, 2022
Formula 1 app to show current Standings from a REST API.Built using jetpack compose and kotlin.

Formula1 Formula 1 app to show Standings fetching data from REST API ?? Screenshots Tech Stack. Kotlin - Kotlin is a programming language that can run

Ezra Kanake 5 Oct 28, 2022
OTPView is a view made in Jetpack compose. It is highly customisable and can be used to show OTP view with different length and shapes.

OTPView OTPView is a highly costumizable OTP view made in the Jetpack compose UI. Usage: CircleOtpView is a sample composable that calls the OtpView w

kunalsale 17 Aug 4, 2022
Gymber: a searcher app for sports clubs using Jetpack compose way

GymberCompose GymberCompose is a searcher app for sports clubs using Jetpack com

Attila AKINCI 0 Jan 11, 2022
An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android.

ThinkRchive An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android. WORK IN PROGRESS GOALS: Use Ret

Racka98 81 Dec 16, 2022
An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android.

An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android. This repo is a Mutliplatform version of the initial Thinkrchive which was Android-centric

Thinkrchive 59 Dec 28, 2022
Pinocchio is a group of libraries for various common UI components. It could contain Composable, View, and everything related to UI.

Pinocchio Pinocchio is a group of libraries for various common UI components. It could contain Composable, View, and everything related to UI. All UI

NAVER Z 24 Nov 30, 2022
Jetpack Compose based project, used to stress-testing compose features / integrations and explore non-trivial functionality

Project containing Jetpack Compose samples For pagination & network images it uses CATAAS. Known issues Navigation-Compose Issue with fast tapping on

Denis Rudenko 59 Dec 14, 2022
๐Ÿ“ฑ WhatsApp clone project demonstrates modern Android development built with Jetpack Compose and Stream Chat SDK for Compose.

This is a WhatsApp clone app built with Jetpack Compose and Stream Chat SDK for Compose. The purpose of this repository is to demonstrate below: Imple

Stream 689 Dec 25, 2022
Jetpack Compose Boids | Flocking Insect ๐Ÿœ. bird or Fish simulation using Jetpack Compose Desktop ๐Ÿš€, using Canvas API ๐ŸŽจ

?? ?? ?? Compose flocking Ants(boids) ?? ?? ?? Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop ?? , usi

Chetan Gupta 38 Sep 25, 2022
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

BHAVNA THACKER 3 Dec 31, 2022
Jetpack-Compose-Demo - Instagram Profile UI using Jetpack Compose

Jetpack-Compose-Demo Instagram Profile UI using Jetpack Compose

omar 1 Aug 11, 2022