Skip to content

Commit d739498

Browse files
committed
Merge pull request #9 from colymore/scroll-state-changed-delegate
Call delegate ScrollListener on scrollChangeState
2 parents b142de5 + b2bda82 commit d739498

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

library/src/main/java/com/tuenti/buttonmenu/animator/ScrollAnimator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
9494

9595
@Override
9696
public void onScrollStateChanged(AbsListView view, int scrollState) {
97-
//Empty
97+
notifyScrollStateChangedToAdditionalScrollListener(view, scrollState);
98+
9899
}
99100
});
100101
}
@@ -175,6 +176,12 @@ private void notifyScrollToAdditionalScrollListener(AbsListView view, int firstV
175176
}
176177
}
177178

179+
private void notifyScrollStateChangedToAdditionalScrollListener(AbsListView view, int scrollState) {
180+
if (additionalScrollListener != null) {
181+
additionalScrollListener.onScrollStateChanged(view, scrollState);
182+
}
183+
}
184+
178185
/**
179186
* Perform the "translateY" animation using the new scroll position and the old scroll position to show or hide
180187
* the animated view.

library/src/test/java/com/tuenti/buttonmenu/animator/ScrollAnimatorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class ScrollAnimatorTest {
4848
private static final int TOTAL_ITEM_COUNT = 10;
4949
private static final int ANY_FIRST_VISIBLE_ITEM = 2;
5050
private static final int ANY_VISIBLE_ITEM_COUNT = 3;
51+
private static final int ANY_SCROLL_ACTION = 0;
5152
private static final int HIDDEN_Y_POSITION = 0;
5253
private static final int SHOW_Y_POSITION = ANIMATED_VIEW_HEIGHT;
5354

@@ -103,6 +104,17 @@ public void shouldNotifyAdditionalScrollListenerOnScroll() {
103104
verify(mockedScrollListener).onScroll(listView, ANY_FIRST_VISIBLE_ITEM, ANY_VISIBLE_ITEM_COUNT, TOTAL_ITEM_COUNT);
104105
}
105106

107+
@Test
108+
public void shouldNotifyAdditionalScrollListenerOnScrollStateChanged() {
109+
OnScrollListener mockedScrollListener = mock(OnScrollListener.class);
110+
scrollAnimator.setAdditionalScrollListener(mockedScrollListener);
111+
scrollAnimator.configureListView(listView);
112+
113+
doAnyScrollAction();
114+
115+
verify(mockedScrollListener).onScrollStateChanged(listView, ANY_SCROLL_ACTION);
116+
}
117+
106118
@Test
107119
public void shouldReleaseListViewScrollListener() {
108120
scrollAnimator.configureListView(listView);
@@ -152,6 +164,12 @@ private void scrollToAnyPosition(int firstVisibleItem, int visibleItemCount, int
152164
scrollListener.onScroll(listView, firstVisibleItem, visibleItemCount, totalItemCount);
153165
}
154166

167+
private void doAnyScrollAction() {
168+
verify(listView).setOnScrollListener(scrollListenerCaptor.capture());
169+
scrollListener = scrollListenerCaptor.getValue();
170+
scrollListener.onScrollStateChanged(listView, ANY_SCROLL_ACTION);
171+
}
172+
155173
private void setUpListView() {
156174
View topChild = mock(View.class);
157175
when(topChild.getHeight()).thenReturn(ANIMATED_VIEW_HEIGHT);

0 commit comments

Comments
 (0)