Skip to content

Instantly share code, notes, and snippets.

@sergey-ben
Last active May 21, 2021 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-ben/3622dd192d8e537c41b303cdd757b1fd to your computer and use it in GitHub Desktop.
Save sergey-ben/3622dd192d8e537c41b303cdd757b1fd to your computer and use it in GitHub Desktop.
PositioningIssue
@Composable
fun CollapsibleContent() {
var innerBoxHeight by remember {
mutableStateOf(200.dp)
}
var outerBoxHeight by remember {
mutableStateOf(100.dp)
}
Column {
Row {
Button(
onClick = {
innerBoxHeight = 200.dp
outerBoxHeight = 200.dp
}
) {
Text(text = "Button 1")
}
Spacer(modifier = Modifier.width(8.dp))
Button(
onClick = {
innerBoxHeight = 400.dp
outerBoxHeight = innerBoxHeight
}
) {
Text(text = "Button 2")
}
}
Row {
ComposableWithPositioningIssue(
outerBoxHeight = outerBoxHeight,
innerBoxHeight = innerBoxHeight,
)
}
}
}
@Composable
fun ComposableWithPositioningIssue(
innerBoxHeight: Dp,
outerBoxHeight: Dp
) {
Box(
modifier = Modifier
.height(outerBoxHeight)
.fillMaxWidth()
.clipToBounds()
.background(Color.DarkGray)
) {
Box(
modifier = Modifier
.requiredHeight(innerBoxHeight)
.fillMaxWidth()
.background(Color.Yellow)
) {
Text(text = "text")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment