Sevban Bayir
05/04/2024, 8:37 AM@Composable
fun PolygonComposable(polygon: RoundedPolygon, modifier: Modifier = Modifier) =
PolygonComposableImpl(polygon, modifier)
@Composable
private fun MorphComposable(
sizedMorph: Morph,
progress: Float,
modifier: Modifier = Modifier,
isDebug: Boolean = false
) = MorphComposableImpl(sizedMorph, modifier, isDebug, progress)
Why did they seperate the composable to implementation and caller ? What is the benefit of this ?Zach Klippenstein (he/him) [MOD]
05/04/2024, 6:45 PMSevban Bayir
05/05/2024, 9:34 AM@Composable
private fun MorphComposableImpl(
sizedMorph: Morph,
modifier: Modifier = Modifier,
isDebug: Boolean = false,
progress: Float
) {
Box(
modifier
.fillMaxSize()
.drawWithContent {
drawContent()
val scale = min(size.width, size.height)
val path = sizedMorph.toComposePath(progress, scale = scale)
if (isDebug) {
drawPath(path, Color.Green, style = Stroke(2f))
sizedMorph.forEachCubic(progress) { cubic ->
cubic.transform { x, y -> TransformResult(x * scale, y * scale) }
debugDraw(cubic)
}
} else {
drawPath(path, Color.White)
}
})
}
@Composable
internal fun PolygonComposableImpl(
polygon: RoundedPolygon,
modifier: Modifier = Modifier,
debug: Boolean = false
) {
val sizedShapes = remember(polygon) { mutableMapOf<Size, List<Cubic>>() }
Box(
modifier
.fillMaxSize()
.drawWithContent {
drawContent()
val scale = min(size.width, size.height)
val shape = sizedShapes.getOrPut(size) { polygon.cubics.scaled(scale) }
if (debug) {
shape.forEach { cubic -> debugDraw(cubic) }
} else {
drawPath(shape.toPath(), Color.White)
}
})
}
and the repo: https://github.com/chethaase/ShapesDemoZach Klippenstein (he/him) [MOD]
05/06/2024, 3:32 PMSevban Bayir
05/06/2024, 3:33 PMZach Klippenstein (he/him) [MOD]
05/06/2024, 3:39 PMSevban Bayir
05/06/2024, 3:52 PMSevban Bayir
05/06/2024, 3:53 PMChris Athanas
05/08/2024, 7:24 PMZach Klippenstein (he/him) [MOD]
05/08/2024, 7:28 PMPolygonComposable
is calling without more bytecode manipulation than most mocking libraries do by default.Zach Klippenstein (he/him) [MOD]
05/08/2024, 7:28 PM