https://kotlinlang.org logo
#compose
Title
# compose
g

gsala

08/25/2022, 4:17 PM
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

Zach Klippenstein (he/him) [MOD]

08/29/2022, 8:04 PM
Please file a feature request
q

Quinten Schelfhout

08/30/2022, 1:54 PM
I create an extension for + and - on PaddingValues I also found it weird that this is not included.
g

gsala

09/01/2022, 8:10 AM
a

Adam Powell

09/15/2022, 1:36 PM
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

Zoltan Demant

09/15/2022, 1:38 PM
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

Adam Powell

09/15/2022, 1:38 PM
Nope, not
LocalLayoutDirection
either
Calculate on the fly
z

Zoltan Demant

09/15/2022, 1:39 PM
Oh, I think I understand what you mean.
a

Adam Powell

09/15/2022, 1:40 PM
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

gsala

09/15/2022, 1:45 PM
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

Zoltan Demant

09/15/2022, 1:49 PM
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

gsala

09/15/2022, 2:03 PM
What if I want to implement a minus then? Another implementation?
z

Zoltan Demant

09/15/2022, 2:05 PM
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!
9 Views