https://kotlinlang.org logo
#compose
Title
# compose
j

Jeisson Sáchica

10/22/2020, 5:40 PM
Hey guys! I have a question. Is there a reason why creating a custom shape that uses the Outline.Rect where width or height are zero draws it with the whole width and height? Ex:
Copy code
@Stable
val EmptyRectangleShape: Shape = object: Shape {
    override fun createOutline(size: Size, density: Density): Outline =
        Outline.Rectangle(Rect.Zero)
}
I think @Leland Richardson [G] had this problem in one of the streams with the movie app when clipping using a custom shape like this, and in the cases where the width of the rect was zero it was drawing the shape as if it had the full width. Is this something that will be worked on or is it the expected behaviour on those cases?
l

Leland Richardson [G]

10/22/2020, 5:44 PM
i believe this is “working as intended”, but whether or not it should be the intended behavior i think may still be up for debate
j

Jeisson Sáchica

10/22/2020, 5:52 PM
Hmm I see. I do think it makes sense to respect the dimensions of the specified rect. I guess my use case is that for specific cases I needed an "empty" shape for clipping and basically not show the content on conditions that are off my scroll boundaries.
I had to play with the opacity or straight up not show the composable whichh might make things out of sync, especially with animations. So to handle everything just with the clipping would be way easier
a

Andrey Kulikov

10/22/2020, 6:07 PM
how do you use this shape afterwards? pass to modifier.clip()?
I think it worth filing a bug so we can double check if it works as expected
l

Leland Richardson [G]

10/22/2020, 6:08 PM
i’m chatting w/ nader about this now
if you use
clipRect(0f,0f,0f,0f) { drawContent() }
it works as you’d expect
i think this behavior is specific to the Outline/Shape API.
a

Andrey Kulikov

10/22/2020, 6:12 PM
I think the bug is in OutlineResolver#outline. there we have
Copy code
return if (!outlineNeeded || cachedOutline.isEmpty) null else cachedOutline
and isEmpty is true when you pass empty rect
definitely a bug. could you please file?
j

Jeisson Sáchica

10/22/2020, 7:05 PM
Yup sure! Will do now
3 Views