Skip to content

Commit

Permalink
Bug Fix #260.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Jun 27, 2022
1 parent 7b00f20 commit c85013d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void initVerticalBanner() {
mViewPagerVertical
.setAutoPlay(true)
.setScrollDuration(500)
.stopLoopWhenDetachedFromWindow(false)
.stopLoopWhenDetachedFromWindow(true)
.setLifecycleRegistry(getLifecycle())
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorSlideMode(IndicatorSlideMode.SCALE)
Expand Down
16 changes: 10 additions & 6 deletions bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ private void initView() {

@Override
protected void onDetachedFromWindow() {
if (mBannerManager != null && mBannerManager.getBannerOptions()
.isStopLoopWhenDetachedFromWindow()) {
if (mBannerManager != null && isStopLoopWhenDetachedFromWindow()) {
stopLoop();
}
super.onDetachedFromWindow();
Expand All @@ -144,8 +143,7 @@ protected void onDetachedFromWindow() {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mBannerManager != null && mBannerManager.getBannerOptions()
.isStopLoopWhenDetachedFromWindow()) {
if (mBannerManager != null && isStopLoopWhenDetachedFromWindow()) {
startLoop();
}
}
Expand Down Expand Up @@ -353,6 +351,10 @@ private void initIndicatorSliderMargin() {
}
}

private boolean isStopLoopWhenDetachedFromWindow() {
return mBannerManager.getBannerOptions().isStopLoopWhenDetachedFromWindow();
}

@Override
protected void dispatchDraw(Canvas canvas) {
float[] roundRectRadiusArray = mBannerManager.getBannerOptions().getRoundRectRadiusArray();
Expand Down Expand Up @@ -505,7 +507,7 @@ public void startLoop() {
*/
public void startLoopNow() {
if (!isLooping && isAutoPlay() && mBannerPagerAdapter != null &&
mBannerPagerAdapter.getListSize() > 1) {
mBannerPagerAdapter.getListSize() > 1) {
mHandler.post(mRunnable);
isLooping = true;
}
Expand Down Expand Up @@ -1051,7 +1053,9 @@ public void onPause() {

@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onResume() {
startLoop();
if (isAttachedToWindow() || !isStopLoopWhenDetachedFromWindow()) {
startLoop();
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
Expand Down

0 comments on commit c85013d

Please sign in to comment.