16
16
package com.squareup.workflow.ui.compose.internal
17
17
18
18
import android.view.View
19
+ import android.view.ViewGroup
19
20
import androidx.compose.Composable
21
+ import androidx.compose.compositionReference
20
22
import androidx.compose.onPreCommit
21
23
import androidx.compose.remember
24
+ import androidx.ui.core.AndroidOwner
22
25
import androidx.ui.core.ContextAmbient
23
26
import androidx.ui.core.Modifier
27
+ import androidx.ui.core.OwnerAmbient
24
28
import androidx.ui.core.Ref
25
29
import androidx.ui.foundation.Box
30
+ import androidx.ui.foundation.drawBorder
31
+ import androidx.ui.graphics.Color
32
+ import androidx.ui.unit.dp
26
33
import androidx.ui.viewinterop.AndroidView
27
34
import com.squareup.workflow.ui.ViewEnvironment
28
35
import com.squareup.workflow.ui.ViewFactory
@@ -51,7 +58,7 @@ import com.squareup.workflow.ui.showRendering
51
58
modifier : Modifier = Modifier
52
59
) {
53
60
val viewFactory = this
54
- Box (modifier = modifier) {
61
+ Box (modifier = modifier.drawBorder( 1 .dp, Color . Red ) ) {
55
62
// Fast path: If the child binding is also a Composable, we don't need to go through the legacy
56
63
// view system and can just invoke the binding's composable function directly.
57
64
if (viewFactory is ComposeViewFactory ) {
@@ -73,16 +80,22 @@ import com.squareup.workflow.ui.showRendering
73
80
viewEnvironment : ViewEnvironment
74
81
): Pair <View , ViewEnvironment > {
75
82
val childView = remember { Ref <View >() }
83
+ val compRef = compositionReference()
76
84
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
+
77
89
// Plumb the current composition "context" through the ViewEnvironment so any nested
78
90
// composable factories get access to any ambients currently in effect.
79
91
// See setOrContinueContent().
80
- viewEnvironment.withParentComposition()
92
+ viewEnvironment.withParentComposition(compRef )
81
93
.also { newEnvironment ->
82
94
childView.value = viewFactory.buildView(
83
95
initialRendering = rendering,
84
96
initialViewEnvironment = newEnvironment,
85
- contextForNewView = ContextAmbient .current
97
+ contextForNewView = ContextAmbient .current,
98
+ container = parentView
86
99
)
87
100
}
88
101
} else viewEnvironment
0 commit comments