diff --git a/ui/src/main/java/kiwi/orbit/compose/ui/layout/ExpandModifier.kt b/ui/src/main/java/kiwi/orbit/compose/ui/layout/ExpandModifier.kt index 88d389ad7..4cc9c322c 100644 --- a/ui/src/main/java/kiwi/orbit/compose/ui/layout/ExpandModifier.kt +++ b/ui/src/main/java/kiwi/orbit/compose/ui/layout/ExpandModifier.kt @@ -12,10 +12,10 @@ import androidx.compose.ui.unit.constrainWidth import androidx.compose.ui.unit.offset /** - * Expands drawing beyond the assigned rect on all sides by provided [shift] size. + * Expands drawing beyond the assigned rect on all sides by provided [all] size. * * This modifier may be utilized to workaround (shadow)cropping issues. Apply the same - * [shift] to the inner content as a padding. + * [all] shift to the inner content as a padding. * * ``` * AnimatedContent(Modifier.expand(16.dp)) { @@ -23,24 +23,41 @@ import androidx.compose.ui.unit.offset * } * ``` */ -public fun Modifier.expand(shift: Dp): Modifier = - then(ExpandModifier(shift)) +public fun Modifier.expand(all: Dp): Modifier = + then(ExpandModifier(all, all)) + +/** + * Expands drawing beyond the assigned rect on all sides by provided [horizontal] and [vertical] size. + * + * This modifier may be utilized to workaround (shadow)cropping issues. Apply the same + * [horizontal] and [vertical] shift to the inner content as a padding. + * + * ``` + * AnimatedContent(Modifier.expand(horizontal = 16.dp, vertical = 8.dp)) { + * CustomContent(Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) + * } + * ``` + */ +public fun Modifier.expand(horizontal: Dp, vertical: Dp): Modifier = + then(ExpandModifier(horizontal, vertical)) private data class ExpandModifier( - private val shift: Dp, + private val horizontalShift: Dp, + private val verticalShift: Dp, ) : LayoutModifier { override fun MeasureScope.measure(measurable: Measurable, constraints: Constraints): MeasureResult { - val shiftPx = shift.roundToPx() + val shiftXPx = horizontalShift.roundToPx() + val shiftYPx = verticalShift.roundToPx() val expandedConstraints = constraints.offset( - horizontal = shiftPx * 2, - vertical = shiftPx * 2, + horizontal = shiftXPx * 2, + vertical = shiftYPx * 2, ) val placeable = measurable.measure(expandedConstraints) - val width = constraints.constrainWidth(placeable.width - shiftPx * 2) - val height = constraints.constrainHeight(placeable.height - shiftPx * 2) + val width = constraints.constrainWidth(placeable.width - shiftXPx * 2) + val height = constraints.constrainHeight(placeable.height - shiftYPx * 2) return layout(width, height) { - placeable.place(-shiftPx, -shiftPx) + placeable.place(-shiftXPx, -shiftYPx) } } }