File tree Expand file tree Collapse file tree 6 files changed +59
-3
lines changed
app/src/main/java/com/canopas/campose/showcase
showcase/src/main/java/com/canopas/lib/showcase Expand file tree Collapse file tree 6 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ import com.canopas.campose.showcase.ui.theme.JetTapTargetTheme
4848import com.canopas.campose.showcase.ui.theme.ThemeColor
4949import com.canopas.lib.showcase.IntroShowcase
5050import com.canopas.lib.showcase.IntroShowcaseScope
51+ import com.canopas.lib.showcase.component.IntroShowcaseManager
5152import com.canopas.lib.showcase.component.ShowcaseStyle
5253
5354class MainActivity : ComponentActivity () {
@@ -222,6 +223,14 @@ fun IntroShowcaseScope.BackButton() {
222223 color = Color .White ,
223224 fontSize = 16 .sp
224225 )
226+
227+ Button (
228+ onClick = {
229+ IntroShowcaseManager .introRestartHandler?.invoke()
230+ },
231+ ) {
232+ Text (text = " Restart Intro" )
233+ }
225234 }
226235 }
227236 },
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ fun ShowcaseSample() {
3030 mutableStateOf(true )
3131 }
3232
33- IntroShowCase (
33+ IntroShowcase (
3434 showIntroShowCase = showAppIntro,
3535 dismissOnClickOutside = false ,
3636 onShowCaseCompleted = {
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ package com.canopas.lib.showcase
22
33import androidx.compose.foundation.layout.BoxScope
44import androidx.compose.runtime.Composable
5+ import androidx.compose.runtime.DisposableEffect
56import androidx.compose.runtime.remember
67import androidx.compose.ui.Modifier
8+ import com.canopas.lib.showcase.component.IntroShowcaseManager
79import com.canopas.lib.showcase.component.IntroShowcaseState
810import com.canopas.lib.showcase.component.ShowcasePopup
911import com.canopas.lib.showcase.component.ShowcaseStyle
@@ -22,6 +24,15 @@ fun IntroShowcase(
2224 IntroShowcaseScope (state)
2325 }
2426
27+ DisposableEffect (Unit ) {
28+ IntroShowcaseManager .registerRestoreHandler {
29+ state.currentTargetIndex = 0
30+ }
31+ onDispose {
32+ IntroShowcaseManager .registerRestoreHandler(null )
33+ }
34+ }
35+
2536 scope.content()
2637
2738 if (showIntroShowCase) {
Original file line number Diff line number Diff line change 1+ package com.canopas.lib.showcase.component
2+
3+ import com.canopas.lib.showcase.handler.IntroRestartHandler
4+
5+ /* *
6+ * Manager class for IntroShowcase. Manages the registration and invocation of
7+ * [IntroRestartHandler] callbacks.
8+ */
9+ object IntroShowcaseManager {
10+ /* *
11+ * A nullable [IntroRestartHandler] that holds a callback function to be invoked when restarting
12+ * IntroShowcase. It allows external components to register custom logic to execute when
13+ * restarting the IntroShowcase, providing flexibility for handling restart events.
14+ */
15+ var introRestartHandler: IntroRestartHandler ? = null
16+
17+ /* *
18+ * Register a [IntroRestartHandler] callback to be invoked when restarting the IntroShowcase.
19+ */
20+ @JvmStatic
21+ internal fun registerRestoreHandler (introRestartHandler : IntroRestartHandler ? ) {
22+ this .introRestartHandler = introRestartHandler
23+ }
24+ }
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ package com.canopas.lib.showcase.component
33import androidx.compose.foundation.layout.BoxScope
44import androidx.compose.runtime.Composable
55import androidx.compose.runtime.getValue
6+ import androidx.compose.runtime.mutableIntStateOf
67import androidx.compose.runtime.mutableStateMapOf
7- import androidx.compose.runtime.mutableStateOf
88import androidx.compose.runtime.remember
99import androidx.compose.runtime.setValue
1010import androidx.compose.ui.Modifier
@@ -47,13 +47,17 @@ internal fun Modifier.introShowcaseTarget(
4747 )
4848}
4949
50+ /* *
51+ * State class for managing the state of the IntroShowcase. Tracks the current target index and
52+ * associated targets.
53+ */
5054class IntroShowcaseState internal constructor(
5155 initialIndex : Int ,
5256) {
5357
5458 internal var targets = mutableStateMapOf<Int , IntroShowcaseTargets >()
5559
56- var currentTargetIndex by mutableStateOf (initialIndex)
60+ var currentTargetIndex by mutableIntStateOf (initialIndex)
5761 internal set
5862
5963 val currentTarget: IntroShowcaseTargets ?
Original file line number Diff line number Diff line change 1+ package com.canopas.lib.showcase.handler
2+
3+ /* *
4+ * Interface for handling restart callbacks in IntroShowcase.
5+ */
6+ fun interface IntroRestartHandler {
7+ operator fun invoke ()
8+ }
You can’t perform that action at this time.
0 commit comments