Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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/ui/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/ui/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 @@ -18,29 +18,28 @@
package com.squareup.workflow.ui.compose.tooling

import androidx.compose.Composable
import androidx.ui.core.DrawScope
import androidx.ui.core.Modifier
import androidx.ui.core.clipToBounds
import androidx.ui.core.drawBehind
import androidx.ui.foundation.Box
import androidx.ui.foundation.Text
import androidx.ui.foundation.drawBorder
import androidx.ui.geometry.Offset
import androidx.ui.geometry.toRect
import androidx.ui.graphics.Color
import androidx.ui.graphics.Paint
import androidx.ui.graphics.Shadow
import androidx.ui.graphics.painter.Stroke
import androidx.ui.graphics.painter.drawCanvas
import androidx.ui.graphics.painter.rotate
import androidx.ui.graphics.drawscope.DrawScope
import androidx.ui.graphics.drawscope.Stroke
import androidx.ui.graphics.drawscope.drawCanvas
import androidx.ui.graphics.drawscope.rotate
import androidx.ui.graphics.withSaveLayer
import androidx.ui.layout.fillMaxSize
import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextAlign
import androidx.ui.tooling.preview.Preview
import androidx.ui.unit.Dp
import androidx.ui.unit.dp
import androidx.ui.unit.px
import androidx.ui.unit.toRect
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.compose.composedViewFactory

Expand Down Expand Up @@ -70,7 +69,7 @@ internal fun placeholderViewFactory(modifier: Modifier): ViewFactory<Any> =
style = TextStyle(
textAlign = TextAlign.Center,
color = Color.White,
shadow = Shadow(blurRadius = 5.px, color = Color.Black)
shadow = Shadow(blurRadius = 5f, color = Color.Black)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Px type is being deleted, replaced with raw floats.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. But…floats? Yuck.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'm not a fan either.

)
)
}
Expand Down
39 changes: 15 additions & 24 deletions core-compose/api/core-compose.api
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public final class com/squareup/workflow/ui/compose/ComposeRendering {
public static final field Companion Lcom/squareup/workflow/ui/compose/ComposeRendering$Companion;
public static final fun <clinit> ()V
public fun <init> (Lkotlin/jvm/functions/Function2;)V
public fun <init> (Lkotlin/jvm/functions/Function4;)V
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parameter count changes are due to the compiler changes that landed in dev12. See release notes for more info.

}

public final class com/squareup/workflow/ui/compose/ComposeRendering$Companion {
Expand All @@ -10,52 +10,43 @@ public final class com/squareup/workflow/ui/compose/ComposeRendering$Companion {
}

public final class com/squareup/workflow/ui/compose/ComposeViewFactory : com/squareup/workflow/ui/ViewFactory {
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function3;)V
public fun <init> (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function5;)V
public fun buildView (Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroid/content/Context;Landroid/view/ViewGroup;)Landroid/view/View;
public fun getType ()Lkotlin/reflect/KClass;
}

public abstract class com/squareup/workflow/ui/compose/ComposeWorkflow : com/squareup/workflow/Workflow {
public fun <init> ()V
public fun asStatefulWorkflow ()Lcom/squareup/workflow/StatefulWorkflow;
public abstract fun render (Ljava/lang/Object;Lcom/squareup/workflow/Sink;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/compose/Composer;)V
public abstract fun render (Ljava/lang/Object;Lcom/squareup/workflow/Sink;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/compose/Composer;II)V
}

public final class com/squareup/workflow/ui/compose/ComposeWorkflowKt {
public static final fun composed (Lcom/squareup/workflow/Workflow$Companion;Lkotlin/jvm/functions/Function4;)Lcom/squareup/workflow/ui/compose/ComposeWorkflow;
public static final fun composed (Lcom/squareup/workflow/Workflow$Companion;Lkotlin/jvm/functions/Function6;)Lcom/squareup/workflow/ui/compose/ComposeWorkflow;
}

