Skip to content

Commit

Permalink
Expose children propery for TestFlexContainer
Browse files Browse the repository at this point in the history
Used when we need to notify the parent with change in children's modifier `children.onModifierUpdated`
  • Loading branch information
ahmed3elshaer committed May 3, 2024
1 parent db0e7d0 commit 4068f49
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import app.cash.redwood.layout.AbstractFlexContainerTest
import app.cash.redwood.layout.TestFlexContainer
import app.cash.redwood.layout.widget.FlexContainer
import app.cash.redwood.widget.Widget
import app.cash.redwood.widget.compose.ComposeWidgetChildren
import app.cash.redwood.yoga.FlexDirection
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
Expand Down Expand Up @@ -67,7 +68,7 @@ class ComposeUiFlexContainerTest(
private val delegate: ComposeUiFlexContainer,
) : TestFlexContainer<@Composable () -> Unit>, FlexContainer<@Composable () -> Unit> by delegate {
private var childCount = 0

override val children: ComposeWidgetChildren = delegate.children
constructor(direction: FlexDirection, backgroundColor: Int) : this(
ComposeUiFlexContainer(direction).apply {
testOnlyModifier = Modifier.background(Color(backgroundColor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ abstract class AbstractFlexContainerTest<T : Any> {
private fun testContainerWithChildrenModifierChanges(
flexDirection: FlexDirection,
) {
assumeTrue(flexDirection in listOf(FlexDirection.Row, FlexDirection.Column))
val container = flexContainer(flexDirection)
container.width(Constraint.Fill)
container.height(Constraint.Fill)
Expand All @@ -577,13 +576,15 @@ abstract class AbstractFlexContainerTest<T : Any> {
container.onEndChanges()
verifySnapshot(container, "Margin")
first.modifier = Modifier
container.children.onModifierUpdated(0, first)
container.onEndChanges()
verifySnapshot(container, "Empty")
}
}

interface TestFlexContainer<T : Any> : Widget<T>, ChangeListener {
override val value: T
val children: Widget.Children<T>
fun width(width: Constraint)
fun height(height: Constraint)
fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class UIViewFlexContainerTest(
private val delegate: UIViewFlexContainer,
) : TestFlexContainer<UIView>, FlexContainer<UIView> by delegate, ChangeListener by delegate {
private var childCount = 0
override val children: Widget.Children<UIView> = delegate.children

init {
value.backgroundColor = UIColor(red = 0.0, green = 0.0, blue = 1.0, alpha = 0.2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import app.cash.redwood.layout.AbstractFlexContainerTest
import app.cash.redwood.layout.TestFlexContainer
import app.cash.redwood.layout.widget.FlexContainer
import app.cash.redwood.widget.ChangeListener
import app.cash.redwood.widget.ViewGroupChildren
import app.cash.redwood.widget.Widget
import app.cash.redwood.yoga.FlexDirection
import com.android.resources.LayoutDirection
Expand Down Expand Up @@ -66,7 +67,7 @@ class ViewFlexContainerTest(
private val delegate: ViewFlexContainer,
) : TestFlexContainer<View>, FlexContainer<View> by delegate, ChangeListener by delegate {
private var childCount = 0

override val children: ViewGroupChildren = delegate.children
override fun add(widget: Widget<View>) {
addAt(childCount, widget)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import app.cash.redwood.layout.widget.Row
import app.cash.redwood.lazylayout.composeui.ComposeUiLazyList
import app.cash.redwood.lazylayout.widget.LazyList
import app.cash.redwood.widget.Widget
import app.cash.redwood.widget.compose.ComposeWidgetChildren
import app.cash.redwood.yoga.FlexDirection
import com.android.resources.LayoutDirection
import com.google.testing.junit.testparameterinjector.TestParameter
Expand Down Expand Up @@ -113,6 +114,8 @@ class ComposeUiLazyListTest(
},
)

override val children: ComposeWidgetChildren = delegate.items

override fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class ViewLazyListTest(
},
)

override val children: Widget.Children<View> = delegate.items

override fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) {
}

Expand Down

0 comments on commit 4068f49

Please sign in to comment.