Skip to content

Commit

Permalink
修复重复设置滑动监听导致递归而栈溢出的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
jellybean committed Jun 7, 2017
1 parent 612826f commit f2caab2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ A library for Android , swipe to refresh or load more

#使用说明
- 添加 gralde 依赖
`compile 'com.github.refreshloadlayout:refreshloadlayout:0.0.2' `
如果收到支持库不统一的警告,可修改为 `compile ('com.github.refreshloadlayout:refreshloadlayout:0.0.2'){exclude group: 'com.android.support'}`
`compile 'com.github.refreshloadlayout:refreshloadlayout:0.0.3' `
如果收到支持库不统一的警告,可修改为 `compile ('com.github.refreshloadlayout:refreshloadlayout:0.0.3'){exclude group: 'com.android.support'}`

- 在布局中使用

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=0.0.2
VERSION_NAME=0.0.3
GROUP=com.github.refreshloadlayout
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,11 @@ private void setScrollListener() {
private void setRecyclerViewOnScrollListener(RecyclerView recyclerView) {
if (recyclerView != null) {
if (recyclerScrollListener == null) {
recyclerScrollListener = new RecyclerScrollListener();
recyclerScrollListener = new RecyclerScrollListener(recyclerView);
recyclerView.addOnScrollListener(recyclerScrollListener);
}else if (recyclerScrollListener.getRecyclerView()!=recyclerView){
recyclerView.addOnScrollListener(recyclerScrollListener);
}
recyclerView.addOnScrollListener(recyclerScrollListener);
}
}

Expand All @@ -768,8 +770,10 @@ private void setAbsListViewOnScrollListener(AbsListView absListView) {
if (absListViewScrollListener == null) {
absListViewScrollListener = new AbsListViewScrollListener();
}
absListViewScrollListener.setOriginalListener(onScrollListener);
absListView.setOnScrollListener(absListViewScrollListener);
if (onScrollListener != absListViewScrollListener){
absListViewScrollListener.setOriginalListener(onScrollListener);
absListView.setOnScrollListener(absListViewScrollListener);
}
} catch (Exception e) {
Log.e(TAG, "反射获取AbsListView#OnScrollListener异常", e);
}
Expand Down Expand Up @@ -822,6 +826,12 @@ public interface OnTargetScrollDownCallback {
}

private class RecyclerScrollListener extends RecyclerView.OnScrollListener {
private RecyclerView recyclerView;

private RecyclerScrollListener(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}

/**
* 是否忽略下此次滑动事件,避免在刚结束加载并滑动一个单元的距离后
* {@link #scrollChildToNextItem()}连续触发加载
Expand All @@ -832,6 +842,10 @@ void setSwallowNextScroll(boolean swallowNextScroll) {
this.swallowNextScroll = swallowNextScroll;
}

RecyclerView getRecyclerView() {
return recyclerView;
}

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (swallowNextScroll) {
Expand Down

0 comments on commit f2caab2

Please sign in to comment.