diff --git a/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt b/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt index 2fe1bf0..b6b378f 100644 --- a/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt +++ b/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt @@ -48,8 +48,9 @@ import com.canopas.campose.showcase.ui.theme.JetTapTargetTheme import com.canopas.campose.showcase.ui.theme.ThemeColor import com.canopas.lib.showcase.IntroShowcase import com.canopas.lib.showcase.IntroShowcaseScope -import com.canopas.lib.showcase.component.IntroShowcaseManager +import com.canopas.lib.showcase.component.IntroShowcaseState import com.canopas.lib.showcase.component.ShowcaseStyle +import com.canopas.lib.showcase.component.rememberIntroShowcaseState class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -76,6 +77,8 @@ fun ShowcaseSample() { mutableStateOf(true) } + val introShowcaseState = rememberIntroShowcaseState() + IntroShowcase( showIntroShowCase = showAppIntro, dismissOnClickOutside = false, @@ -83,6 +86,7 @@ fun ShowcaseSample() { //App Intro finished!! showAppIntro = false }, + state = introShowcaseState, ) { Scaffold( modifier = Modifier.fillMaxSize(), @@ -92,7 +96,7 @@ fun ShowcaseSample() { backgroundColor = Color.Transparent, elevation = 0.dp, navigationIcon = { - BackButton() + BackButton(introShowcaseState) }, actions = { IconButton( @@ -192,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() { } @Composable -fun IntroShowcaseScope.BackButton() { +fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) { IconButton( onClick = {}, modifier = Modifier.introShowCaseTarget( @@ -226,7 +230,8 @@ fun IntroShowcaseScope.BackButton() { Button( onClick = { - IntroShowcaseManager.introRestartHandler?.invoke() + // Used to restart the intro showcase + introShowcaseState.resetState() }, ) { Text(text = "Restart Intro") diff --git a/showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt b/showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt index 4f65d42..c8199c0 100644 --- a/showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt +++ b/showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt @@ -2,10 +2,8 @@ package com.canopas.lib.showcase import androidx.compose.foundation.layout.BoxScope import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import com.canopas.lib.showcase.component.IntroShowcaseManager import com.canopas.lib.showcase.component.IntroShowcaseState import com.canopas.lib.showcase.component.ShowcasePopup import com.canopas.lib.showcase.component.ShowcaseStyle @@ -24,15 +22,6 @@ fun IntroShowcase( IntroShowcaseScope(state) } - DisposableEffect(Unit) { - IntroShowcaseManager.registerRestoreHandler { - state.currentTargetIndex = 0 - } - onDispose { - IntroShowcaseManager.registerRestoreHandler(null) - } - } - scope.content() if (showIntroShowCase) { diff --git a/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseManager.kt b/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseManager.kt deleted file mode 100644 index 91f2c72..0000000 --- a/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseManager.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.canopas.lib.showcase.component - -import com.canopas.lib.showcase.handler.IntroRestartHandler - -/** - * Manager class for IntroShowcase. Manages the registration and invocation of - * [IntroRestartHandler] callbacks. - */ -object IntroShowcaseManager { - /** - * A nullable [IntroRestartHandler] that holds a callback function to be invoked when restarting - * IntroShowcase. It allows external components to register custom logic to execute when - * restarting the IntroShowcase, providing flexibility for handling restart events. - */ - var introRestartHandler: IntroRestartHandler? = null - - /** - * Register a [IntroRestartHandler] callback to be invoked when restarting the IntroShowcase. - */ - @JvmStatic - internal fun registerRestoreHandler(introRestartHandler: IntroRestartHandler?) { - this.introRestartHandler = introRestartHandler - } -} \ No newline at end of file diff --git a/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt b/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt index 6d158e9..2f7b494 100644 --- a/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt +++ b/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt @@ -62,4 +62,11 @@ class IntroShowcaseState internal constructor( val currentTarget: IntroShowcaseTargets? get() = targets[currentTargetIndex] + + /** + * Resets the state to its initial values, effectively restarting the showcase. + */ + fun resetState() { + currentTargetIndex = 0 + } } diff --git a/showcase/src/main/java/com/canopas/lib/showcase/handler/IntroRestartHandler.kt b/showcase/src/main/java/com/canopas/lib/showcase/handler/IntroRestartHandler.kt deleted file mode 100644 index 5142905..0000000 --- a/showcase/src/main/java/com/canopas/lib/showcase/handler/IntroRestartHandler.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.canopas.lib.showcase.handler - -/** - * Interface for handling restart callbacks in IntroShowcase. - */ -fun interface IntroRestartHandler { - operator fun invoke() -} \ No newline at end of file