Marcin Wisniowski
11/12/2021, 2:36 PMModifer
conditionally? Like previousModifier().apply{ if(hasPadding) padding(4.dp) }
, except that doesn't work. (I know why it doesn't work, but I don't know a nice method that works)rsktash
11/12/2021, 2:41 PMEric
11/12/2021, 2:42 PMinline fun Modifier.modifyIf(
condition: Boolean,
then: Modifier.() -> Modifier
): Modifier = if (condition) then() else this
.modifyIf(hasPadding) { padding(4.dp) }
Marcin Wisniowski
11/12/2021, 2:47 PMCsaba Kozák
11/12/2021, 3:36 PMapply
will return the original object (this
), so your changes are thrown away. .run { }
would solve the problem with your snippet as well, but you have to add an else
block similar to @Eric did.Marcin Wisniowski
11/12/2021, 4:43 PMapply
doesn't work, and only used it to convey what I am looking for. : ) I tried run
but found it quite verbose with the else
, hence my question. Hiding it in an extension like Eric suggested is a good solution.Csaba Kozák
11/13/2021, 9:58 AMColton Idle
12/01/2021, 4:15 AM