This used to work but the `clickable` is not bein...
# compose
t
This used to work but the
clickable
is not being applied anymore. What's the proper way to handle dynamic modifiers?
Copy code
val localModifier = Modifier
    .fillMaxWidth()
    .height(IntrinsicSize.Max)
    .apply {
        if (!disableClick) {
            this.clickable {
                Timber.w("Music CLicked")
                onMusicClick.invoke(music)
            }
        }
    }
    .padding(8.dp)
g
I think
clickable
accepts a
enable
parameter. You can pass
!disableClick
there
t
@Giang this solved the problem and it looks 100x better now haha Thanks!
e
Actually surprised this ever worked
It is 100% a bug since calling
clickable
on a modifier creates a new instance
Also the previous code and the new one of setting
enable
are not equivalent at all.
The correct fix is to change
apply
to
run
g
It is 100% a bug since calling
clickable
on a modifier creates a new instance
Agree. Using let or run will work
Also the previous code and the new one of setting
enable
are not equivalent. One always adds the clickable modifier and disables it while the other does not add the clickable at all
Surely they aren’t the same, but I think that’s what Tiago tries to achieve judging from the name of the parameter disableClick
e
Fully agree @Giang. But removing the clickable modifier altogether is slightly better because clickable internally uses
Modifier.composed { ... }
which has some very slight performance impact (cant remember the details)
m
i use: ’modifier.then(if(a) Modifier.sth() else Modifier)