Giter VIP home page Giter VIP logo

Comments (6)

JakeWharton avatar JakeWharton commented on July 26, 2024 1

Yes. Although that doesn't cover Box.

I think we should actually switch to a completely empty Modifier not just remove one. Then every test should snap back to the same image.

from redwood.

ahmed3elshaer avatar ahmed3elshaer commented on July 26, 2024

Can we add these modifier removal test functions to the existing shared screenshot tests AbstractFlexContainerTest?

from redwood.

ahmed3elshaer avatar ahmed3elshaer commented on July 26, 2024

What is the proper method for switching to an empty modifier? I tried widget.modifier = Modifier which results in different behaviors from ComposeUI and View.

For example when I created and recorded the following screenshot test inside AbstractFlexContainerTest

@Test
  fun testColumnWithChildModifierChanges() {
    testContainerWithChildrenModifierChanges(FlexDirection.Column)
  }

  @Test
  fun testRowWithChildModifierChanges() {
    testContainerWithChildrenModifierChanges(FlexDirection.Row)
  }

  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)

    val first = text(longText(), backgroundColor = Red)
    first.modifier = MarginImpl(30.dp)

    container.add(first)
    container.add(text(mediumText(), backgroundColor = Green))
    container.add(text(shortText(), backgroundColor = Blue))
    container.onEndChanges()
    verifySnapshot(container, "Assigned_Modifier")

    first.modifier = Modifier
    container.onEndChanges()
    verifySnapshot(container, "Empty_Modifier")
  }

ComposeUI outputs the expected screenshots, while View always outputs the screenshot with a margin applied, Note that I tried different modifiers and widgets and I get similar results
I feel that I'm missing something ๐Ÿ˜…

Platform Assigned Modifier Empty Modifier
ComposeUI app cash redwood layout composeui_ComposeUiFlexContainerTest_testColumnWithChildModifierChanges LTR_assigned_modifier app cash redwood layout composeui_ComposeUiFlexContainerTest_testColumnWithChildModifierChanges LTR _empty_modifier
View app cash redwood layout view_ViewFlexContainerTest_testColumnWithChildModifierChanges LTR _assigned_modifier app cash redwood layout view_ViewFlexContainerTest_testColumnWithChildModifierChanges LTR _empty_modifier

from redwood.

ahmed3elshaer avatar ahmed3elshaer commented on July 26, 2024

Also in AbstractBoxTest When I attempt to call verifySnapshot(widget.value) once with the modifier assigned and again when the modifier is emptied, I receive a crash from the View platform.

app.cash.redwood.layout.view.ViewBoxTest > testChildrenModifierChanges[RTL] FAILED
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:5248)
        at android.view.ViewGroup.addView(ViewGroup.java:5077)
        at android.view.ViewGroup.addView(ViewGroup.java:5017)
        at android.view.ViewGroup.addView(ViewGroup.java:4989)
        at app.cash.redwood.layout.view.ViewBoxTest.verifySnapshot(ViewBoxTest.kt:69)
        at app.cash.redwood.layout.view.ViewBoxTest.verifySnapshot(ViewBoxTest.kt:33)

Test function

@Test
  fun testChildrenModifierChanges() {
    val redColor = coloredText(MarginImpl(30.dp), longText(), Red)
    val widget = box().apply {
      width(Constraint.Fill)
      height(Constraint.Fill)
      children.insert(0, redColor)
      children.insert(1, coloredText(text = mediumText(), color = Blue))
      children.insert(2, coloredText(text = shortText(), color = Green))
    }
    verifySnapshot(widget.value)
    redColor.modifier = Modifier
    widget.children.onModifierUpdated(0, redColor)
    verifySnapshot(widget.value)
  }

from redwood.

ahmed3elshaer avatar ahmed3elshaer commented on July 26, 2024

@JakeWharton , sorry for bothering you with a lot of questions ๐Ÿ™, Let me know if my approach with the test functions is what we need

from redwood.

JakeWharton avatar JakeWharton commented on July 26, 2024

So it sounds like views are just broken today (which is the point of the tests!). We can file a separate bug about them not clearing state.

from redwood.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.