Andrew Hughes
01/28/2022, 12:45 AMAdam Powell
01/28/2022, 2:08 AMAndrew Hughes
01/28/2022, 4:59 AMLocalContentColor
, however, that doesn't really help me in this case since what I want is the color that this composable is going to be sitting on. This will most likely be background
or surface
, so it'll probably fine to just hard code it to one of those. I was just hoping to not have to do that and make it a little more robust (without having to pass the value in either). I know I could also create my own CompositionLocal
instead of passing it down, but that's probably overkill.myanmarking
01/28/2022, 10:05 AMAdam Powell
01/28/2022, 2:45 PMChris Sinco [G]
01/28/2022, 6:10 PMAndrew Hughes
01/29/2022, 10:33 PMShape
so I can clip the touch ripple to the shape. I could create a separate version of the folder with the cutout, but the folder can scale to different sizes while the checkmark circle should stay the same size, so I don't think that will work.
On a separate note, is there a way to convert SVGs or VDs into Shapes? I just manually converted the path data into Path commands, but it'd be helpful if there was a tool to do this.Chris Sinco [G]
01/30/2022, 1:50 AMis there a way to convert SVGs or VDs into Shapes?Not in Android Studio, but I did write this Figma plugin that helps do the conversion. One could write an Android Studio plugin as well since what is happening is it's just transforming SVG paths to Android paths
Andrew Hughes
01/31/2022, 11:38 PMPathParser
which lets me easily convert the path data to a Path
for a Shape
! Obviously it's more efficient to do this conversion once rather than every time, but it definitely makes it easier for prototyping.Chris Sinco [G]
02/01/2022, 1:10 AMAndrew Hughes
02/02/2022, 12:32 AMPathParser().parsePathString()
in order to build the Shape
. However, it appears I can't use PathParser
as I hoped because the Path
for a Shape
needs to be adjusted to match the size of the shape. I'm doing this currently by calculating the scaleX and scaleY between the shape size and path size and then multiplying each point in the path by the appropriate scale when manually calling each Path
command. However, as far as I can tell, there's no way to simply scale a Path
. 😕 I see that Vector.kt
is using PathParser
, but I assume it's just scaling the Canvas
when drawing the path/vector to change it's size.Chris Sinco [G]
02/02/2022, 1:07 AMval bounds = RectF()
val aPath = path.asAndroidPath()
aPath.computeBounds(bounds, true)
val scaleMatrix = Matrix()
scaleMatrix.setScale(
size.width / baseWidth,
size.height / baseHeight,
0f,
0f
)
aPath.transform(scaleMatrix)
Andrew Hughes
02/02/2022, 1:49 AMPath.translate()
but no Path.scale()
(or just Path.transform()
). Do you know if there's any reason these are not exposed by the compose Path
or is it just a matter of it hasn't been implemented yet?class PathShape(
private val pathData: String,
private val pathDataWidth: Float,
private val pathDataHeight: Float,
) : Shape {
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
return Outline.Generic(
PathParser()
.parsePathString(pathData)
.toPath()
.asAndroidPath()
.apply {
transform(Matrix().apply {
setScale(size.width / pathDataWidth, size.height / pathDataHeight)
})
}
.asComposePath())
}
}
Chris Sinco [G]
02/02/2022, 8:28 PMDo you know if there’s any reason these are not exposed by the composeNot sure - maybe @Nader Jawad can commentor is it just a matter of it hasn’t been implemented yet?Path
Nader Jawad
02/02/2022, 8:35 PMAndrew Hughes
02/02/2022, 9:50 PM