Skip to content

Commit

Permalink
Merge pull request #22 from canopas/add-restart-intro-support
Browse files Browse the repository at this point in the history
Add restart intro support
  • Loading branch information
cp-megh-l authored Jan 3, 2024
2 parents 3e0bdf6 + 368d5bc commit 1245bde
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/com/canopas/campose/showcase/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -75,13 +77,16 @@ fun ShowcaseSample() {
mutableStateOf(true)
}

val introShowcaseState = rememberIntroShowcaseState()

IntroShowcase(
showIntroShowCase = showAppIntro,
dismissOnClickOutside = false,
onShowCaseCompleted = {
//App Intro finished!!
showAppIntro = false
},
state = introShowcaseState,
) {
Scaffold(
modifier = Modifier.fillMaxSize(),
Expand All @@ -91,7 +96,7 @@ fun ShowcaseSample() {
backgroundColor = Color.Transparent,
elevation = 0.dp,
navigationIcon = {
BackButton()
BackButton(introShowcaseState)
},
actions = {
IconButton(
Expand Down Expand Up @@ -191,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() {
}

@Composable
fun IntroShowcaseScope.BackButton() {
fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) {
IconButton(
onClick = {},
modifier = Modifier.introShowCaseTarget(
Expand Down Expand Up @@ -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")
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun ShowcaseSample() {
mutableStateOf(true)
}

IntroShowCase(
IntroShowcase(
showIntroShowCase = showAppIntro,
dismissOnClickOutside = false,
onShowCaseCompleted = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Int, IntroShowcaseTargets>()

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
}
}

0 comments on commit 1245bde

Please sign in to comment.