Skip to content

Instantly share code, notes, and snippets.

View charbgr's full-sized avatar
🤘
Implementing common sense

Vasilis Charalampakis charbgr

🤘
Implementing common sense
View GitHub Profile
@charbgr
charbgr / OffsetsWithDirection.kt
Created August 17, 2017 12:54 — forked from ZacSweers/OffsetsWithDirection.kt
Observable stream of AppBarLayout offsets + scroll direction
/*
* Here we want to get the appbar offset changes paired with the direction it's moving and
* using RxBinding's great `offsetChanges` API to make an rx Observable of this. The first
* part buffers two while skipping one at a time and emits "scroll direction" enums. Second
* part is just a simple map to pair the offset with the resolved scroll direction comparing
* to the previous offset. This gives us a nice stream of (offset, direction) emissions.
*
* Note that the filter() is important if you manipulate child views of the ABL. If any child
* view requests layout again, it will trigger an emission from the offset listener with the
* same value as before, potentially causing measure/layout/draw thrashing if your logic