Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] bugfix of the scrollstart and scrollend event mismatching (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zshshr authored and YorkShen committed Jul 10, 2019
1 parent 7e274f2 commit c928c5c
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public class ScrollStartEndHelper implements Runnable{
private Handler handler;
private WXComponent component;
private boolean hasStart;
private boolean canStart = false;

private long minInterval;
private int oldState = OnWXScrollListener.IDLE;

private int x;
private int y;
Expand All @@ -64,14 +67,16 @@ public void onScrolled(int x, int y){
|| component.getEvents().contains(Constants.Event.SCROLL_END))){
this.x = x;
this.y = y;
if(!hasStart){
if(!hasStart && canStart){
if(component.getEvents().contains(Constants.Event.SCROLL_START)){
Map<String, Object> event = getScrollEvent(x,y);
if (null !=event && !event.isEmpty()){
component.fireEvent(Constants.Event.SCROLL_START,event);

}
}
hasStart = true;
canStart = false;
}
handler.removeCallbacks(this);
handler.postDelayed(this, minInterval);
Expand All @@ -87,8 +92,13 @@ public void run() {
if(!hasScrollEnd){
return;
}
if(canStart){
component.fireEvent(Constants.Event.SCROLL_START, getScrollEvent(this.x, this.y));
canStart = false;
}
if(component.getEvents().contains(Constants.Event.SCROLL_END)){
component.fireEvent(Constants.Event.SCROLL_END, getScrollEvent(this.x, this.y));

}
hasStart = false;
hasScrollEnd = false;
Expand All @@ -115,11 +125,18 @@ private Map<String, Object> getScrollEvent(int offsetX, int offsetY){
}

public void onScrollStateChanged(int newState){

if(oldState == OnWXScrollListener.IDLE){
canStart = true;
}

if(newState == OnWXScrollListener.IDLE){
hasScrollEnd = true;
handler.removeCallbacks(this);
handler.postDelayed(this, minInterval);
}

oldState = newState;
}


Expand Down

0 comments on commit c928c5c

Please sign in to comment.