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

galex

08/08/2020, 12:27 PM
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

Ricardo C.

08/08/2020, 12:31 PM
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

allan.conda

08/08/2020, 12:31 PM
I thought the idea of visibility in compose is not rendering it in code
Copy code
if (showProgress){
  ProgressDialog(...)
}
g

galex

08/08/2020, 12:47 PM
That’s actually…. so simple… 🤦 thanks to you both
r

Ricardo C.

08/08/2020, 12:50 PM
That's the cool part of being declarative :D
g

galex

08/08/2020, 12:54 PM
Yes, it seems that 10 years of non-declarative UI molded my brain to think in a certain way 😂
g

Giorgos Neokleous

08/08/2020, 12:55 PM
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

Mehdi Haghgoo

08/08/2020, 5:41 PM
I still don't get it. Would someone help clarify for me please? It's already in tree. How to remove it then?
a

allan.conda

08/08/2020, 5:44 PM
simply use the snippet I put above, @composable functions define the components on every recompose
b

brandonmcansh

08/08/2020, 7:17 PM
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 :)
2 Views