Stylianos Gakis
08/19/2022, 8:13 AMmovableContentOf()
, got an issue where the state does not persist when (I think) I’m using the content normally on one end, and inside a SubComposeLayout on the other call site. More details in Thread 🧵val movableItem = remember { movableContentOf... }
if(true) {
Foo1(movableItem)
} else {
Foo2(movableItem)
}
fun Foo1(movableItem) {
ModalBottomSheetLayout(...) {
movableItem()
}
}
fun Foo2(movableItem) {
Stuff() {
movableItem()
}
}
And I feel like since ModalBottomSheetLayout uses subcomposition this does not work. If I specifically move inside Foo1
the movableItem()
call to outside of the bottom sheet the state is persisted perfectly fine!movableContentOf()
so there’s a good chance I’m completely missing something of course.fengdai
08/19/2022, 8:42 AMStylianos Gakis
08/19/2022, 8:47 AM@Composable
fun Demo() {
val movableItem = remember {
movableContentOf<String> { text ->
val infiniteTransition = rememberInfiniteTransition()
val height by infiniteTransition.animateValue(50.dp, 150.dp, Dp.VectorConverter, infiniteRepeatable(tween(600), RepeatMode.Reverse))
Text(text, Modifier.height(height).border(1.dp, Color.Red))
}
}
var placementFlag by remember { mutableStateOf(true) }
Box(Modifier.fillMaxSize()) {
Button(onClick = { placementFlag = !placementFlag }) {
Text("Flip state")
}
if (placementFlag) {
Column(Modifier.align(Alignment.Center)) {
Text("Smth else")
Spacer(Modifier.height(40.dp))
movableItem("cat")
}
} else {
//BoxWithConstraints(Modifier.align(Alignment.Center)) { // uncomment this (and the '}' below) to break the movableContentOf
Column(Modifier.align(Alignment.Center)) {
movableItem("cat12")
Spacer(Modifier.height(40.dp))
Text("Smth else")
}
//}
}
}
}