Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Talk Composing UI :: DevFest Kolkata '19

Let's Talk Composing UI :: DevFest Kolkata '19

While Developing Apps, following a Reactive Architecture (for example MVI, Mobius, Redux and even MVVM) & Single Source of Truth can get you some big wins including but not limited to, Loose Coupling & Separation of Concerns, Code Testability and easy debugging, unidirectional data, etc. However, unlike Web, where Reactive Architectures are the norm, in Android, we need to opt for Reactive Architecture considering few tradeoffs (time to market, learning curve, etc.), as it’s not natural in Android.

What do I mean by saying Reactive architecture is not natural in Android? Just like web frontends, Android apps revolve around the UI, everything we do in our Android apps has some direct or indirect relation with the UI, and the Android UI framework is imperative itself.
While the Android Platform team kept adding more and more types of Views (such as Constraint Layout, RecyclerView or more recent Motion Layout), they didn’t change the nature of UI framework itself since the beginning of android development. This was majorly due to language and tooling limitations (limited by the technologies of that time).

Google announced official support for Kotlin 2 years back, and now major numbers of professional Android Developers worldwide already adopted Kotlin, which made it easier for Google to go Kotlin first in this IO19. Kotlin comes with many perks, some of them are Functional Programming support, compiler plugin capabilities and most importantly huge support on building DSLs at ease.

What relation does Koltin have with Reactive applications? In this IO19, Google announced Jetpack Compose (https://developer.android.com/jetpack/compose/), a new (still-in-development) next generation, Kotlin based, reactive cum declarative UI toolkit, backed by principals like Single Source of Truth, Unidirectional Data Flow, Functional Programming (especially function composition and effects).

This new UI toolkit would require a radical shift in our thought process about app architectures UI programming. In this talk, we would see how we can create and interact with UI with Jetpack Compose and how different it is from the present Android framework. We will also look into examples of some code patterns and ideas of from a few famous platforms such as Vue.js, React, Flutters, etc., and how these patterns and are adopted in Jetpack Compose.

Rivu Chakraborty

August 04, 2019
Tweet

More Decks by Rivu Chakraborty

Other Decks in Programming

Transcript

  1. Rivu Chakraborty About Me • https://rivu.dev • Sr Software Engineer

    (Android) - BYJU’S • Instructor - Caster.io • Google Certified Associate Android Developer • Speaks on Kotlin / Android • Author - Reactive Programming in Kotlin • Author - Functional Kotlin • Author - Hands-On Data Structures and Algorithms with Kotlin
  2. @rivuchakraborty https://rivu.dev This Talk Covers • Why should we care

    • How to Use Jetpack Compose • How Compose Works
  3. This Talk Covers @rivuchakraborty https://rivu.dev • Why should we care

    • How to Use Jetpack Compose • How Compose Works • How to manage States with Compose
  4. Why Should We Care • UI • Declarative • Functional

    • Reactive @rivuchakraborty https://rivu.dev
  5. Why Should We Care • UI • Declarative • Functional

    • Reactive Functional Declarative UI is on rise to become The Way of doing UI @rivuchakraborty https://rivu.dev
  6. Why Should We Care Benefits • Separation of Concerns •

    Declarative + Functional / Reactive @rivuchakraborty https://rivu.dev
  7. Why Should We Care Benefits • Separation of Concerns •

    Declarative + Functional / Reactive • DSL @rivuchakraborty https://rivu.dev
  8. Why Should We Care Benefits • Separation of Concerns •

    Declarative + Functional / Reactive • DSL • Developer Friendly @rivuchakraborty https://rivu.dev
  9. Why Should We Care Benefits • Separation of Concerns •

    Functional / Reactive • DSL • Developer Friendly • Designer Friendly • Flattened UI @rivuchakraborty https://rivu.dev
  10. Why Should We Care Benefits • Flattened UI • Less

    Compile Time Overhead • Separation of Concerns • Functional / Reactive • DSL • Developer Friendly • Designer Friendly @rivuchakraborty https://rivu.dev
  11. Why Should We Care Benefits • Flattened UI • Less

    Compile Time Overhead • Better Performance, Less Memory Wastage • Separation of Concerns • Functional / Reactive • DSL • Developer Friendly • Designer Friendly @rivuchakraborty https://rivu.dev
  12. CraneWrapper: Needed to buld the Foundation Might be renamed/removed later

    or get invoked by the framework itself inside `setContent()` How to use Jetpack Compose @rivuchakraborty https://rivu.dev
  13. MaterialTheme / CustomTheme: Every Root Layout (Anything inside CraneWrapper), should

    have a Theme How to use Jetpack Compose @rivuchakraborty https://rivu.dev
  14. Let’s write the logic for Counter How to use Jetpack

    Compose @rivuchakraborty https://rivu.dev
  15. Item 1 Item 2 Item 3 Empty Empty Empty Empty

    How Compose Works Gap Buffer @rivuchakraborty https://rivu.dev
  16. How Compose Works Slot Table Item 1 Item 2 Item

    3 Empty Empty Empty Empty Cu rr en t In de x @rivuchakraborty https://rivu.dev
  17. Item 1 Item 2 Item 3 Item 4 Empty Empty

    Empty Cu rr en t In de x @rivuchakraborty https://rivu.dev How Compose Works Slot Table
  18. Group State(1) Group “Count 1” Group {...} Empty Recompose How

    Compose Works @rivuchakraborty https://rivu.dev
  19. View Tree with XML in Present Day View Group 1

    View Group 2 View Group 3 View Group 4 Image View Button Text View Toolbar @rivuchakraborty https://rivu.dev How Compose Works
  20. Slot Table Group State(1) Group “Count 1” “Group” {...} Empty

    Cu rr en t In de x How Compose Works @rivuchakraborty https://rivu.dev
  21. How to Manage States with Compose How should we align

    our thinking to work with Functional Declarative UIs
  22. How to Manage States with Compose State View Action Reactive

    - Redux, Mobx, MVI, Mobius, MVPI, MVMI ... @rivuchakraborty https://rivu.dev
  23. Let’s build a statefull App How to Manage States with

    Compose @rivuchakraborty https://rivu.dev
  24. State change In the UI Level 2 ways How to

    Manage States with Compose @rivuchakraborty https://rivu.dev
  25. Let’s Talk Composing UI Resources ➢ https://developer.android.com/jetpack/compose ➢ http://bit.ly/composefirstprinciple ➢

    http://bit.ly/contentondeclarativeUI ➢ https://speakerdeck.com/lelandrichardson/react-meet-compo se ➢ https://rivu.dev/writing-android-ui-code-in-jetpack-compose/ ➢ https://rivu.dev/jetpack-compose-managing-states/ ➢ https://fragmentedpodcast.com/episodes/172/ @rivuchakraborty https://rivu.dev