@@ -12,6 +12,7 @@ import androidx.compose.foundation.pager.HorizontalPager
12
12
import androidx.compose.foundation.pager.PagerState
13
13
import androidx.compose.foundation.pager.rememberPagerState
14
14
import androidx.compose.runtime.Composable
15
+ import androidx.compose.runtime.LaunchedEffect
15
16
import androidx.compose.runtime.rememberCoroutineScope
16
17
import androidx.compose.ui.Alignment
17
18
import androidx.compose.ui.Modifier
@@ -103,20 +104,6 @@ fun <T : BaseBannerBean> BannerPager(
103
104
stop = 1f ,
104
105
fraction = 1f - pageOffset.coerceIn(0f , 1f )
105
106
)
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
- }
120
107
}
121
108
.fillMaxSize()
122
109
.padding(config.bannerImagePadding),
@@ -129,6 +116,22 @@ fun <T : BaseBannerBean> BannerPager(
129
116
}
130
117
)
131
118
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
+
132
135
if (indicatorIsVertical) {
133
136
VerticalPagerIndicator (
134
137
pagerState = pagerState,
0 commit comments