patrick-elmquist / Demo-RecyclerViewEnterAnimation

Demo project for a blog post
https://proandroiddev.com/enter-animation-using-recyclerview-and-layoutanimation-part-1-list-75a874a5d213
302 stars 90 forks source link

Animation executes on older data set #3

Open abhinav272 opened 6 years ago

abhinav272 commented 6 years ago

https://github.com/patrick-iv/Enter-animation-demo/blob/7b35deb075d03c9907502ff29e27e3c72beb6368/app/src/main/java/com/patrickiv/demo/enteranimationdemo/fragment/BaseFragment.java#L95

RecyclerView gets data from API call and when data gets populated it gets Animation as expected, but when the user scrolls to end and pagination logic calls for next page data I call runLayoutAnimation() when next page data is available but Animation gets executed on older data set which is already in recyclerview.

I want the Animation to execute only on the new data set.

idrisbohra commented 6 years ago

Hi @abhinav272 i am also having the same problem. Did you find any solution? Please let us know. Thank you.

abhinav272 commented 6 years ago

@idrisbohra No

idrisbohra commented 6 years ago

Thanks @abhinav272 did you find out any other library based on same animation?

abhinav272 commented 6 years ago

@idrisbohra you can try one thing, there is a way to add animation on recyclerview onCreateViewHolder(), You can specify the enter animation there and see if it's what you expect

abhinav272 commented 6 years ago

@idrisbohra have you found the solution? If not, maybe you can try this

add this to your adapter and make the call from bindViewHolder()

fun setAnimation(viewToAnimate: View, position: Int) {
        if (position > lastPosition) {
            val animation = AnimationUtils.loadAnimation(viewToAnimate.context, android.R.anim.fade_in)
            viewToAnimate.startAnimation(animation)
            lastPosition = position
        }
    }

override fun onViewDetachedFromWindow(holder: CollectionsViewHolder?) {
        super.onViewDetachedFromWindow(holder)
        holder?.rootLayout!!.clearAnimation()
    }

onViewDetachedFromWindow() is called by Android and using here to clear the animation of view which is out of screen when user scolls quickly.