Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

[DNM] Introduce ViewFactoryTransformer with vibrating demo effect. #28

Draft
wants to merge 28 commits into
base: weekend-features
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56165a1
Upgrade gradle to latest version.
zach-klippenstein May 16, 2020
6daf2e7
Merge pull request #26 from square/zachklipp/dev11
zach-klippenstein May 18, 2020
471c856
Merge pull request #25 from square/zachklipp/upgrade-gradle
zach-klippenstein May 18, 2020
fc180e3
Merge pull request #23 from square/zachklipp/cleanup-packages
zach-klippenstein May 18, 2020
acfbee0
Make ViewFactory.showRendering function responsible for applying the …
zach-klippenstein May 15, 2020
a58aafe
Merge pull request #24 from square/zachklipp/better-root
zach-klippenstein May 18, 2020
9a6c51a
Fix gradle cache in CI.
zach-klippenstein May 18, 2020
f91253a
Upload UI test reports as Github Actions artifacts.
zach-klippenstein May 18, 2020
eb8a3d0
Releasing v0.29.0.
zach-klippenstein May 18, 2020
41cbbf1
Finish releasing v0.29.0.
zach-klippenstein May 18, 2020
4c1c33b
Update README with dependency instructions for v0.29.0.
zach-klippenstein May 18, 2020
55c4403
Merge pull request #30 from square/zachklipp/fix-ci-caching
zach-klippenstein May 18, 2020
240cbe7
Merge pull request #31 from square/zachklipp/update-readme
zach-klippenstein May 18, 2020
da4527c
Inline WorkflowViewStub logic in ViewFactory.showRendering to avoid u…
zach-klippenstein May 17, 2020
dc194c3
Merge pull request #29 from square/zachklipp/inline-viewstub
zach-klippenstein May 19, 2020
5e620d7
Make ViewRegistry.showRendering update if ViewRegistry changes.
zach-klippenstein May 19, 2020
3bb2f1f
Rename bindCompose to composedViewFactory.
zach-klippenstein May 19, 2020
a23b56e
Merge pull request #35 from square/zachklipp/composedviewfactory
zach-klippenstein May 28, 2020
2295483
Merge pull request #33 from square/zachklipp/fix-viewregistry-showren…
zach-klippenstein May 28, 2020
49228bd
Rename showRendering to WorkflowRendering and make it not an extensio…
zach-klippenstein May 20, 2020
3f460f8
Merge pull request #36 from square/zachklipp/rename-showrendering
zach-klippenstein May 28, 2020
ea57ae0
Renames ComposeViewFactoryRoot to CompositionRoot and decouples the i…
zach-klippenstein May 18, 2020
508029e
Merge pull request #34 from square/zachklipp/even-better-root
zach-klippenstein May 28, 2020
4a5373a
Make renderAsState public, make WorkflowContainer take a ViewEnvironm…
zach-klippenstein May 19, 2020
5730afa
Merge pull request #32 from square/zachklipp/renderasstate
zach-klippenstein May 29, 2020
f54fa51
Update Compose to dev12.
zach-klippenstein May 28, 2020
e5e9337
Merge pull request #41 from square/zachklipp/update-compose
zach-klippenstein May 29, 2020
d6a15f2
[DNM] Introduce ViewFactoryTransformer with vibrating demo effect.
zach-klippenstein May 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .buildscript/android-ui-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
testOptions {
animationsDisabled = true
}
}

dependencies {
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/kotlin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ on:
pull_request:

env:
# Must use $HOME here, NOT a tilde, because of the order in which bash does expansion:
# Tilde happens before variables, so will be used literally, whereas $HOME will be
# recursively expanded.
GRADLE_CACHE_PATH: $HOME/.gradle/caches
GRADLE_HOME: ${{ github.workspace }}/gradle-home

jobs:
assemble:
Expand All @@ -29,7 +26,7 @@ jobs:
- name: Cache gradle dependencies
uses: actions/cache@v1
with:
path: ${{ env.GRADLE_CACHE_PATH }}
path: ${{ env.GRADLE_HOME }}/caches
# Include the SHA in the hash so this step always adds a cache entry. If we didn't use the SHA, the artifacts
# would only get cached once for each build config hash.
# Don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests.
Expand All @@ -47,13 +44,13 @@ jobs:
# and there's no way to modify the cache after the job that created it finishes.
- name: Clean gradle build cache to assemble fresh
run: |
ls -lhrt $GRADLE_CACHE_PATH || true
rm -rf $GRADLE_CACHE_PATH/build-cache-1
ls -lhrt $GRADLE_CACHE_PATH || true
ls -lhrt "$GRADLE_HOME/caches" || true
rm -rf "$GRADLE_HOME/caches/build-cache-1"
ls -lhrt "$GRADLE_HOME/caches" || true

## Actual task
- name: Assemble with gradle
run: ./gradlew assemble --build-cache --no-daemon --stacktrace
run: ./gradlew assemble --build-cache --no-daemon --stacktrace --gradle-user-home "$GRADLE_HOME"

# Runs all check tasks in parallel.
check:
Expand Down Expand Up @@ -84,28 +81,26 @@ jobs:
- name: Cache build artifacts
uses: actions/cache@v1
with:
path: ${{ env.GRADLE_CACHE_PATH }}
path: ${{ env.GRADLE_HOME }}/caches
# Don't set restore-keys so cache is always only valid for the current build config.
# Also don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests.
key: gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}-${{ github.sha }}

