Skip to content

Commit ed31992

Browse files
committed
Revert changes and add reset through state
1 parent ede4ef1 commit ed31992

File tree

5 files changed

+16
-47
lines changed

5 files changed

+16
-47
lines changed

app/src/main/java/com/canopas/campose/showcase/MainActivity.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ import com.canopas.campose.showcase.ui.theme.JetTapTargetTheme
4848
import com.canopas.campose.showcase.ui.theme.ThemeColor
4949
import com.canopas.lib.showcase.IntroShowcase
5050
import com.canopas.lib.showcase.IntroShowcaseScope
51-
import com.canopas.lib.showcase.component.IntroShowcaseManager
51+
import com.canopas.lib.showcase.component.IntroShowcaseState
5252
import com.canopas.lib.showcase.component.ShowcaseStyle
53+
import com.canopas.lib.showcase.component.rememberIntroShowcaseState
5354

5455
class MainActivity : ComponentActivity() {
5556
override fun onCreate(savedInstanceState: Bundle?) {
@@ -76,13 +77,16 @@ fun ShowcaseSample() {
7677
mutableStateOf(true)
7778
}
7879

80+
val introShowcaseState = rememberIntroShowcaseState()
81+
7982
IntroShowcase(
8083
showIntroShowCase = showAppIntro,
8184
dismissOnClickOutside = false,
8285
onShowCaseCompleted = {
8386
//App Intro finished!!
8487
showAppIntro = false
8588
},
89+
state = introShowcaseState,
8690
) {
8791
Scaffold(
8892
modifier = Modifier.fillMaxSize(),
@@ -92,7 +96,7 @@ fun ShowcaseSample() {
9296
backgroundColor = Color.Transparent,
9397
elevation = 0.dp,
9498
navigationIcon = {
95-
BackButton()
99+
BackButton(introShowcaseState)
96100
},
97101
actions = {
98102
IconButton(
@@ -192,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() {
192196
}
193197

194198
@Composable
195-
fun IntroShowcaseScope.BackButton() {
199+
fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) {
196200
IconButton(
197201
onClick = {},
198202
modifier = Modifier.introShowCaseTarget(
@@ -226,7 +230,8 @@ fun IntroShowcaseScope.BackButton() {
226230

227231
Button(
228232
onClick = {
229-
IntroShowcaseManager.introRestartHandler?.invoke()
233+
// Used to restart the intro showcase
234+
introShowcaseState.resetState()
230235
},
231236
) {
232237
Text(text = "Restart Intro")

showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package com.canopas.lib.showcase
22

33
import androidx.compose.foundation.layout.BoxScope
44
import androidx.compose.runtime.Composable
5-
import androidx.compose.runtime.DisposableEffect
65
import androidx.compose.runtime.remember
76
import androidx.compose.ui.Modifier
8-
import com.canopas.lib.showcase.component.IntroShowcaseManager
97
import com.canopas.lib.showcase.component.IntroShowcaseState
108
import com.canopas.lib.showcase.component.ShowcasePopup
119
import com.canopas.lib.showcase.component.ShowcaseStyle
@@ -24,15 +22,6 @@ fun IntroShowcase(
2422
IntroShowcaseScope(state)
2523
}
2624

27-
DisposableEffect(Unit) {
28-
IntroShowcaseManager.registerRestoreHandler {
29-
state.currentTargetIndex = 0
30-
}
31-
onDispose {
32-
IntroShowcaseManager.registerRestoreHandler(null)
33-
}
34-
}
35-
3625
scope.content()
3726

3827
if (showIntroShowCase) {

showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseManager.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ class IntroShowcaseState internal constructor(
6262

6363
val currentTarget: IntroShowcaseTargets?
6464
get() = targets[currentTargetIndex]
65+
66+
/**
67+
* Resets the state to its initial values, effectively restarting the showcase.
68+
*/
69+
fun resetState() {
70+
currentTargetIndex = 0
71+
}
6572
}

showcase/src/main/java/com/canopas/lib/showcase/handler/IntroRestartHandler.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)