gowong / material-sheet-fab

Android library that provides the floating action button to sheet transition from Google's Material Design.
MIT License
1.58k stars 255 forks source link

Problems after applying animation to Fab #28

Closed phyora closed 8 years ago

phyora commented 8 years ago

Hi

I am applying an animation to the Fab to hide/show it when a list is scrolled. I apply the animation as so:

fab.startAnimation(anim)

The Fab animates correctly however when you tap the Fab after it has been animated the Fab does not transition into the material sheet correctly. Instead the Fab button grows in size and is drawn above the material sheet. Tapping it several more times makes it grow even larger until the app crashes with this exception:

OpenGLRenderer: Error: Ambient Vertex Buffer overflow!!! used 480, total 320

Is there a way to reinitialise the Fab after an animation has been applied to it?

Thanks in advance.

gowong commented 8 years ago

Can you include the animation code? You won't need to reset the FAB if you're animating its translationX and translationY values.

Take a look at the sample code for how to animate scaling and translating the FAB. https://github.com/gowong/material-sheet-fab/blob/master/sample/src/main/java/com/gordonwong/materialsheetfab/sample/Fab.java#L98

phyora commented 8 years ago

The animation was a simple translate animation like this: <translate android:duration="300" android:fromYDelta="0" android:toYDelta="100%p" />

I have since implemented the sample code you linked to and it works great.

Thanks for an excellent library and great support.

phyora commented 8 years ago

Oops I spoke to soon! After implementing the sample code and calling animatedFab.show() and animatedFab.hide() a few times I have a similar issue.

The Fab will sometimes appear twice the size after calling show and tapping it will cause an incorrect animation into the sheet. Tapping it again causes this exception: OpenGLRenderer: Error: Ambient Vertex Buffer overflow!!! used 480, total 320

I am using the exact same code listed here: https://github.com/gowong/material-sheet-fab/blob/master/sample/src/main/java/com/gordonwong/materialsheetfab/sample/Fab.java#L98

I'm using a Nexus 6 running Android 6.0.1. Have you experienced this before?

Thanks

phyora commented 8 years ago

I have found the problem.

If you fling the ListView and quickly tap the Fab whilst the list is still scrolling this is when the error occurs. The Fab grows twice the size and is drawn above the sheet. Then when you attempt to hide the sheet you get the 'Ambient Vertex Buffer overflow!!!' exception.

The problem does NOT happen if you haven't called hide() or show() on the fab. It does occur after either of those have been called.

Any ideas what causes this?

phyora commented 8 years ago

A solution I've found is to wrap the call to fab.show() with a condition that checks that it cannot be called more than once whilst the show animation is playing. That seems to have fixed it!

gowong commented 8 years ago

Glad you got it working!

Yes, I imagine issues similar to what you described will happen when multiple animations are repeatedly playing on the FAB. It's up to the app to implement logic to enforce only one playing animation since there's no way for the library to know about outside animations on the FAB.