public final class com/squareup/workflow/ui/compose/CompositionRootKt {
public static final fun <clinit> ()V
public static final fun withCompositionRoot (Lcom/squareup/workflow/ui/ViewEnvironment;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow/ui/ViewEnvironment;
public static final fun withCompositionRoot (Lcom/squareup/workflow/ui/ViewRegistry;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow/ui/ViewRegistry;
public static final fun withCompositionRoot (Lcom/squareup/workflow/ui/ViewEnvironment;Lkotlin/jvm/functions/Function4;)Lcom/squareup/workflow/ui/ViewEnvironment;
public static final fun withCompositionRoot (Lcom/squareup/workflow/ui/ViewRegistry;Lkotlin/jvm/functions/Function4;)Lcom/squareup/workflow/ui/ViewRegistry;
}

public final class com/squareup/workflow/ui/compose/RenderAsStateKt {
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)Landroidx/compose/State;
public static synthetic fun renderAsState$default (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)Landroidx/compose/State;
public static synthetic fun renderAsState$default (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)Landroidx/compose/State;
public static synthetic fun renderAsState$default (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)Landroidx/compose/State;
public static synthetic fun renderAsState$default (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)Landroidx/compose/State;
public static final fun renderAsState (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)Landroidx/compose/State;
}

public final class com/squareup/workflow/ui/compose/ViewEnvironmentsKt {
public static final fun WorkflowRendering (Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Landroidx/compose/Composer;)V
public static synthetic fun WorkflowRendering$default (Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static final fun WorkflowRendering (Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Landroidx/compose/Composer;III)V
}

public final class com/squareup/workflow/ui/compose/WorkflowContainerKt {
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;)V
public static synthetic fun WorkflowContainer$default (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static synthetic fun WorkflowContainer$default (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static synthetic fun WorkflowContainer$default (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static synthetic fun WorkflowContainer$default (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;ILjava/lang/Object;)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)V
public static final fun WorkflowContainer (Lcom/squareup/workflow/Workflow;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow/ui/ViewEnvironment;Landroidx/ui/core/Modifier;Lcom/squareup/workflow/diagnostic/WorkflowDiagnosticListener;Landroidx/compose/Composer;III)V
}

public final class com/squareup/workflow/ui/compose/internal/ComposeSupportKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.mutableStateOf
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.ui.foundation.Text
import androidx.ui.layout.Column
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.findByText
import com.squareup.workflow.ui.ViewEnvironment
Expand Down Expand Up @@ -53,11 +52,13 @@ class ComposeViewFactoryTest {
RootView(viewEnvironment = viewEnvironment)
}

findByText("one\ntwo").assertIsDisplayed()
// Compose bug doesn't let us use assertIsDisplayed on older devices.
// See https://issuetracker.google.com/issues/157728188.
findByText("one\ntwo").assertExists()
FrameManager.framed {
wrapperText.value = "ENO"
}
findByText("ENO\ntwo").assertIsDisplayed()
findByText("ENO\ntwo").assertExists()
}

private class RootView(context: Context) : FrameLayout(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import androidx.compose.currentComposer
import androidx.compose.mutableStateOf
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.ui.foundation.Text
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.findBySubstring
import androidx.ui.test.findByText
import org.junit.Rule
import org.junit.Test
Expand All @@ -47,7 +47,9 @@ class ComposeSupportTest {
TestComposable("foo")
}

findByText("foo").assertIsDisplayed()
// Compose bug doesn't let us use assertIsDisplayed on older devices.
// See https://issuetracker.google.com/issues/157728188.
findByText("foo").assertExists()
}

@Test fun ambientChangesPassThroughSubcomposition() {
Expand All @@ -56,11 +58,13 @@ class ComposeSupportTest {
TestComposable(ambientValue.value)
}

findByText("foo").assertIsDisplayed()
// Compose bug doesn't let us use assertIsDisplayed on older devices.
// See https://issuetracker.google.com/issues/157728188.
findBySubstring("foo").assertExists()
FrameManager.framed {
ambientValue.value = "bar"
}
findByText("bar").assertIsDisplayed()
findByText("bar").assertExists()
}

@Composable private fun TestComposable(ambientValue: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,19 @@
package com.squareup.workflow.ui.compose.internal

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.compose.Composable
import androidx.compose.Composition
import androidx.compose.CompositionReference
import androidx.compose.FrameManager
import androidx.compose.Recomposer
import androidx.compose.compositionFor
import androidx.lifecycle.LifecycleOwner
import androidx.ui.core.AndroidOwner
import androidx.ui.node.UiComposer
import com.squareup.workflow.ui.compose.internal.ReflectionSupport.ANDROID_OWNER_CLASS
import com.squareup.workflow.ui.compose.internal.ReflectionSupport.androidOwnerView
import com.squareup.workflow.ui.compose.internal.ReflectionSupport.createOwner
import com.squareup.workflow.ui.compose.internal.ReflectionSupport.createWrappedContent
import com.squareup.workflow.ui.compose.internal.ReflectionSupport.ownerRoot
import com.squareup.workflow.ui.core.compose.R

private typealias AndroidOwner = Any
private typealias WrappedComposition = Composition
private typealias LayoutNode = Any

private val DefaultLayoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
Expand All @@ -59,12 +53,13 @@ internal fun ViewGroup.setContent(
parent: CompositionReference,
content: @Composable() () -> Unit
): Composition {
FrameManager.ensureStarted()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes in this file are to ensure this code stays as close as possible to the actual private code in the runtime.

val composeView: AndroidOwner =
if (childCount > 0) {
getChildAt(0).takeIf(ANDROID_OWNER_CLASS::isInstance)
getChildAt(0) as? AndroidOwner
} else {
removeAllViews(); null
} ?: createOwner(context).also { addView(androidOwnerView(it), DefaultLayoutParams) }
} ?: AndroidOwner(context).also { addView(it.view, DefaultLayoutParams) }
return doSetContent(context, composeView, recomposer, parent, content)
}

Expand All @@ -80,53 +75,38 @@ private fun doSetContent(
content: @Composable() () -> Unit
): Composition {
// val original = compositionFor(context, owner.root, recomposer)
val container = ownerRoot(owner)
val original = compositionFor(
container = container,
container = owner.root,
recomposer = recomposer,
parent = parent,
composerFactory = { slotTable, factoryRecomposer ->
UiComposer(context, container, slotTable, factoryRecomposer)
UiComposer(context, owner.root, slotTable, factoryRecomposer)
}
)

val wrapped = androidOwnerView(owner).getTag(R.id.wrapped_composition_tag)
val wrapped = owner.view.getTag(R.id.wrapped_composition_tag)
as? WrappedComposition
// ?: WrappedComposition(owner, original).also {
?: createWrappedContent(owner, original).also {
androidOwnerView(owner).setTag(R.id.wrapped_composition_tag, it)
owner.view.setTag(R.id.wrapped_composition_tag, it)
}
wrapped.setContent(content)
return wrapped
}

private object ReflectionSupport {

val ANDROID_OWNER_CLASS = Class.forName("androidx.ui.core.AndroidOwner")
private val WRAPPED_COMPOSITION_CLASS = Class.forName("androidx.ui.core.WrappedComposition")
private val ANDROID_OWNER_KT_CLASS = Class.forName("androidx.ui.core.AndroidOwnerKt")

private val WRAPPED_COMPOSITION_CTOR =
WRAPPED_COMPOSITION_CLASS.getConstructor(ANDROID_OWNER_CLASS, Composition::class.java)

private val CREATE_OWNER_FUN =
ANDROID_OWNER_KT_CLASS.getMethod("createOwner", Context::class.java, LifecycleOwner::class.java)
private val ANDROID_OWNER_ROOT_GETTER = ANDROID_OWNER_CLASS.getMethod("getRoot")
WRAPPED_COMPOSITION_CLASS.getConstructor(AndroidOwner::class.java, Composition::class.java)

init {
WRAPPED_COMPOSITION_CTOR.isAccessible = true
}

fun createOwner(context: Context): AndroidOwner =
CREATE_OWNER_FUN.invoke(null, context, null) as AndroidOwner

fun ownerRoot(owner: AndroidOwner): LayoutNode =
ANDROID_OWNER_ROOT_GETTER.invoke(owner) as LayoutNode

fun createWrappedContent(
owner: AndroidOwner,
original: Composition
): WrappedComposition = WRAPPED_COMPOSITION_CTOR.newInstance(owner, original) as Composition

fun androidOwnerView(owner: AndroidOwner): View = owner as View
}
Loading