Issue
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'
Solution
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.
Answered By - Róbert Nagy
Answer Checked By - Candace Johnson (JavaFixing Volunteer)