Some tips for developers who will involve Jetpack Compose in new APPs

Overview

Compose TakeAway

给即将用Jetpack Compose开发APP的开发人员

1. Jetpack Compose vs Xml

Pros:

  • 声明式UI,纯kotlin
  • 代码更少
  • 可直接兼容现有View - 双向兼容
  • 性能更好(measure次数减少...)
  • UI自定义更简单
    • 没有adapter
    • 更容易override
    • material design(主题、动画等)支持更好
    • KeyEvent/MotionEvent/Gesture 支持更好
    • 常用系统API接口已提供
  • API(21+)无关,甚至跨平台Web/Desktop - Unbundled
  • 纯compose build更快,APP更小(据官方说法)
  • 对新人友好,易上手

Cons:

  • priview支持,但不完善(每次修改重新build)
  • 实现不透明(编译器-编译时处理)
  • recomposition 机制复杂

2. with View - Enough for use

  • Android(Compose)View用于封装旧的View
    • WebView
    • 三方库 ...
  • 自定义方式
    1. Modifier 或自定义 Modifier
    2. 组合已有组件
    3. 使用drawContent等方法
    4. 很少需要完全自定义

3. Architecture for compose

  • MVIntent -> MVIi
  • MVVMinteractor/Clean Arch

a demo(TBC)

4. Navigation between Composables - Good to go

  • 用Composable Screen替代Fragment
  • deeplink
  • 简单数据传输
  • 过度动画

pros:

  1. 可以从ViewModel获取数据
  2. 与hilt集成完善

cons:

  1. 跳转返回数据?
  2. 导航传数据,只能基本类型

使用enro补充

5. State

  • single business state for one screen
  • 数据(state)驱动UI - 比data-binding好用
  • 如何组织state:business state/pure ui state - 统一模式
  • state太大怎么办 - 注意命名、分组

Share state/data

  • Flow/Scoped Bus - 无状态

  • Repository/DB数据源

  • Composable官方方式,还没有

  • 跨Activity/Fragment - navigation, savedState

6. 三方库

For Compose

  • accompanist
  • dev.enro
  • io.coil-kt

For UT

  • io.kotest
  • io.mockk
  • app.cash.turbine

7. Others

  • 什么时候用Activity,而不是Screen - 跨module、业务分割

  • 多用Preview

  • 优先使用组合,而不是集成

  • 多用state,少用event

  • 好像不太鼓励开发去了解SDK的实现,相关文档也没有 - 以后?

You might also like...
Glance Experimental Tools aims to supplement Jetpack Glance with features that are commonly required by developers but not yet available.

Glance Experimental Tools 🚧 Work in-progress: artifacts not available yet This project aims to supplement Jetpack Glance with features that are commo

Koin-compose - A pragmatic lightweight dependency injection framework for Kotlin developers
Koin-compose - A pragmatic lightweight dependency injection framework for Kotlin developers

What is KOIN? - https://insert-koin.io A pragmatic lightweight dependency inject

Add Cloud Firestore to your Android apps built with Jetpack Compose

JetFirestore Add Cloud Firestore to your Android apps built with Jetpack Compose Now with Jetpack Compose you can easily add Cloud Firestore to your e

Add chips to your apps built with Jetpack Compose!

Chip Add chips to your apps built with Jetpack Compose! To get started with Chip just add the maven url and the Chip dependency build.gradle (Project

A framework for building responsive Android apps using Jetpack Compose
A framework for building responsive Android apps using Jetpack Compose

Jetmagic - A framework for building responsive Android apps using Jetpack Compose Jetmagic is an Android framework that can be used to develop respons

A minimalist framework for rapidly building Jetpack compose apps.
A minimalist framework for rapidly building Jetpack compose apps.

VelocityX Show some ❤️ and star the repo. Subscribe to Codepur VelocityX is a 100% free Jetpack open-source minimalist UI Framework built with Kotlin

Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop 🚀, using Canvas API 🎨
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

A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!
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!

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.
Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Owner
Le
Android developer, mainly on ROM customization. Focus on HMI, V2X.
Le
a set of Settings like composable items to help android Jetpack Compose developers build complex settings screens

This library provides a set of Settings like composable items to help android Jetpack Compose developers build complex settings screens without all the boilerplate

Bernat Borrás Paronella 178 Jan 4, 2023
This repository is a playground of jetpack compose for android developers

Pritesh Jetpack Compose This repository is a playground of jetpack compose for Android Developers, I tried to get my hands dirty with challenging UI t

PriteshVadhiya 5 Apr 20, 2022
Here you can try out Kotlin Multiplatform and Jetpack Compose with some other cutting-edge technologies.

wire The Wire is a Kotlin Multiplatform sample project, currently supporting Android and Windows. Tools And Technolagies Architecture: MVVM MultiThrea

Ali Rezaiyan 9 Aug 16, 2022
Small Android project demonstrating some navigation components for Jetpack Compose.

Small Android project demonstrating some navigation components for Jetpack Compose. Created this for presenting about this topic for a GDG meetup.

Parshav 3 Sep 15, 2021
Google CodeLab: learn how to use some Animation APIs in Jetpack Compose.

Compose Animation Codelab This folder contains the source code for the Compose Animation codelab. In this codelab, you will learn how to use some Anim

Ryan Wong 0 Dec 26, 2021
New style for app design Online Flora Go Go App UI made in Jetpack Compose. 😉 😎

JetComposeLoginUI New style for app design Online Flora Go Go App UI made in Jetpack Compose. ?? ?? (Navigation Components, Dagger-Hilt, Material Comp

Arvind Meshram 95 Dec 22, 2022
New style for app design E-commerce Shop App UI made in Jetpack Compose.😉😎

E-commerceShopAppUI-Android New style for app design E-commerce Shop App UI made in Jetpack Compose. ?? ?? (Navigation Components, Dagger-Hilt, Materi

Arvind Meshram 30 Jan 8, 2023
New style for app design and Movies App with Movies API JetMaxMovies made in Jetpack Compose.😉😎

JetMaxMovie New style for app design and Movies App with Movies API JetMaxMovies made in Jetpack Compose. ?? ?? (Navigation Compose,Dagger-Hilt, Mater

Arvind Meshram 6 Jul 6, 2022
A template for your new Jetpack Compose app

A template for your new Jetpack Compose app

Sebastien Guillemin 3 May 24, 2022
Instagraph is an Instagram Clone which I am practicing on a new concepts and other advanced Jetpack compose specific concepts.

Instagraph Instagraph is an Instagram Clone which I am practicing on a new concepts and other advanced Jetpack compose specific concepts. The clone on

Mustafa Ibrahim 117 Nov 25, 2022