Compose 编程思想 & 可组合函数

95 阅读1分钟

Intuitive: Thinking in Compose - MAD Skills

Less code: Composable functions - MAD Skills

一、Compose 编程思想

Construct UI by describing what, not how.

了解如何代入 Compose 编程思想,将重点放在“什么”而不是“如何”上。

image.png

image.png

Summary

  1. Describe what, not how

  2. UI elements are functions

  3. State controls UI

  4. Events control State

二、可组合函数

了解 Compose 的构建块:可组合函数。

image.png

Composable functions can execute in any order.

Composable functions can run in parallel.

Recomposition skips as much as possible.

Recomposition is optimistic.

Composable functions might run frequently.

Summary

  1. Create composables using @Composable annotation

  2. It's quick & easy to create composables

  3. Composables accept parameters

  4. Use MutableState and remember / rememberSaveable

  5. Composables shoule be side-effect free

Composables can:

  • Execute in any order

  • Run in parallel

  • Be skipped

  • Run frequently