ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

Fix NPE in scrollVerticallyBy when top/bottom-most view not found #74

Closed jcyuyi closed 5 years ago

jcyuyi commented 6 years ago

Fixed NPE in scrollVerticallyBy.

This NPE might happen after dataset change when use dynamic item type with inner RecyclerView. scrollVerticallyBy might run many times during the layout. In middle state of them, there might be only 1 item with type TYPE_HEADER that exist in child views, and thus getTopmostChildView/getBottommostChildView will return Null. And then the getDecoratedTop/getDecoratedBottom will trigger the NPE.

Fixed by: simply add Null check and return 0. In the later layout pass, child view will be added and scrollVerticallyBy will work normally.

ShamylZakariya commented 6 years ago

I will check this out and merge this weekend. Sorry for delay, but job & life beckon. Thanks for the PR!