• Stars
    star
    1,649
  • Rank 28,345 (Top 0.6 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 22 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multiplatform reactive UI for Android, iOS, and web using Kotlin and Jetpack Compose

Redwood

Redwood is a library for building reactive Android, iOS, and web UIs using Kotlin.

Redwood is currently under development and not ready for use by anyone.

Reactive UIs

Android and iOS UI frameworks model the user interface as a โ€˜mutable view treeโ€™ or document object model (DOM). To build an application using the mutable view tree abstraction, the programmer performs two discrete steps:

  • Build the static view tree. In Android the conventional tool for this is layout XML, though we've done some cool work with Contour to build view trees with Kotlin lambdas.

  • Make it dance. The view tree should change in response to user actions (like pushing buttons) and external events (like data loading). The program mutates the view tree to represent the current application state. Some mutations change the on-screen UI instantly; others animate smoothly from the old state to the new state.

React popularized a new programming model, reactive UIs. With reactive UIs, the programmer writes a render() function that accepts the application state and returns a view tree. The framework calls this function with the initial application state and again each time the application state changes. The framework analyzes the differences between pairs of view trees and updates the display, including animating transitions where appropriate.

In React the view tree returned by the render function is called a virtual DOM, and it has an on-screen counterpart called the real DOM. The virtual DOM is a tree of simple JavaScript value objects; the real DOM is a tree of live browser HTML components. Creating and traversing thousands of virtual DOM objects is fast; creating thousands of HTML components is not! Therefore, the virtual DOM optimization is the magic that makes React work.

Compose

Jetpack Compose is an implementation of the reactive UI model for Android. It uses an implementation trick to further optimize the reactive programming model. It is implemented in two complementary modules:

  • The Compose compiler is a Kotlin compiler plugin that supports partial re-evaluation of a function. The programmer still writes render functions to transform application state into a view tree. The compiler rewrites this function to track which inputs yield which outputs. When the input application state changes, it evaluates only what is necessary to generate the corresponding view tree changes.

  • Compose UI is a new set of Android UI components designed to work with the Compose compiler. It addresses longstanding technical debt with Android's view system.

A Kotlin function that is rewritten by the Compose compiler is called a composable function. Partial re-evaluation of a composable function is called recomposing.

Note that the Compose compiler can be used without Compose UI. For example, compose-server-side renders HTML components on a server that are sent to a browser over a WebSocket.

Design Systems

In Cash App we use a design system. It specifies our UI in detail and names its elements:

  • Names for our standard colors, fonts, icons, dimensions
  • Named text blocks, specified using the names above
  • Named controls, such as our standard checkboxes, buttons, and dialogs

The design system helps with collaboration between programmers and designers. It also increases uniformity within the application and across platforms.

What Is Redwood?

Redwood integrates the Compose compiler, a design system, and a set of platform-specific displays. Each Redwood project is implemented in three parts:

  • A design system. Redwood includes a sample design system called โ€˜Sunspotโ€™. Most applications should customize this to match their product needs.

  • Displays for UI platforms. The display draws the pixels of the design system on-screen. Displays can be implemented for any UI platform. Redwood includes sample displays for Sunspot for Android, iOS, and web.

  • Composable Functions. This is client logic that accepts application state and returns elements of the design system. These have similar responsibilities to presenters in an MVP system.

Why Redwood?

We're eager to start writing reactive UIs! But we're reluctant to continue duplicating code across iOS, Android, and web platforms. In particular, we don't like how supporting multiple platforms reduces our overall agility.

We'd like to shortcut the slow native UI development process. Iterating on UIs for Android requires a slow compile step and a slow adb install step. With Redwood, we hope to use the web as our development target while we iterate on composable function changes.

We want the option to change application behavior without waiting for users to update their apps. With Kotlin/JS we may be able to update our composable functions at application launch time, and run them in a JavaScript VM. We may even be able to use WebAssembly to accomplish this with little performance penalty.

Redwood is a library, not a framework. It is designed to be adopted incrementally, and to be low-risk to integrate in an existing Android project. Using Redwood in an iOS or web application is riskier! We've had good experiences with Kotlin Multiplatform Mobile, and expect a similar outcome with Redwood.

Code Sample

We start by expressing our design system as a set of Kotlin data classes. Redwood will use these classes to generate type-safe APIs for the displays and composable functions.

@Widget(1)
data class Text(
  @Property(1) val text: String?,
  @Property(2) @Default("\"black\"") val color: String,
)

@Widget(2)
data class Button(
  @Property(1) val text: String?,
  @Property(2) @Default("true") val enabled: Boolean,
  @Property(3) val onClick: () -> Unit,
)

Displays implement the design system using native UI components.

class AndroidText(
  override val value: TextView,
) : Text<View> {
  override fun text(text: String?) {
    value.text = text
  }

  override fun color(color: String) {
    value.setTextColor(Color.parseColor(color))
  }
}

Composable functions render application state into the design system. These will make use of Compose API features like remember().

@Composable
fun Counter(value: Int = 0) {
  var count by remember { mutableStateOf(value) }

  Button("-1", onClick = { count-- })
  Text(count.toString())
  Button("+1", onClick = { count++ })
}

More Repositories

1

sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
Kotlin
6,146
star
2

turbine

A testing library for kotlinx.coroutines Flow
Kotlin
2,472
star
3

paparazzi

Render your Android screens without a physical device or emulator
Kotlin
2,284
star
4

zipline

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs
C
2,053
star
5

molecule

Build a StateFlow stream using Jetpack Compose
Kotlin
1,864
star
6

contour

Layouts with lambdas ๐Ÿ˜Ž
Kotlin
1,531
star
7

InflationInject

Constructor-inject views during XML layout inflation
Kotlin
904
star
8

licensee

Gradle plugin which validates the licenses of your dependency graph match what you expect
Kotlin
626
star
9

pranadb

Go
613
star
10

hermit

๐Ÿš Hermit manages isolated, self-bootstrapping sets of tools in software projects.
Go
596
star
11

AccessibilitySnapshot

Easy regression testing for iOS accessibility
Swift
550
star
12

multiplatform-paging

A library that packages AndroidX Paging for Kotlin/Multiplatform.
Kotlin
542
star
13

exhaustive

An annotation and Kotlin compiler plugin for enforcing a when statement is exhaustive
Kotlin
463
star
14

misk

Microservice Kontainer
Kotlin
402
star
15

copper

A content provider wrapper for reactive queries
Kotlin
301
star
16

barber

Barber ๐Ÿ’ˆ A type safe Kotlin JVM library for building up localized, fillable, themed documents using Mustache templating
Kotlin
166
star
17

paraphrase

A Gradle plugin that generates type-safe formatters for Android string resources in the ICU message format.
Kotlin
163
star
18

stagehand

Modern, type-safe API for building animations on iOS
Swift
132
star
19

hermit-packages

Hermit manages isolated, self-bootstrapping sets of tools in software projects.
HCL
120
star
20

quiver

Quiver is a collection of extension methods and handy functions to make the wonderful functional programming Kotlin library, Arrow, even better.
Kotlin
116
star
21

spirit

Online Schema Change Tool for MySQL 8.0+
Go
104
star
22

pivit

Go
89
star
23

tempest

Typesafe DynamoDB for Kotlin and Java.
Kotlin
83
star
24

better-dynamic-features

Making dynamic feature modules better
Kotlin
80
star
25

misk-web

Micro-Frontends React + Redux + Typescript Framework
TypeScript
64
star
26

blip

Sublime MySQL monitoring
Go
62
star
27

logquacious

Logquacious (lq) is a fast and simple log viewer.
TypeScript
59
star
28

wisp

Wisp is a collection of kotlin modules providing various features and utilities, including config, logging, feature flags and more.
Kotlin
57
star
29

certifikit

Kotlin Certificate processing library.
Kotlin
40
star
30

cash-app-pay-android-sdk

Cash Android PayKit SDK for merchant integrations with Cash App Pay
Kotlin
32
star
31

backfila

Service that manages backfill state, calling into other services to do batched work
Kotlin
31
star
32

nostrino

A Kotlin SDK for Nostr
Kotlin
28
star
33

cloner

Go
28
star
34

cash-app-pay-ios-sdk

Swift
24
star
35

transflect

Kubernetes operator using Istio to set up Envoy's gRPC-JSON transcoding.
Go
24
star
36

kfsm

Finite state machinery in Kotlin
Kotlin
22
star
37

cmmc

K8S ConfigMap Merging Controller
Go
21
star
38

yet-another-aws-exporter

A Prometheus metrics exporter for AWS that fills in gaps CloudWatch doesn't cover
Go
17
star
39

protosync

ProtoSync synchronises remote .proto files to a local directory
Go
15
star
40

cash-pay-pay-sdk-android-sample-app

Cash App Pay Kit SDK Sample app for Android.
Kotlin
15
star
41

trifle

Security functionality for interoperability/interaction with core services.
Swift
12
star
42

jooq-encryption

Kotlin
11
star
43

kfactories

Set of factories and utils to create effective and lightweight property-based testing strategies.
Kotlin
10
star
44

AardvarkReveal

Generate and attach a Reveal file to your Aardvark bug reports
Swift
10
star
45

ln-invoice

Parse lightning network payment requests (invoices) in Kotlin.
Kotlin
10
star
46

hermit-ij-plugin

Kotlin
9
star
47

kotlin-editor

Kotlin
8
star
48

cash-app-pay-sdk-ios-sample-app

Swift
8
star
49

awsu

su for aws roles
Go
8
star
50

AardvarkCrashReport

AardvarkCrashReport makes it easy to provide high quality data about crashes in your bug reports
Swift
7
star
51

activate-hermit

Github Action to activate a Hermit environment.
Shell
7
star
52

knit

Safety features for Swinject
Swift
7
star
53

csop

Go
6
star
54

check-signature-action

Shell
5
star
55

kruit

TypeScript
4
star
56

hermit-build

Relocatable/static builds for Hermit packages
Makefile
3
star
57

chronicler

Kotlin
2
star
58

s3-copy-gradle-plugin

1
star
59

.github

1
star
60

hermit-package-version

Shell
1
star
61

cash-app-pay-sandbox-releases

1
star