Changing Modifier size maybe possible with creating a Modifier such as SizeModifier
. If anyone posts accurate answer that accomplishes task that way would be more than welcome.
I solved this by first setting a requiredSize to have minimum dimensions for this Composable.
@Composable
fun TransformLayout(
modifier: Modifier = Modifier,
enabled: Boolean = true,
handleRadius: Dp = 15.dp,
handlePlacement: HandlePlacement = HandlePlacement.Corner,
onDown: (Transform) -> Unit = {},
onMove: (Transform) -> Unit = {},
onUp: (Transform) -> Unit = {},
content: @Composable () -> Unit
) {
MorphSubcomposeLayout(
modifier = modifier
.requiredSizeIn(
minWidth = handleRadius * 2,
minHeight = handleRadius * 2
)
}
In SubcomposeLayout
instead of increasing size of Composable by handles which doesn’t work with Modifier.size
I constrained maximum dimensions to maxWidth and maxHeight of constraints with
// Get max width and height of main component
var maxWidth = 0
var maxHeight = 0
mainPlaceables.forEach { placeable: Placeable ->
maxWidth += placeable.width
maxHeight = placeable.height
}
val handleSize = handleRadiusInPx * 2
maxWidth = maxWidth.coerceAtMost(constraints.maxWidth - handleSize)
maxHeight = maxHeight.coerceAtMost(constraints.maxHeight - handleSize)
val maxSize = IntSize(maxWidth, maxHeight)
And passed with subcompose()
function to dependent Composable as dimensions of content
val dependentPlaceables = subcompose(SlotsEnum.Dependent) {
dependentContent(maxSize)
}.map {
it.measure(constraints)
}
When i set dimensions of parent Composable with layout(width, height)
added the handle size or area i subtract initially
width = maxSize.width + 2 * handleRadiusInPx
height = maxSize.height + 2 * handleRadiusInPx
layout(width, height) {
dependentPlaceables.forEach { placeable: Placeable ->
placeable.placeRelative(0, 0)
}
}
This way i’m able to shrink content area by handle size when there is a fixed size modifier, if there is no fixed size modifier to limit measurement with upper bound as big as Composable it works as in question.