What this message means 'Modifier factory functions must use the receiver Modifier instance' When w...
m
What this message means 'Modifier factory functions must use the receiver Modifier instance' When writing a modifier like fun Modifier.myModifier(i:Int):Modifier{ return Modifier.border(BorderStroke(1.dp,Color.Blue),RoundedCornerShape(6.dp))} It works as expected ...
z
Probably means you have a function that returns a modifier, but you’re not chaining it to the incoming modifier (specified as the extension receiver). Might be missing a
then
m
Thank you so much, but why then it works?
z
Modifier chaining doesn’t happen by magic. Under the hood, it’s all:
Copy code
Modifier
  .then(modifier1)
  .then(modifier2)
  .then(etc)
If you factor out modifier2 into an extension function like:
Copy code
fun Modifier.modifier2(): Modifier =
  modifier2
Then you lose that chaining:
modifier2
throws away
modifier1
. To preserve the chaining you need to keep using `then`:
Copy code
fun Modifier.modifier2(): Modifier =
  then(modifier2)
m
So nice!! Thank you again (btw very nice articles about state)
3478 Views