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

Benjamin Deroche

10/03/2023, 8:58 AM
I get a lint warning saying modifier factory functions shouldn't use
@Composable
, then how do I get access to
MaterialTheme
there?
Copy code
@Composable
fun Modifier.underlined(
    strokeWidth: Float = 8f,
    color: Color = MaterialTheme.colors.primary
) = composed(
    factory = {
        drawBehind {
            val width: Float = size.width
            val height: Float = size.height - strokeWidth / 2

            drawLine(
                color = color,
                start = Offset(x = 0f, y = height),
                end = Offset(x = width, y = height),
                strokeWidth = strokeWidth
            )
        }
    }
)
b

Blundell

10/03/2023, 9:05 AM
you don't? 🙂 If you look at another Modifier, say background - it does not offer a default for its color - it is a required attribute
😢 1
a

ascii

10/03/2023, 5:37 PM
composed
is more for stateful modifiers. Its overkill for something as simple as accessing theme colors, and comes with a (minor?) performance cost too.