Skip to content

Conversation

@tom0334
Copy link
Contributor

@tom0334 tom0334 commented Nov 3, 2025

As discussed in the android Coffee on 3-11-2025

Why is this important?

It's useful! It lets you avoid making ugly chains with modifiers like this for example:

val modifier = Modifier
.width(300.dp)

if( clickable){
modifier.clickable(.....)
}
modifier.padding(30.dp)

Box(modifier = modifier){=
// content here..

}


Instead, you can do this:


Box( modifier = Modifier
.width(300.dp)
.applyIf( clickable) { Modifier.Clickable( ...) })
.padding(30.dp)

Notes

We discussed this during the android coffee meeting, and it was proposed I make a PR on the template out of it.

I'm aware this kind of thing is bad to do in swiftUI (Mathijs said so), but after some research and discussion in slack it was deemed to fine for compose.

As discussed in the android Coffee on 3-11-2025
@ninovanhooff ninovanhooff merged commit df9daa6 into develop Nov 28, 2025
3 checks passed
@ninovanhooff ninovanhooff deleted the ModifierApplyIfExtension branch November 28, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants