Android UI Development with Jetpack Compose

Book description

Get started with creating intuitive native user interfaces on Android platforms

Key Features

  • Understand the difference between the imperative (Android View) and declarative (Jetpack Compose) approach
  • Learn about the structure of a Compose app, built-in Compose UI elements, and core concepts such as state hoisting and composition over inheritance
  • Write, test, and debug composable functions

Book Description

Jetpack Compose is Android’s new framework for building fast, beautiful, and reliable native user interfaces. It simplifies and significantly accelerates UI development on Android using the declarative approach. This book will help developers to get hands-on with Jetpack Compose and adopt a modern way of building Android applications. The book is not an introduction to Android development, but it will build on your knowledge of how Android apps are developed.

Complete with hands-on examples, this easy-to-follow guide will get you up to speed with the fundamentals of Jetpack Compose such as state hoisting, unidirectional data flow, and composition over inheritance and help you build your own Android apps using Compose. You'll also cover concepts such as testing, animation, and interoperability with the existing Android UI toolkit.

By the end of the book, you'll be able to write your own Android apps using Jetpack Compose.

What you will learn

  • Gain a solid understanding of the core concepts of Jetpack Compose
  • Develop beautiful, neat, and immersive UI elements that are user friendly, reliable, and performant
  • Build a complete app using Jetpack Compose
  • Add Jetpack Compose to your existing Android applications
  • Test and debug apps that use Jetpack Compose
  • Find out how Jetpack Compose can be used on other platforms

Who this book is for

This book is for any mobile app developer looking to understand the fundamentals of the new Jetpack Compose framework and the benefits of native development. A solid understanding of Android app development, along with some knowledge of the Kotlin programming language, will be beneficial. Basic programming knowledge is necessary to grasp the concepts covered in this book effectively.

Table of contents

  1. Android UI Development with Jetpack Compose
  2. Contributors
  3. About the author
  4. About the reviewers
  5. The Peer Reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  7. Part 1:Fundamentals of Jetpack Compose
  8. Chapter 1: Building Your First Compose App
    1. Technical requirements
    2. Saying hello to composable functions
      1. Showing a welcome text
      2. Using rows, text fields, and buttons
      3. Showing a greeting message
    3. Using the preview
      1. Preview parameters
      2. Configuring previews
      3. Grouping previews
    4. Running a Compose app
      1. Deploying a composable function
      2. Using composable functions in activities
      3. Looking under the hood
      4. Pressing the play button
    5. Summary
    6. Further reading
  9. Chapter 2: Understanding the Declarative Paradigm
    1. Technical requirements
    2. Looking at the Android view system
      1. Inflating layout files
      2. Modifying the UI
    3. Moving from components to composable functions
      1. Component hierarchies
      2. Limitations of component hierarchies
      3. Composing UIs with functions
    4. Examining architectural aspects
      1. Reacting to clicks
      2. Sizing and positioning UI elements
    5. Summary
  10. Chapter 3: Exploring the Key Principles of Compose
    1. Technical requirements
    2. Looking closer at composable functions
      1. Building blocks of composable functions
      2. Emitting UI elements
      3. Returning values
    3. Composing and recomposing the UI
      1. Sharing state among composable functions
      2. Controlling size
      3. Displaying a composable hierarchy inside an Activity
    4. Modifying the behavior of composable functions
      1. Understanding how modifiers work
      2. Implementing custom modifiers
    5. Summary
  11. Part 2:Building User Interfaces
  12. Chapter 4: Laying Out UI Elements
    1. Technical requirements
    2. Using predefined layouts
      1. Combining basic building blocks
      2. Creating layouts based on constraints
    3. Understanding the single measure pass
      1. Defining measure policies
    4. Creating custom layouts
      1. Implementing a custom measure policy
    5. Summary
  13. Chapter 5: Managing the State of Your Composable Functions
    1. Technical requirements
    2. Understanding stateful and stateless composable functions
      1. Using state in a composable function
      2. Writing stateless composable functions
    3. Hoisting state and passing events
      1. Creating radio button groups
    4. Surviving configuration changes
      1. Using ViewModel
    5. Summary
  14. Chapter 6: Putting Pieces Together
    1. Technical requirements
    2. Styling a Compose app
      1. Defining colors, shapes, and text styles
      2. Using resource-based themes
    3. Integrating toolbars and menus
      1. Using Scaffold() to structure your screen
      2. Creating a top app bar
    4. Adding navigation
      1. Defining screens
      2. Using NavHostController and NavHost()
    5. Summary
  15. Chapter 7: Tips, Tricks, and Best Practices
    1. Technical requirements
    2. Persisting and retrieving state
      1. Injecting objects into a ViewModel
      2. Using the factory
    3. Keeping your composables responsive
      1. Communicating with ViewModel instances
      2. Handling long-running tasks
    4. Understanding side effects
      1. Invoking suspending functions
      2. Cleaning up with DisposableEffect()
    5. Summary
  16. Part 3:Advanced Topics
  17. Chapter 8: Working with Animations
    1. Technical requirements
    2. Using animation to visualize state changes
      1. Animating single value changes
      2. Animating multiple value changes
    3. Showing and hiding UI elements with animations
      1. Understanding AnimatedVisibility()
      2. Animating size changes
    4. Spicing up transitions through visual effects
      1. Crossfading composable functions
      2. Understanding animation specifications
    5. Summary
  18. Chapter 9: Exploring Interoperability APIs
    1. Technical requirements
    2. Showing Views in a Compose app
      1. Adding custom components to a Compose app
      2. Inflating View hierarchies with AndroidViewBinding()
    3. Sharing data between Views and composable functions
      1. Revisiting ViewModels
      2. Combining View Binding and ViewModels
    4. Embedding composables in View hierarchies
    5. Summary
  19. Chapter 10: Testing and Debugging Compose Apps
    1. Technical requirements
    2. Setting up and writing tests
      1. Implementing unit tests
      2. Testing composable functions
    3. Understanding semantics
      1. Working with semantics nodes
      2. Adding custom semantics properties
    4. Debugging Compose apps
      1. Using custom modifiers for logging and debugging
    5. Summary
    6. Further reading
  20. Chapter 11: Conclusion and Next Steps
    1. Technical requirements
    2. Exploring the future
      1. Showing exposed drop-down menus
      2. Using NavigationRail()
    3. Migrating to Material You
      1. Looking at some differences between Material 2 and Material 3 for Compose
    4. Moving beyond Android
      1. Setting up a sample project
    5. Summary
    6. Why subscribe?
  21. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Android UI Development with Jetpack Compose
  • Author(s): Thomas Künneth
  • Release date: February 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801812160