Skip to content

Commit

Permalink
stopLoopWhenDetachedFromWindow supported for issue #207
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Jun 17, 2021
1 parent ea2a87f commit 6703c4a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private void initVerticalBanner() {
mViewPagerVertical
.setAutoPlay(true)
.setScrollDuration(500)
.stopLoopWhenDetachedFromWindow(false)
.setLifecycleRegistry(getLifecycle())
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSlideMode(IndicatorSlideMode.SCALE)
Expand Down
21 changes: 19 additions & 2 deletions bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ private void initView() {

@Override
protected void onDetachedFromWindow() {
stopLoop();
if (mBannerManager != null && mBannerManager.getBannerOptions()
.isStopLoopWhenDetachedFromWindow()) {
stopLoop();
}
super.onDetachedFromWindow();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
startLoop();
if (mBannerManager != null && mBannerManager.getBannerOptions()
.isStopLoopWhenDetachedFromWindow()) {
startLoop();
}
}

@Override
Expand Down Expand Up @@ -1087,6 +1093,17 @@ public BannerViewPager<T> setRTLMode(boolean rtlMode) {
return this;
}

/**
* @param stopLoopWhenDetachedFromWindow 当BVP滑动出屏幕的时候是否要停止轮播,
*
* true:滑动出屏幕停止自动轮播,false:滑动出屏幕继续自动轮播。默认值为true
*/
public BannerViewPager<T> stopLoopWhenDetachedFromWindow(boolean stopLoopWhenDetachedFromWindow) {
mBannerManager.getBannerOptions()
.setStopLoopWhenDetachedFromWindow(stopLoopWhenDetachedFromWindow);
return this;
}

/**
* @deprecated Use {@link BannerViewPager#disallowParentInterceptDownEvent(boolean)} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public BannerOptions() {

private boolean disallowParentInterceptDownEvent;

private boolean stopLoopWhenDetachedFromWindow = true;

private final IndicatorOptions mIndicatorOptions;

public int getInterval() {
Expand Down Expand Up @@ -296,6 +298,14 @@ public void setRtl(boolean rtl) {
rtl ? IndicatorOrientation.INDICATOR_RTL : IndicatorOrientation.INDICATOR_HORIZONTAL);
}

public boolean isStopLoopWhenDetachedFromWindow() {
return stopLoopWhenDetachedFromWindow;
}

public void setStopLoopWhenDetachedFromWindow(boolean stopLoopWhenDetachedFromWindow) {
this.stopLoopWhenDetachedFromWindow = stopLoopWhenDetachedFromWindow;
}

public static class IndicatorMargin {

private final int left, right, top, bottom;
Expand Down

0 comments on commit 6703c4a

Please sign in to comment.