@@ -28,7 +28,10 @@ import androidx.compose.material3.OutlinedButton
28
28
import androidx.compose.material3.Scaffold
29
29
import androidx.compose.runtime.Composable
30
30
import androidx.compose.runtime.getValue
31
+ import androidx.compose.runtime.mutableStateOf
32
+ import androidx.compose.runtime.remember
31
33
import androidx.compose.runtime.rememberCoroutineScope
34
+ import androidx.compose.runtime.setValue
32
35
import androidx.compose.ui.Alignment
33
36
import androidx.compose.ui.Modifier
34
37
import androidx.compose.ui.draw.alpha
@@ -41,6 +44,7 @@ import com.shifthackz.aisdv1.presentation.screen.onboarding.page.FormPageContent
41
44
import com.shifthackz.aisdv1.presentation.screen.onboarding.page.LocalDiffusionPageContent
42
45
import com.shifthackz.aisdv1.presentation.screen.onboarding.page.LookAndFeelPageContent
43
46
import com.shifthackz.aisdv1.presentation.screen.onboarding.page.ProviderPageContent
47
+ import kotlinx.coroutines.Job
44
48
import kotlinx.coroutines.launch
45
49
46
50
@Composable
@@ -69,14 +73,23 @@ private fun OnBoardingScreenContent(
69
73
initialPage = OnBoardingPage .entries.first().ordinal,
70
74
pageCount = { OnBoardingPage .entries.size },
71
75
)
72
- BackHandler (pagerState.currentPage > 0 ) {
73
- scope.launch {
76
+
77
+ var scrollAnimationJob: Job ? by remember { mutableStateOf(null ) }
78
+
79
+ fun scrollToPage (page : Int ) {
80
+ if (scrollAnimationJob != null ) return
81
+ scrollAnimationJob = scope.launch {
74
82
pagerState.animateScrollToPage(
75
- page = pagerState.currentPage - 1 ,
83
+ page = page ,
76
84
animationSpec = onBoardingPageAnimation,
77
85
)
78
- }
86
+ }. apply { invokeOnCompletion { scrollAnimationJob = null } }
79
87
}
88
+
89
+ BackHandler (pagerState.currentPage > 0 ) {
90
+ scrollToPage(pagerState.currentPage - 1 )
91
+ }
92
+
80
93
Scaffold (
81
94
modifier = Modifier .fillMaxSize(),
82
95
bottomBar = {
@@ -113,12 +126,7 @@ private fun OnBoardingScreenContent(
113
126
contentPadding = PaddingValues (0 .dp),
114
127
onClick = {
115
128
if (pagerState.currentPage > 0 ) {
116
- scope.launch {
117
- pagerState.animateScrollToPage(
118
- page = pagerState.currentPage - 1 ,
119
- animationSpec = onBoardingPageAnimation,
120
- )
121
- }
129
+ scrollToPage(pagerState.currentPage - 1 )
122
130
} else if (pagerState.currentPage == 0 && launchSource == LaunchSource .SETTINGS ) {
123
131
processIntent(OnBoardingIntent .Navigate )
124
132
}
@@ -127,7 +135,7 @@ private fun OnBoardingScreenContent(
127
135
Icon (
128
136
modifier = Modifier .rotate(180f ),
129
137
imageVector = Icons .Default .DoubleArrow ,
130
- contentDescription = " Next " ,
138
+ contentDescription = " Back " ,
131
139
)
132
140
}
133
141
Spacer (modifier = Modifier .weight(1f ))
@@ -156,12 +164,7 @@ private fun OnBoardingScreenContent(
156
164
if (pagerState.currentPage == OnBoardingPage .entries.size - 1 ) {
157
165
processIntent(OnBoardingIntent .Navigate )
158
166
} else {
159
- scope.launch {
160
- pagerState.animateScrollToPage(
161
- page = pagerState.currentPage + 1 ,
162
- animationSpec = onBoardingPageAnimation,
163
- )
164
- }
167
+ scrollToPage(pagerState.currentPage + 1 )
165
168
}
166
169
},
167
170
) {
0 commit comments