trafi / anchor-bottom-sheet-behavior

BottomSheet behavior with collapsed, expanded and anchor states
Apache License 2.0
172 stars 25 forks source link

Send also the old state to the onStateChanged() callback #11

Closed riclage closed 6 years ago

riclage commented 6 years ago

Problem

Listeners of the onStateChanged() callback cannot know the previous state the behavior was in. Knowing the old state is useful to perform one time operations.

For example, while the new state isSTATE_DRAGGING the onStateChanged() callback will be called ~several times~ and there is no way of knowing where it came from before without caching the value externally. But we might be interested in performing an action only when the state is changing from STATE_COLLAPSED to STATE_DRAGGING.

Solution

We add the param oldState to the callback.

riclage commented 6 years ago

explicitly checks whether mState == state.

True. I missed that. Still, the problem applies. I updated the PR description.

Also, the same could be achieved by caching the latest value of newState externally, e.g.

Sure. That's how I'm currently doing. Just felt like it belonged in the lib instead.

riclage commented 6 years ago

@justasm Could you merge this?