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

Steffen Funke

11/10/2021, 4:21 PM
Is there a way to make
Surface
to not set any
contentColor
, e.g. make it behave like a
Box
in this regard? I have custom colored content (Texts, Sliders, etc….), but as soon as I wrap them into a
ModalBottomSheetLayout
- which is backed by a
Surface
- everything gets tinted with the
contentColor
. I surely miss something here. 🤔
Surface initializer:
Copy code
@Composable
fun Surface(
    modifier: Modifier = Modifier,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colors.surface,
    contentColor: Color = contentColorFor(color),
    border: BorderStroke? = null,
    elevation: Dp = 0.dp,
    content: @Composable () -> Unit
) {
    Surface(
        modifier = modifier,
        shape = shape,
        color = color,
        contentColor = contentColor,
        border = border,
        elevation = elevation,
        content = content,
        clickAndSemanticsModifier = Modifier
            .semantics(mergeDescendants = false) {}
            .pointerInput(Unit) { }
    )
}
Ideally, I would like to set
contentColor
to null to have the widgets shown their color. But I guess that is not how it is supposed to work.
l

Luke

11/10/2021, 4:27 PM
Maybe using
contentColor = Color.Transparent
would help?
Or
Color.Unspecified
s

Steffen Funke

11/10/2021, 4:32 PM
@Luke Interesting, thanks. Indeed that removes the tinting. The alpha however is still a bit off 😩 I am wondering if that has any implications, setting a transparent / unspecified color?
Ok, resetting the Sheet
color
(which actually is its
backgroundColor
) fixes the alpha of the foreground now. Interesting. Thanks for pointing me in the direction @Luke !
👍 1