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 154043e..661471f 100644 --- a/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt +++ b/app/src/main/java/com/canopas/campose/showcase/MainActivity.kt @@ -48,7 +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.IntroShowcaseState import com.canopas.lib.showcase.component.ShowcaseStyle +import com.canopas.lib.showcase.component.rememberIntroShowcaseState class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -75,6 +77,8 @@ fun ShowcaseSample() { mutableStateOf(true) } + val introShowcaseState = rememberIntroShowcaseState() + IntroShowcase( showIntroShowCase = showAppIntro, dismissOnClickOutside = false, @@ -82,6 +86,7 @@ fun ShowcaseSample() { //App Intro finished!! showAppIntro = false }, + state = introShowcaseState, ) { Scaffold( modifier = Modifier.fillMaxSize(), @@ -91,7 +96,7 @@ fun ShowcaseSample() { backgroundColor = Color.Transparent, elevation = 0.dp, navigationIcon = { - BackButton() + BackButton(introShowcaseState) }, actions = { IconButton( @@ -191,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() { } @Composable -fun IntroShowcaseScope.BackButton() { +fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) { IconButton( onClick = {}, modifier = Modifier.introShowCaseTarget( @@ -222,6 +227,15 @@ fun IntroShowcaseScope.BackButton() { color = Color.White, fontSize = 16.sp ) + + Button( + onClick = { + // Used to restart the intro showcase + introShowcaseState.reset() + }, + ) { + Text(text = "Restart Intro") + } } } }, diff --git a/docs/index.md b/docs/index.md index 149f5c5..1898c5d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -30,7 +30,7 @@ fun ShowcaseSample() { mutableStateOf(true) } - IntroShowCase( + IntroShowcase( showIntroShowCase = showAppIntro, dismissOnClickOutside = false, onShowCaseCompleted = { diff --git a/showcase/src/main/java/com/canopas/lib/showcase/component/ShowCasestate.kt b/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt similarity index 81% rename from showcase/src/main/java/com/canopas/lib/showcase/component/ShowCasestate.kt rename to showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt index 2708112..7237b1a 100644 --- a/showcase/src/main/java/com/canopas/lib/showcase/component/ShowCasestate.kt +++ b/showcase/src/main/java/com/canopas/lib/showcase/component/IntroShowcaseState.kt @@ -3,8 +3,8 @@ package com.canopas.lib.showcase.component import androidx.compose.foundation.layout.BoxScope import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateMapOf -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier @@ -47,15 +47,26 @@ internal fun Modifier.introShowcaseTarget( ) } +/** + * State class for managing the state of the IntroShowcase. Tracks the current target index and + * associated targets. + */ class IntroShowcaseState internal constructor( initialIndex: Int, ) { internal var targets = mutableStateMapOf() - var currentTargetIndex by mutableStateOf(initialIndex) + var currentTargetIndex by mutableIntStateOf(initialIndex) internal set val currentTarget: IntroShowcaseTargets? get() = targets[currentTargetIndex] + + /** + * Resets the state to its initial values, effectively restarting the showcase. + */ + fun reset() { + currentTargetIndex = 0 + } }