Skip to content

Commit 3a1cb48

Browse files
author
zhujiang2
committed
优化刷新效率
1 parent 429ed77 commit 3a1cb48

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

banner/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ afterEvaluate {
1717
// You can then customize attributes of the publication as shown below.
1818
groupId = 'com.zj.banner'
1919
artifactId = 'banner'
20-
version = '2.6.0'
20+
version = '2.6.1'
2121
}
2222
// // Creates a Maven publication called “debug”.
2323
// debug(MavenPublication) {

banner/src/main/java/com/zj/banner/BannerPager.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.pager.HorizontalPager
1212
import androidx.compose.foundation.pager.PagerState
1313
import androidx.compose.foundation.pager.rememberPagerState
1414
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.LaunchedEffect
1516
import androidx.compose.runtime.rememberCoroutineScope
1617
import androidx.compose.ui.Alignment
1718
import androidx.compose.ui.Modifier
@@ -103,20 +104,6 @@ fun <T : BaseBannerBean> BannerPager(
103104
stop = 1f,
104105
fraction = 1f - pageOffset.coerceIn(0f, 1f)
105106
)
106-
107-
var position: Int = pagerState.currentPage
108-
Log.d(TAG, "finish update before, position=$position")
109-
if (position == 0) {
110-
position = size
111-
coroutineScope.launch {
112-
pagerState.scrollToPage(position)
113-
}
114-
} else if (position == FAKE_BANNER_SIZE - 1) {
115-
position = size - 1
116-
coroutineScope.launch {
117-
pagerState.scrollToPage(position)
118-
}
119-
}
120107
}
121108
.fillMaxSize()
122109
.padding(config.bannerImagePadding),
@@ -129,6 +116,22 @@ fun <T : BaseBannerBean> BannerPager(
129116
}
130117
)
131118

119+
LaunchedEffect(key1 = pagerState){
120+
var position: Int = pagerState.currentPage
121+
Log.d(TAG, "finish update before, position=$position")
122+
if (position == 0) {
123+
position = size
124+
coroutineScope.launch {
125+
pagerState.scrollToPage(position)
126+
}
127+
} else if (position == FAKE_BANNER_SIZE - 1) {
128+
position = size - 1
129+
coroutineScope.launch {
130+
pagerState.scrollToPage(position)
131+
}
132+
}
133+
}
134+
132135
if (indicatorIsVertical) {
133136
VerticalPagerIndicator(
134137
pagerState = pagerState,

0 commit comments

Comments
 (0)