Created
December 21, 2025 22:20
-
-
Save adityabhaskar/2b98ad7b25e16ed8ec4f9ea5c300ec79 to your computer and use it in GitHub Desktop.
Modifier to make components invisible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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