From c3c3dd4f05fcdb4e19672333651bb8a3c6bd19ee Mon Sep 17 00:00:00 2001 From: zhujiang2 Date: Mon, 21 Feb 2022 21:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=9A=E4=B8=AA=20Banner?= =?UTF-8?q?=20=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- banner/src/main/java/com/zj/banner/BannerPager.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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