Skip to content

Instantly share code, notes, and snippets.

@akshat12
Created September 4, 2025 06:07
Show Gist options
  • Select an option

  • Save akshat12/d9b3a80622adc86902f93ab82d52bcd5 to your computer and use it in GitHub Desktop.

Select an option

Save akshat12/d9b3a80622adc86902f93ab82d52bcd5 to your computer and use it in GitHub Desktop.
@Composable
fun ConditionalColumnLayoutWithThreshold() {
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
// This '200.dp' is brittle and doesn't adapt to content changes!
if (maxHeight > 200.dp) {
Column {
Text("Top Element", Modifier.background(Color.Yellow).height(100.dp))
Text("Middle Element", Modifier.background(Color.Green).height(50.dp))
Text("Bottom Element", Modifier.background(Color.Blue).height(50.dp))
}
} else {
Column {
Text("Middle Element", Modifier.background(Color.Green).height(50.dp))
Text("Bottom Element", Modifier.background(Color.Blue).height(50.dp))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment