Timo Drick
02/18/2021, 1:27 PMTimo Drick
02/18/2021, 1:36 PMval ld = LocalLayoutDirection.current
val paddingFab = PaddingValues(
start = padding.calculateStartPadding(ld),
top = padding.calculateTopPadding(),
end = padding.calculateEndPadding(ld),
bottom = padding.calculateBottomPadding() + fabHeight
)
grandstaish
02/18/2021, 1:51 PMplus
operator, but I agree it seems like something that should be provided out of the box.
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = TODO()
Then you could +
your paddings together:
val padding = PaddingValues(...)
val fabPadding = PaddingValues(bottom = ...)
val result = padding + fabPadding
Timo Drick
02/18/2021, 1:52 PM@Composable
fun PaddingValues.add(start: Dp = 0.dp, top: Dp = 0.dp, end: Dp = 0.dp, bottom: Dp = 0.dp): PaddingValues {
val ld = LocalLayoutDirection.current
return PaddingValues(
start = calculateStartPadding(ld) + start,
top = calculateTopPadding() + top,
end = calculateEndPadding(ld) + end,
bottom = calculateBottomPadding() + bottom
)
}
grandstaish
02/18/2021, 1:54 PMTimo Drick
02/18/2021, 1:54 PMAndrey Kulikov
02/18/2021, 2:39 PMfun PaddingValues.add(start: Dp = 0.dp, top: Dp = 0.dp, end: Dp = 0.dp, bottom: Dp = 0.dp): PaddingValues {
return object: PaddingValues {
override fun calculateLeftPadding(layoutDirection: LayoutDirection) =
this@add.calculateLeftPadding(layoutDirection) +
if (layoutDirection == LayoutDirection.Ltr) start else end
override fun calculateTopPadding(): Dp =
this@add.calculateTopPadding() + top
override fun calculateRightPadding(layoutDirection: LayoutDirection) =
this@add.calculateRightPadding(layoutDirection) +
if (layoutDirection == LayoutDirection.Ltr) end else start
override fun calculateBottomPadding() =
this@add.calculateBottomPadding() + bottom
}
}
as a non composable optionTimo Drick
02/18/2021, 3:21 PMAndrey Kulikov
02/18/2021, 4:07 PM