Skip to content

Commit 1245bde

Browse files
authored
Merge pull request #22 from canopas/add-restart-intro-support
Add restart intro support
2 parents 3e0bdf6 + 368d5bc commit 1245bde

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +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.IntroShowcaseState
5152
import com.canopas.lib.showcase.component.ShowcaseStyle
53+
import com.canopas.lib.showcase.component.rememberIntroShowcaseState
5254

5355
class MainActivity : ComponentActivity() {
5456
override fun onCreate(savedInstanceState: Bundle?) {
@@ -75,13 +77,16 @@ fun ShowcaseSample() {
7577
mutableStateOf(true)
7678
}
7779

80+
val introShowcaseState = rememberIntroShowcaseState()
81+
7882
IntroShowcase(
7983
showIntroShowCase = showAppIntro,
8084
dismissOnClickOutside = false,
8185
onShowCaseCompleted = {
8286
//App Intro finished!!
8387
showAppIntro = false
8488
},
89+
state = introShowcaseState,
8590
) {
8691
Scaffold(
8792
modifier = Modifier.fillMaxSize(),
@@ -91,7 +96,7 @@ fun ShowcaseSample() {
9196
backgroundColor = Color.Transparent,
9297
elevation = 0.dp,
9398
navigationIcon = {
94-
BackButton()
99+
BackButton(introShowcaseState)
95100
},
96101
actions = {
97102
IconButton(
@@ -191,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() {
191196
}
192197

193198
@Composable
194-
fun IntroShowcaseScope.BackButton() {
199+
fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) {
195200
IconButton(
196201
onClick = {},
197202
modifier = Modifier.introShowCaseTarget(
@@ -222,6 +227,15 @@ fun IntroShowcaseScope.BackButton() {
222227
color = Color.White,
223228
fontSize = 16.sp
224229
)
230+
231+
Button(
232+
onClick = {
233+
// Used to restart the intro showcase
234+
introShowcaseState.reset()
235+
},
236+
) {
237+
Text(text = "Restart Intro")
238+
}
225239
}
226240
}
227241
},

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 = {

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.canopas.lib.showcase.component
33
import androidx.compose.foundation.layout.BoxScope
44
import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.getValue
6+
import androidx.compose.runtime.mutableIntStateOf
67
import androidx.compose.runtime.mutableStateMapOf
7-
import androidx.compose.runtime.mutableStateOf
88
import androidx.compose.runtime.remember
99
import androidx.compose.runtime.setValue
1010
import androidx.compose.ui.Modifier
@@ -47,15 +47,26 @@ 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+
*/
5054
class 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?
6064
get() = targets[currentTargetIndex]
65+
66+
/**
67+
* Resets the state to its initial values, effectively restarting the showcase.
68+
*/
69+
fun reset() {
70+
currentTargetIndex = 0
71+
}
6172
}

0 commit comments

Comments
 (0)