Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle visibility of a Text in Jetpack Compose?

I have this Text:

Text(
    text = stringResource(id = R.string.hello)
)

How can I show and hide this component?

I'm using Jetpack Compose version '1.0.0-alpha03'

like image 902
Agna JirKon Rx Avatar asked Oct 14 '20 23:10

Agna JirKon Rx


1 Answers

As CommonsWare stated, compose being a declarative toolkit you tie your component to a state (for ex: isVisible), then compose will intelligently decide which composables depend on that state and recompose them. For ex:

@Composable
fun MyText(isVisible: Boolean){
  if(isVisible){
     Text(text = stringResource(id = R.string.hello))
  }
}

Also you could use the AnimatedVisibility() composable for animations.

like image 190
Róbert Nagy Avatar answered Sep 29 '22 18:09

Róbert Nagy