Hey. Why is it that there’s no easy way to combine...
# compose
g
Hey. Why is it that there’s no easy way to combine or modify
PaddingValues
. Sometimes I would like to combine padding values like
WindowInsets.ime.asPaddingValues - PaddingValues(bottom = 30.dp)
. Other times I would just like to override some default padding values like
BottomSheetDefaults.ContentPadding.copy(bottom = 0.dp)
. Shouldn’t this be easier in the compose APIs ? Or am I missing the right way to do this?
4
z
Please file a feature request
q
I create an extension for + and - on PaddingValues I also found it weird that this is not included.
g
a
The hardcoded LTR is going to give you a bad time
You're going to have to return a PaddingValues that holds onto both inputs so it can delegate with the right layout direction when asked
z
Was just going to say that, probably huge headache when RTL support lands in the future and the padding is off for some reason. LocalLayoutDirection.current
a
Nope, not
LocalLayoutDirection
either
Calculate on the fly
z
Oh, I think I understand what you mean.
a
Bidi padding when mixed relative and absolute paddings are involved is a nightmare
Anything you try to cache or precompute will be a bug later
g
So there’s no straightforward solution for this? I’d have to make a new implementation of
PaddingValues
The issue I filed has people mentioning that it shouldn’t be a problem to support this. I was hoping to just have it now instead of waiting for it to be implemented in foundation and released
z
Couldnt you do something like this?
Copy code
class CombinedPaddingValues(
    val first: PaddingValues,
    val second: PaddingValues,
) : PaddingValues {

    override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp {
        return first.calculateLeftPadding(layoutDirection) + second.calculateLeftPadding(layoutDirection)
    }
}
g
What if I want to implement a minus then? Another implementation?
z
Its far from ideal, especially if you need to do it yourself as compared to it already being in one of the compose libraries. Ive starred the issue!