Popalay / workflow-kotlin-compose

Jetpack Compose integration for Square Workflows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

workflow-kotlin-compose

GitHub license Maven Central

This module provides experimental support for Jetpack Compose UI with workflows.

The only integration that is currently supported is the ability to define ViewFactories that are implemented as @Composable functions. See the hello-compose-binding sample in samples for an example of how to use.


Pre-Alpha

DO NOT USE this module in your production apps!

Jetpack Compose is in pre-alpha, developer preview stage. The API is incomplete and changes very frequently. This integration module exists as a proof-of-concept, to show what's possible, and to experiment with various ways to integrate Compose with Workflow.


Usage

Add the dependency

Add the dependencies from this project (they're on Maven Central):

dependencies {
  // Main dependency
  implementation "com.squareup.workflow:workflow-ui-core-compose:${versions.workflow_compose}"

  // For the preview helpers
  implementation "com.squareup.workflow:workflow-ui-compose-tooling:${versions.workflow_compose}"
}

Enable Compose

You must be using the latest Android Gradle Plugin 4.x version, and enable Compose support in your build.gradle:

android {
  buildFeatures {
    compose true
  }
  composeOptions {
    kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
    kotlinCompilerExtensionVersion "${compose_version}"
  }
}

You may also need to set the Kotlin API version to 1.3:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
  kotlinOptions.apiVersion = "1.3"
}

To create a ViewFactory, call composedViewFactory. The lambda passed to composedViewFactory is a @Composable function.

val HelloBinding = composedViewFactory<MyRendering> { rendering, _ ->
  MaterialTheme {
    Clickable(onClick = { rendering.onClick() }) {
      Text(rendering.message)
    }
  }
}

The composedViewFactory function returns a regular ViewFactory which can be added to a ViewRegistry like any other:

val viewRegistry = ViewRegistry(HelloBinding)

About

Jetpack Compose integration for Square Workflows.

License:Apache License 2.0


Languages

Language:Kotlin 100.0%