Skip to content

Instantly share code, notes, and snippets.

@adityabhaskar
Created December 21, 2025 22:20
Show Gist options
  • Select an option

  • Save adityabhaskar/2b98ad7b25e16ed8ec4f9ea5c300ec79 to your computer and use it in GitHub Desktop.

Select an option

Save adityabhaskar/2b98ad7b25e16ed8ec4f9ea5c300ec79 to your computer and use it in GitHub Desktop.
Modifier to make components invisible
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
/**
* Similar to [android.view.View.INVISIBLE] - when [isVisible] is `false`, the component still
* occupies its space in the composition but does not display.
*/
fun Modifier.visibility(isVisible: Boolean) = this then layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
if (isVisible) {
placeable.placeRelative(0, 0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment