Skip to content

Commit

Permalink
Revert changes and add reset through state
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-megh-l committed Jan 3, 2024
1 parent ede4ef1 commit ed31992
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 47 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/com/canopas/campose/showcase/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand All @@ -76,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 @@ -92,7 +96,7 @@ fun ShowcaseSample() {
backgroundColor = Color.Transparent,
elevation = 0.dp,
navigationIcon = {
BackButton()
BackButton(introShowcaseState)
},
actions = {
IconButton(
Expand Down Expand Up @@ -192,7 +196,7 @@ fun IntroShowcaseScope.FloatingMailButton() {
}

@Composable
fun IntroShowcaseScope.BackButton() {
fun IntroShowcaseScope.BackButton(introShowcaseState: IntroShowcaseState) {
IconButton(
onClick = {},
modifier = Modifier.introShowCaseTarget(
Expand Down Expand Up @@ -226,7 +230,8 @@ fun IntroShowcaseScope.BackButton() {

Button(
onClick = {
IntroShowcaseManager.introRestartHandler?.invoke()
// Used to restart the intro showcase
introShowcaseState.resetState()
},
) {
Text(text = "Restart Intro")
Expand Down
11 changes: 0 additions & 11 deletions showcase/src/main/java/com/canopas/lib/showcase/IntroShowcase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,15 +22,6 @@ fun IntroShowcase(
IntroShowcaseScope(state)
}

DisposableEffect(Unit) {
IntroShowcaseManager.registerRestoreHandler {
state.currentTargetIndex = 0
}
onDispose {
IntroShowcaseManager.registerRestoreHandler(null)
}
}

scope.content()

if (showIntroShowCase) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

This file was deleted.

0 comments on commit ed31992

Please sign in to comment.