Hello Everyone. Can you guide me about the Modifie...
# compose
b
Hello Everyone. Can you guide me about the Modifiers in Compose? What is the purpose and use cases of Modifier.then(), Modifier.merge() & Modifier.composed?
v
One of the common usages for me for Modifier.then is to conditionally add something to the initial modifier depends on other fields. For simple example:
Copy code
@Composable
fun MyText(
    modifier: Modifier,
    value: String
) {
    Text(
        modifier = modifier
            .then(
                other = if (value.isEmpty()) {
                    Modifier
                        .background(color = Color.Red)
                } else {
                    Modifier
                }
            ),
        text = value,
    )
}
Pretty much sure those function could very useful if you actually have heavy usage of modifiers and pass the same instance of some base modifier to different functions
z
Modifier.composed
is basically deprecated
b
@Zach Klippenstein (he/him) [MOD] what’s the replacement?
z
Modifier.Node and related APIs
b
Ah duh.