Animated FAB does wird things with cradling

0

GIF of the app running on actual Device

I think it is quite obvious what should happen.

My main problem is that when the Fab goes down to its previous location it doesn't cradle back into the BottomAppBar. But when you click it again the cradle appears, is there a way to update the BAB manually? (BTW, the FAB going down in the last hit is not intentional, but the cradling is a bigger problem for me now. But if it's just n oversight from me, I'd appreciate a correction)

...
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:foregroundTint="@android:color/white"
android:foregroundTintMode="src_over"
app:contentInsetStart="0dp"
app:fabCradleMargin="7dp"
app:fabCradleRoundedCornerRadius="16dp"
app:hideOnScroll="true">
...
</com.google.android.material.bottomappbar.BottomAppBar>


<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tint="@android:color/white"
app:backgroundTint="@color/colorPrimaryDark"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar"
app:maxImageSize="32dp"
app:srcCompat="@drawable/fab_animation_up" />
...

in the following code for the animation are probably a number of improper or 'bad' things. If there is any better way to easily do this, let me know.

bi.addFab.setOnClickListener {
            val fab = it as FloatingActionButton
            if (bi.editTextCard.visibility == View.INVISIBLE) {
                fab.animate().setDuration(200).translationYBy(-340f).setListener(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator?) {
                        super.onAnimationEnd(animation)
                        fab.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.fab_animation_up, null))
                        bi.backdrop.visibility = View.VISIBLE
                        bi.backdrop.background = ColorDrawable(0x00000000)
                        ViewAnimationUtils.createCircularReveal(bi.editTextCard, fab.x.toInt(), fab.y.toInt(), 0f, bi.editTextCard.height * 1.2f)
                            .also { bi.editTextCard.visibility = View.VISIBLE }.setDuration(300).start()
                        (fab.drawable as AnimatedVectorDrawable).start()
                        bi.backdrop.background = ColorDrawable(0x99000000.toInt())
                        window.navigationBarColor = ResourcesCompat.getColor(resources, R.color.colorPrimaryOccluded, null)
                    }
                }).start()
            } else { //TODO Doesn't really work, doesnt keep the state?!
                ViewAnimationUtils.createCircularReveal(bi.editTextCard, fab.x.toInt(), fab.y.toInt(), bi.editTextCard.height * 1.2f, 0f).setDuration(300).start()
                bi.backdrop.background = ColorDrawable(0x00000000)
                window.navigationBarColor = ResourcesCompat.getColor(resources, R.color.colorPrimary, null)
                fab.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.fab_animation_down, null))
                Handler().postDelayed({
                    (fab.drawable as AnimatedVectorDrawable).start()
                    fab.animate().setDuration(200).translationYBy(340f).setListener(object : AnimatorListenerAdapter() {
                        override fun onAnimationEnd(animation: Animator?) {
                            super.onAnimationEnd(animation)
                            bi.backdrop.visibility = View.INVISIBLE
                            bi.editTextCard.visibility = View.VISIBLE
                        }
                    })
                }, 300)
            }
        }
android
kotlin
animation
floating-action-button
android-bottomappbar
asked on Stack Overflow Jun 28, 2020 by Sett

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0