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

Se7eN

11/20/2020, 11:17 AM
Should I annotate my modifiers with
@Stable
? Also, is it fine to make a modifier composable?
a

Andrey Kulikov

11/20/2020, 3:34 PM
no, you don’t need it this annotation in most cases. we still experimenting with it by adding it on some of our modifiers.
Modifier.yourModifierName()
function shouldn’t be composable according to our guidelines. instead you can use
Modifier.yourModifierName()  = composed { …your code }
which allows you to have a composable factory. When you use it the real composable would be invoked right on the applied Layout. imagine if you apply the same modifier object for two Layouts, in this case they will not share the same state
1
s

Se7eN

11/20/2020, 3:37 PM
Okay so both the customModifiers in this case will have different states, right?
Copy code
Box {
    Image(customModifier)
    Image(customModifier)
}

Modifier.customModifier = composed {
   // some state
}
a

Andrey Kulikov

11/20/2020, 5:57 PM
yes
👍 1