Is there a way to further constrain a `PaddingValues` instance? E.g. say I want to apply some additi...
j
Is there a way to further constrain a
PaddingValues
instance? E.g. say I want to apply some additional padding on top of the one passed in as the receiver in the
Scaffold
content lambda: how to?
n
just add it with β€œ+” operator, for example:
Copy code
Modifier.padding(bottom = paddingValues.calculateBottomPadding() + 300.dp)
n
or
Copy code
Scaffold { scaffoldPadding ->
        Box(
            Modifier
                .padding(scaffoldPadding)
                .padding(24.dp)
                .padding(bottom = 8.dp)
        ) {

        }
    }
(I really like that we can do that)
πŸ‘πŸ½ 1
πŸ‘ 1
πŸ‘πŸ» 1
j
But what when using the
PaddingValues
in a
LazyColumn
contentPadding
? That’s not a modifier so we can’t chain in there.
πŸ‘ 1
n
that's right ! it probably lacks operators like plus or minus I checked if we could add it but it's annoying as we can't use start/end/top/bottom directly from the PaddingValues (private
Ah I used the bug template instead of feature roadmap :s
a
I use this:
Copy code
@Stable
private class AdditionalPaddingValues(
    private val base: PaddingValues,
    private val additionalStart: Dp,
    private val additionalTop: Dp,
    private val additionalEnd: Dp,
    private val additionalBottom: Dp
) : PaddingValues {

    override fun calculateLeftPadding(layoutDirection: LayoutDirection) =
        base.calculateLeftPadding(layoutDirection) +
                if (layoutDirection == LayoutDirection.Ltr) additionalStart else additionalEnd

    override fun calculateTopPadding() =
        base.calculateTopPadding() + additionalTop

    override fun calculateRightPadding(layoutDirection: LayoutDirection) =
        base.calculateRightPadding(layoutDirection) +
                if (layoutDirection == LayoutDirection.Ltr) additionalEnd else additionalStart

    override fun calculateBottomPadding() =
        base.calculateBottomPadding() + additionalBottom

    override fun toString(): String = "AdditionalPaddingValues(base=$base, " +
            "additionalStart=$additionalStart, additionalTop=$additionalTop, " +
            "additionalEnd=$additionalEnd, additionalBottom=$additionalBottom)"

    override fun equals(other: Any?): Boolean = this === other ||
            other is AdditionalPaddingValues && base == other.base
            && additionalStart == other.additionalStart
            && additionalTop == other.additionalTop
            && additionalEnd == other.additionalEnd
            && additionalBottom == other.additionalBottom

    override fun hashCode(): Int {
        var result = base.hashCode()
        result = 31 * result + additionalStart.hashCode()
        result = 31 * result + additionalTop.hashCode()
        result = 31 * result + additionalEnd.hashCode()
        result = 31 * result + additionalBottom.hashCode()
        return result
    }
}
⭐ 1
n
I added it to the issue, thanks !