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

Commit fd296d7

Browse files
fixed measuring issue
1 parent ff927c4 commit fd296d7

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ParentComposition.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ internal data class ParentComposition(
5050
* Creates a [ParentComposition] from the current point in the composition and adds it to this
5151
* [ViewEnvironment].
5252
*/
53-
@Composable internal fun ViewEnvironment.withParentComposition(): ViewEnvironment {
53+
@Composable internal fun ViewEnvironment.withParentComposition(
54+
reference: CompositionReference = compositionReference()
55+
): ViewEnvironment {
5456
val compositionReference = ParentComposition(
55-
reference = compositionReference(),
57+
reference = reference,
5658
recomposer = currentComposer.recomposer
5759
)
5860
return this + (ParentComposition to compositionReference)

core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewFactories.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616
package com.squareup.workflow.ui.compose.internal
1717

1818
import android.view.View
19+
import android.view.ViewGroup
1920
import androidx.compose.Composable
21+
import androidx.compose.compositionReference
2022
import androidx.compose.onPreCommit
2123
import androidx.compose.remember
24+
import androidx.ui.core.AndroidOwner
2225
import androidx.ui.core.ContextAmbient
2326
import androidx.ui.core.Modifier
27+
import androidx.ui.core.OwnerAmbient
2428
import androidx.ui.core.Ref
2529
import androidx.ui.foundation.Box
30+
import androidx.ui.foundation.drawBorder
31+
import androidx.ui.graphics.Color
32+
import androidx.ui.unit.dp
2633
import androidx.ui.viewinterop.AndroidView
2734
import com.squareup.workflow.ui.ViewEnvironment
2835
import com.squareup.workflow.ui.ViewFactory
@@ -51,7 +58,7 @@ import com.squareup.workflow.ui.showRendering
5158
modifier: Modifier = Modifier
5259
) {
5360
val viewFactory = this
54-
Box(modifier = modifier) {
61+
Box(modifier = modifier.drawBorder(1.dp, Color.Red)) {
5562
// Fast path: If the child binding is also a Composable, we don't need to go through the legacy
5663
// view system and can just invoke the binding's composable function directly.
5764
if (viewFactory is ComposeViewFactory) {
@@ -73,16 +80,22 @@ import com.squareup.workflow.ui.showRendering
7380
viewEnvironment: ViewEnvironment
7481
): Pair<View, ViewEnvironment> {
7582
val childView = remember { Ref<View>() }
83+
val compRef = compositionReference()
7684
val newEnvironment = if (childView.value?.canShowRendering(rendering) != true) {
85+
// If we don't pass the parent Android View, the child will have the wrong LayoutParams.
86+
@Suppress("DEPRECATION")
87+
val parentView = (OwnerAmbient.current as? AndroidOwner)?.view as? ViewGroup
88+
7789
// Plumb the current composition "context" through the ViewEnvironment so any nested
7890
// composable factories get access to any ambients currently in effect.
7991
// See setOrContinueContent().
80-
viewEnvironment.withParentComposition()
92+
viewEnvironment.withParentComposition(compRef)
8193
.also { newEnvironment ->
8294
childView.value = viewFactory.buildView(
8395
initialRendering = rendering,
8496
initialViewEnvironment = newEnvironment,
85-
contextForNewView = ContextAmbient.current
97+
contextForNewView = ContextAmbient.current,
98+
container = parentView
8699
)
87100
}
88101
} else viewEnvironment

0 commit comments

Comments
 (0)