Skip to content

Commit

Permalink
优化多个 Banner 同时使用问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujiang2 committed Feb 21, 2022
1 parent 35a00ea commit c3c3dd4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions banner/src/main/java/com/zj/banner/BannerPager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,20 @@ fun <T : BaseBannerBean> BannerPager(
}
}

var mTimer: Timer? = null
var mTimerTask: TimerTask? = null



@ExperimentalPagerApi
@Composable
fun StartBanner(pagerState: PagerState, intervalTime: Long) {
val coroutineScope = rememberCoroutineScope()
mTimer?.cancel()
mTimerTask?.cancel()
mTimer = Timer()
mTimerTask = object : TimerTask() {
val timer = Timer()
val timerTask = object : TimerTask() {
override fun run() {
coroutineScope.launch {
pagerState.animateScrollToPage((pagerState.currentPage + 1) % pagerState.pageCount)
}
}
}
mTimer?.schedule(mTimerTask, intervalTime, intervalTime)
timer.schedule(timerTask, intervalTime, intervalTime)
}

0 comments on commit c3c3dd4

Please sign in to comment.