Skip to content

Commit

Permalink
fix(android): implement old scrolling event behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and sgtcoolguy committed Jan 19, 2021
1 parent 29880c7 commit 393072c
Showing 1 changed file with 20 additions and 19 deletions.
Expand Up @@ -53,6 +53,8 @@ public class TiListView extends TiSwipeRefreshLayout implements OnSearchChangeLi
private final SelectionTracker tracker;

private boolean isFiltered = false;
private boolean isScrolling = false;
private int lastScrollDeltaY;

public TiListView(ListViewProxy proxy)
{
Expand All @@ -76,6 +78,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
super.onScrollStateChanged(recyclerView, newState);

if (newState == RecyclerView.SCROLL_STATE_IDLE) {
isScrolling = false;
proxy.fireSyncEvent(TiC.EVENT_SCROLLEND, generateScrollPayload());
}
}
Expand All @@ -85,28 +88,26 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);

proxy.fireSyncEvent(TiC.EVENT_SCROLLSTART, generateScrollPayload());
}
});
this.recyclerView.setOnFlingListener(new RecyclerView.OnFlingListener()
{
@Override
public boolean onFling(int velocityX, int velocityY)
{
final KrollDict payload = new KrollDict();

// Determine scroll direction.
if (velocityY > 0) {
payload.put(TiC.PROPERTY_DIRECTION, "down");
} else if (velocityY < 0) {
payload.put(TiC.PROPERTY_DIRECTION, "up");
if (!isScrolling) {
isScrolling = true;
proxy.fireSyncEvent(TiC.EVENT_SCROLLSTART, generateScrollPayload());
}

// Set scroll velocity.
payload.put(TiC.EVENT_PROPERTY_VELOCITY, velocityY);
// Only fire `scrolling` event upon direction change.
if (lastScrollDeltaY >= 0 && dy <= 0 || lastScrollDeltaY <= 0 && dy >= 0) {
final KrollDict payload = generateScrollPayload();

// Determine scroll direction.
if (dy > 0) {
payload.put(TiC.PROPERTY_DIRECTION, "up");
} else if (dy < 0) {
payload.put(TiC.PROPERTY_DIRECTION, "down");
}
payload.put(TiC.EVENT_PROPERTY_VELOCITY, 0);
proxy.fireSyncEvent(TiC.EVENT_SCROLLING, payload);
}

proxy.fireSyncEvent(TiC.EVENT_SCROLLING, payload);
return false;
lastScrollDeltaY = dy;
}
});

Expand Down

0 comments on commit 393072c

Please sign in to comment.