diff --git a/banner/src/main/java/com/zj/banner/BannerPager.kt b/banner/src/main/java/com/zj/banner/BannerPager.kt index 6d51180..5f1a47a 100644 --- a/banner/src/main/java/com/zj/banner/BannerPager.kt +++ b/banner/src/main/java/com/zj/banner/BannerPager.kt @@ -84,23 +84,20 @@ fun 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) } \ No newline at end of file