I am currently working on an Android library called Floating-Bubble-View, this library helps create a floating view on the screen. Recently, I added support for Composable
and with the help of a custom LifecycleOwner
, I can show/remove the composable without any issue. However, when scrolling through the LazyColumn, if I call removeView
before the animation stops, the app start crashing. this is the error message:
Process: com.torrydo.testfloatingbubble, PID: 29264
java.lang.IllegalStateException: Cannot start this animator on a detached view!
at android.graphics.RenderNode.addAnimator(RenderNode.java:1469)
at android.graphics.animation.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:288)
at android.graphics.animation.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:277)
at android.graphics.drawable.RippleForeground.startPending(RippleForeground.java:139)
at android.graphics.drawable.RippleForeground.drawHardware(RippleForeground.java:168)
at android.graphics.drawable.RippleForeground.draw(RippleForeground.java:340)
at android.graphics.drawable.RippleDrawable.drawBackgroundAndRipples(RippleDrawable.java:848)
at android.graphics.drawable.RippleDrawable.draw(RippleDrawable.java:679)
at android.view.View.drawBackground(View.java:22581)
at android.view.View.draw(View.java:22342)
at androidx.compose.material.ripple.AndroidRippleIndicationInstance.drawIndication(Ripple.android.kt:204)
and this is remove function
fun remove() {
builder.composeView?.also { composeView ->
builder.composeLifecycleOwner?.onPause()
builder.composeLifecycleOwner?.onStop()
windowManager!!.removeView(composeView)
}
}
basic composable with a button to pop back to the screen, and a LazyColumn