Are there some known cases where `AnimatedVisibili...
# compose-android
v
Are there some known cases where
AnimatedVisibility
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.
Copy code
setContent {
    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()
            )
        }
    }
}
it stops working when uncommenting the second
addView
it doesn't break if the
FrameLayout
is not inside a
RecyclerView
🤔
it also kind of works if you increase the height of the latter box from 1.dp to something bigger