vide
09/23/2023, 1:36 PMAnimatedVisibility
can skip transitions or are there some extra steps to take when animating size inside Views?
I have an AnimatedVisibility
with expandVertically
and shrinkVertically
inside a ComposeView
nested in a RecyclerView
in an outer ComposeView
. When expanding, the animation doesn't occur and it snaps immediately to full height, but shrinking works normally.vide
09/23/2023, 6:34 PMsetContent {
Column {
Box(Modifier.clickable { visible = !visible }) {
BasicText(text = "Toggle", style = TextStyle(fontSize = 50.sp))
}
AndroidView(factory = {
class Holder(val view: View) : ViewHolder(view)
class FrameCompose(ctx: Context) : FrameLayout(ctx) {
val compose = ComposeView(ctx)
val view = View(ctx)
init {
addView(compose)
//addView(view)
}
}
RecyclerView(it).apply {
layoutManager = LinearLayoutManager(it)
adapter = object : RecyclerView.Adapter<Holder>() {
override fun getItemCount() = 1
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
return Holder(FrameCompose(it))
}
override fun onBindViewHolder(holder: Holder, position: Int) {
(holder.view as FrameCompose).compose.setContent {
Anim { visible }
}
}
}
}
})
}
@Composable
fun Anim(visible: () -> Boolean) {
Column {
AnimatedVisibility(
visible = visible(),
enter = expandVertically(),
exit = shrinkVertically()
) {
Box(
Modifier
.height(300.dp)
.fillMaxWidth()
.background(Color.Magenta)
)
}
Box(
Modifier
.background(Color.Cyan)
.height(height = 1.dp)
.fillMaxWidth()
)
}
}
}
vide
09/23/2023, 6:35 PMaddView
vide
09/23/2023, 6:36 PMFrameLayout
is not inside a RecyclerView
🤔vide
09/23/2023, 6:38 PM