## Actual task
- name: Check with Gradle
run: ./gradlew ${{ matrix.gradle-task }} --build-cache --no-daemon --stacktrace
run: ./gradlew ${{ matrix.gradle-task }} --build-cache --no-daemon --stacktrace --gradle-user-home "$GRADLE_HOME"

instrumentation-tests:
name: Instrumentation tests
needs: assemble
runs-on: macos-latest
timeout-minutes: 20
timeout-minutes: 30
strategy:
# Allow tests to continue on other devices if they fail on one device.
fail-fast: false
matrix:
api-level:
# Tests are failing on APIs <24.
#- 21
#- 23
- 21
- 24
- 29
steps:
Expand All @@ -119,7 +114,7 @@ jobs:
- name: Cache build artifacts
uses: actions/cache@v1
with:
path: ${{ env.GRADLE_CACHE_PATH }}
path: ${{ env.GRADLE_HOME }}/caches
# Don't set restore-keys so cache is always only valid for the current build config.
# Also don't use ${{ runner.os }} in the key so we don't re-assemble for UI tests.
key: gradle-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/buildSrc/**') }}-${{ github.sha }}
Expand All @@ -130,4 +125,9 @@ jobs:
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
script: ./gradlew connectedCheck --build-cache --no-daemon --stacktrace
script: ./gradlew connectedCheck --build-cache --no-daemon --stacktrace --gradle-user-home "$GRADLE_HOME"
- name: Upload results
uses: actions/upload-artifact@v2
with:
name: instrumentation-test-results
path: ./**/build/reports/androidTests/connected/**
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Change Log
==========

Version 0.29.0
--------------

_2020-05-18_

* First release from separate repo.
* Update: Compose version to dev11. (#26)
* New: Add the ability to display nested renderings with `bindCompose`. (#7)
* New: Introduce `ComposeWorkflow`, a self-rendering Workflow. (#8)
* New: Introduce tooling module with support for previewing ViewBindings with Compose's Preview. (#15)
* New: Introduce WorkflowContainer for running a workflow inside a Compose app. (#16)
* Breaking: Tidy up the package structure. (#23)
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# workflow-kotlin-compose

[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.squareup.workflow/workflow-ui-core-compose.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:com.squareup.workflow%20AND%20a:workflow-ui-core-compose)

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

The only integration that is currently supported is the ability to define [ViewFactories][2] that
Expand All @@ -20,8 +23,24 @@ and to experiment with various ways to integrate Compose with Workflow.

## Usage

To get started, you must be using the latest Android Gradle Plugin 4.x version. Then, you need to
enable Compose support in your `build.gradle`:
### Add the dependency

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

```groovy
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`:

```groovy
android {
Expand All @@ -43,11 +62,11 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
}
```

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

```kotlin
val HelloBinding = bindCompose<MyRendering> { rendering ->
val HelloBinding = composedViewFactory<MyRendering> { rendering, _ ->
MaterialTheme {
Clickable(onClick = { rendering.onClick() }) {
Text(rendering.message)
Expand All @@ -56,7 +75,7 @@ val HelloBinding = bindCompose<MyRendering> { rendering ->
}
```

The `bindCompose` function returns a regular [`ViewFactory`][2] which can be added to a
The `composedViewFactory` function returns a regular [`ViewFactory`][2] which can be added to a
[`ViewRegistry`][3] like any other:

```kotlin
Expand Down
104 changes: 104 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Releasing
=========

Production Releases
-------------------

1. Merge an update of [the change log](CHANGELOG.md) with the changes since the last release.

1. Make sure you're on the `master` branch (or fix branch, e.g. `v0.1-fixes`).

1. Confirm that the kotlin build is green before committing any changes
```bash
(cd kotlin && ./gradlew build connectedCheck)
```

1. In `kotlin/gradle.properties`, remove the `-SNAPSHOT` prefix from the `VERSION_NAME` property.
E.g. `VERSION_NAME=0.1.0`

1. Create a commit and tag the commit with the version number:
```bash
git commit -am "Releasing v0.1.0."
git tag v0.1.0
```

1. Upload the kotlin artifacts:
```bash
(cd kotlin && ./gradlew build && ./gradlew uploadArchives --no-parallel)
```

1. Close and release the staging repository at https://oss.sonatype.org.

1. Update the `VERSION_NAME` property in `kotlin/gradle.properties` to the new
snapshot version, e.g. `VERSION_NAME=0.2.0-SNAPSHOT`.

1. Commit the new snapshot version:
```
git commit -am "Finish releasing v0.1.0."
```

1. Push your commits and tag:
```
git push origin master
# or git push origin fix-branch
git push origin v0.1.0
```

1. Create the release on GitHub:
1. Go to the [Releases](https://github.com/square/workflow-kotlin-compose/releases) page for the GitHub
project.
1. Click "Draft a new release".
1. Enter the tag name you just pushed.
1. Title the release with the same name as the tag.
1. Copy & paste the changelog entry for this release into the description.
1. If this is a pre-release version, check the pre-release box.
1. Hit "Publish release".

1. If this was a fix release, merge changes to the master branch:
```bash
git checkout master
git pull
git merge --no-ff v0.1-fixes
# Resolve conflicts. Accept master's versions of gradle.properties and podspecs.
git push origin master
```

1. Publish the website. See below.

---

## Kotlin Notes

### Development

To build and install the current version to your local Maven repository (`~/.m2`), run:

```bash
./gradlew clean installArchives
```

### Deploying

#### Configuration

In order to deploy artifacts to a Maven repository, you'll need to set 4 properties in your private
Gradle properties file (`~/.gradle/gradle.properties`):

```
RELEASE_REPOSITORY_URL=<url of release repository>
SNAPSHOT_REPOSITORY_URL=<url of snapshot repository
SONATYPE_NEXUS_USERNAME=<username>
SONATYPE_NEXUS_PASSWORD=<password>
```

#### Snapshot Releases

Double-check that `gradle.properties` correctly contains the `-SNAPSHOT` suffix, then upload
snapshot artifacts to Sonatype just like you would for a production release:

```bash
./gradlew clean build && ./gradlew uploadArchives --no-parallel
```

You can verify the artifacts are available by visiting
https://oss.sonatype.org/content/repositories/snapshots/com/squareup/workflow/.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.Locale.US
import kotlin.reflect.full.declaredMembers

object Versions {
const val compose = "0.1.0-dev11"
const val compose = "0.1.0-dev12"
const val kotlin = "1.3.71"
const val targetSdk = 29
const val workflow = "0.28.0"
Expand Down
6 changes: 2 additions & 4 deletions compose-tooling/api/compose-tooling.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ public final class com/squareup/workflow/ui/compose/tooling/BuildConfig {
}

public final class com/squareup/workflow/ui/compose/tooling/ComposeWorkflowsKt {
public static final fun preview (Lcom/squareup/workflow/compose/ComposeWorkflow;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;)V
public static synthetic fun preview$default (Lcom/squareup/workflow/compose/ComposeWorkflow;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static final fun preview (Lcom/squareup/workflow/ui/compose/ComposeWorkflow;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;III)V
}

public final class com/squareup/workflow/ui/compose/tooling/ViewFactoriesKt {
public static final fun preview (Lcom/squareup/workflow/ui/ViewFactory;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;)V
public static synthetic fun preview$default (Lcom/squareup/workflow/ui/ViewFactory;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static final fun preview (Lcom/squareup/workflow/ui/ViewFactory;Ljava/lang/Object;Landroidx/ui/core/Modifier;Landroidx/ui/core/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/Composer;III)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import androidx.ui.test.findByText
import androidx.ui.tooling.preview.Preview
import androidx.ui.unit.dp
import com.squareup.workflow.Workflow
import com.squareup.workflow.compose.composed
import com.squareup.workflow.ui.ViewEnvironmentKey
import com.squareup.workflow.ui.compose.showRendering
import com.squareup.workflow.ui.compose.WorkflowRendering
import com.squareup.workflow.ui.compose.composed
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -98,7 +98,7 @@ class PreviewComposeWorkflowTest {
Column {
Text(props.first)
Semantics(container = true, mergeAllDescendants = true) {
environment.showRendering(rendering = props.second)
WorkflowRendering(props.second, environment)
}
}
}
Expand All @@ -111,11 +111,11 @@ class PreviewComposeWorkflowTest {
Workflow.composed<Triple<String, String, String>, Nothing> { props, _, environment ->
Column {
Semantics(container = true) {
environment.showRendering(rendering = props.first)
WorkflowRendering(rendering = props.first, viewEnvironment = environment)
}
Text(props.second)
Semantics(container = true) {
environment.showRendering(rendering = props.third)
WorkflowRendering(rendering = props.third, viewEnvironment = environment)
}
}
}
Expand Down
Loading