Is there a difference between using `this then` vs...
# compose
s
Is there a difference between using
this then
vs simply using
this
?
Copy code
@Compose
fun Modifier.myClickable(...) {
    ...
    return this then Modifier.clickable(...)
}

@Compose
fun Modifier.myClickable(...) {
    ...
    return this.clickable(...)
}
Both seem to be working but I can't find any example for the second one in the documentation.
z
No practical difference, assuming
this
refers to a modifier instance (which it doesn’t appear to in your code).
this then
is just unnecessary when dealing with a modifier factory that already calls
then
internally.
s
Yes, this refers to a modifier instance. Edited the code. Not sure why this then is used everywhere in the documentation in that case.
e
consistency perhaps? if you create a custom ModifierNodeElement then you will need to use
this then
s
Based on my understanding, in the above case
this then
will add an extra layer of modifier compared to the second one. Is that correct?
e
it'll
fold
away
yes it does create one extra intermediate object but in the end the modifier chain only keeps actual modifier elements
z
Not just a node - any time you have a reference to a modifier that you want to chain you need to use
then
. Eg if you call a modifier factory function from a remember lambda for some reason, and then later pass that modifier to a composable, you’d need to use
then
.
137 Views