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

wck

05/27/2022, 12:32 AM
Hi, I had a question regarding default value for
Modifier
as a parameter, apparently
fillMaxWidth
is ignored if passed like this.
Copy code
@Composable
fun TextButton(
    modifier: Modifier = Modifier.fillMaxWidth(),
yeah, that’s the way to go, thanks.
t

tad

05/27/2022, 3:47 AM
Or just
modifier.fillMaxWidth()
This is perfectly idiomatic and is used throughout the Compose codebase.
l

Leland Richardson [G]

05/27/2022, 4:27 PM
yep. convention is to have the default expression just be
modifier: Modifier = Modifier
and then just start your modifier chain with that:
Copy code
InternalTextButton(modifier = modifier.fillMaxWidth().etc(...)
note that the documents saying
the first modifier parameter must: …
are indicating what the convention is, not what is technically allowed/not allowed. what you wrote initially was perfectly valid kotlin, just not what you wanted 🙂
google 1
👍 1
d

dimsuz

06/01/2022, 10:42 AM
convention is to have the default expression just be
modifier: Modifier = Modifier
Oh, I guess I'll add it to the detekt-rules-compose as a new (togglable) rule. UPD: turns out there was already an issue-request for such a rule
4 Views