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

Commit

Permalink
Add can scroll listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAfc committed Mar 12, 2019
1 parent 0c03bbc commit 6c5232c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.alibaba.android.vlayout.RecyclablePagerAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams;
import com.alibaba.android.vlayout.extend.LayoutManagerCanScrollListener;
import com.alibaba.android.vlayout.extend.PerformanceMonitor;
import com.alibaba.android.vlayout.extend.ViewLifeCycleListener;
import com.alibaba.android.vlayout.layout.ColumnLayoutHelper;
Expand Down Expand Up @@ -197,6 +198,20 @@ public void onDisappeared(View view) {
}
});

layoutManager.setLayoutManagerCanScrollListener(new LayoutManagerCanScrollListener() {
@Override
public boolean canScrollVertically() {
Log.i("vlayout", "canScrollVertically: ");
return true;
}

@Override
public boolean canScrollHorizontally() {
Log.i("vlayout", "canScrollHorizontally: ");
return true;
}
});

final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);

recyclerView.setAdapter(delegateAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.view.ViewGroup;
import android.view.ViewParent;

import com.alibaba.android.vlayout.extend.LayoutManagerCanScrollListener;
import com.alibaba.android.vlayout.extend.PerformanceMonitor;
import com.alibaba.android.vlayout.extend.ViewLifeCycleHelper;
import com.alibaba.android.vlayout.extend.ViewLifeCycleListener;
Expand Down Expand Up @@ -100,6 +101,8 @@ public static void enableDebugging(boolean isDebug) {

private boolean mCanScrollVertically;

private LayoutManagerCanScrollListener layoutManagerCanScrollListener;

private boolean mEnableMarginOverlapping = false;

private int mMaxMeasureSize = -1;
Expand Down Expand Up @@ -169,6 +172,10 @@ public void setCanScrollHorizontally(boolean canScrollHorizontally) {
this.mCanScrollHorizontally = canScrollHorizontally;
}

public void setLayoutManagerCanScrollListener(LayoutManagerCanScrollListener layoutManagerCanScrollListener) {
this.layoutManagerCanScrollListener = layoutManagerCanScrollListener;
}

public void setNestedScrolling(boolean nestedScrolling) {
setNestedScrolling(nestedScrolling, -1);
}
Expand Down Expand Up @@ -1327,12 +1334,20 @@ public int getChildMeasureSpec(int parentSize, int size, boolean canScroll) {

@Override
public boolean canScrollHorizontally() {
return mCanScrollHorizontally && !mNoScrolling;
boolean ret = true;
if (layoutManagerCanScrollListener != null) {
ret = ret && layoutManagerCanScrollListener.canScrollHorizontally();
}
return mCanScrollHorizontally && !mNoScrolling && ret;
}

@Override
public boolean canScrollVertically() {
return mCanScrollVertically && !mNoScrolling;
boolean ret = true;
if (layoutManagerCanScrollListener != null) {
ret = ret && layoutManagerCanScrollListener.canScrollVertically();
}
return mCanScrollVertically && !mNoScrolling && ret;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.alibaba.android.vlayout.extend;

public interface LayoutManagerCanScrollListener {
boolean canScrollVertically();

boolean canScrollHorizontally();
}

0 comments on commit 6c5232c

Please sign in to comment.