Is there an equivalent to `View.setVisibility` on ...
# compose
g
Is there an equivalent to
View.setVisibility
on Composables? I’d like to hide a Composable when needed but not just change its opacity because this means it still catches onClicks!
I found some kind of solution, not one that I really like I must say:
Copy code
var modifier = Modifier.fillMaxSize()

        modifier = if (showProgress) modifier + Modifier.noTap().drawOpacity(1f)
        else modifier + Modifier.drawOpacity(0f)
r
Don't add it to the tree then? You can do that with a simple if. Unless I'm not understanding what you want to achieve.
a
I thought the idea of visibility in compose is not rendering it in code
Copy code
if (showProgress){
  ProgressDialog(...)
}
g
That’s actually…. so simple… 🤦 thanks to you both
r
That's the cool part of being declarative :D
g
Yes, it seems that 10 years of non-declarative UI molded my brain to think in a certain way 😂
g
So far I was doing it exactly as stated above, not adding it in the tree. That's the equivalent of
gone
, out of curiosity what about
invisible
?
m
I still don't get it. Would someone help clarify for me please? It's already in tree. How to remove it then?
a
simply use the snippet I put above, @composable functions define the components on every recompose
b
Composable's have the ability to recompose by design. If you don't need the view to be present simply don't add it to the tree like others have stated :)