maybe Modifier.drawBehind?
# compose
a
maybe Modifier.drawBehind?
l
Could it be implemented using clips?
drawBehind is so difficult..
a
you wanted custom background behavior. I think it’s the only option
l
I don’t want a custom background. I just want to crop part of the view.
r
Crop or transparency? Those sound different to me. I just did something with cropping using
Modifier.clip(myShape)
where
myShape
is a
GenericShape { ... }
. In my preview I have a Slider that changes the width of the clip shape from 0 to 100%.
l
@robnik Can i see code of myShape??
I think that is What i want!
r
Copy code
val myClip = GenericShape { size ->
    val right = size.width * fraction
    lineTo(right, 0f)
    lineTo(right, size.height)
    lineTo(0f, size.height)
    close()
}
And fraction is a float from state, getting moved by a slider.
l
Thank you 😃
👍 1
n
Just FYI,
GenericShape
will work here as a parameter to the clip modifier, however, because this is a rectangle, using
RectangleShape
to provide the clipping bounds will be more efficient as it would avoid software rasterization of paths
r
@Nader Jawad The
RectangleShape
I see is a
val
. How do I use it? How do I give it a narrower width so that it actually clips the thing I'm trying to clip/crop?
n
Just pass in that instance of
RectangleShape
Or you can create your own instance of Shape that creates a rectangle based on the percentage offset you wish to clip by
r
Okay, I see - override
Shape
and return an
Outline
that is a
Rectangle
instead of a
Generic
, and get that performance benefit. Thanks!
l
https://github.com/wooooooak/DragToPeekSurface-Compose I did it thanks to you guys. Thank you.
👍 1
a
cool