Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在onresume时回调的生命周期没有判定,造成暂停的轮播图没法恢复滚动 #329

Open
MoYuFly opened this issue Jan 15, 2024 · 0 comments

Comments

@MoYuFly
Copy link

MoYuFly commented Jan 15, 2024

在onresume时,回调生命周期:Lifecycle.State.STARTED,所以下面的判定会造成轮播图无法恢复滚动,这个问题出现的时机是当轮播图已经加载了,切换到别的页面时暂停这个轮播图,再回来这个页面无法恢复滚动。这个轮播图是用在recycleview列表的,第二段代码是轮播图的实现代码。
现在是暂停后,需要我自己在onresume时调用startLoopNow方法才能恢复播放,因为这个方法没有进行判定生命周期。
/**

  • Start loop
    */
    public void startLoop() {
    if (!isLooping
    && isAutoPlay()
    && mBannerPagerAdapter != null
    && mBannerPagerAdapter.getListSize() > 1
    && isAttachedToWindow() && (lifecycleRegistry == null
    || lifecycleRegistry.getCurrentState() == Lifecycle.State.RESUMED
    || lifecycleRegistry.getCurrentState() == Lifecycle.State.CREATED)) {
    mHandler.postDelayed(mRunnable, getInterval());
    isLooping = true;
    }}

第二段代码
holder.bannerView
.registerLifecycleObserver(lifecycle)
.setIndicatorHeight(AutoSizeUtils.pt2px(context, 4f))
.setCanLoop(!isStopLoops)
.setIndicatorSliderWidth(tipWidth)
.setIndicatorStyle(IndicatorStyle.ROUND_RECT)
.setIndicatorMargin(0, 0, 0, AutoSizeUtils.pt2px(context, 12f))
.stopLoopWhenDetachedFromWindow(false)
.setIndicatorSliderColor(Color.parseColor("#80FFFFFF"), Color.parseColor("#FFFFFF"))
.setAdapter(MainItemBannerTestAdapter(context)).create(lists[position].banner)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant