Intro Showcase View

repository·master·Indexed 20 days ago

https://github.com/canopas/compose-intro-showcase

An Android library for Jetpack Compose that provides an introductory showcase and onboarding UI to highlight specific app features. It includes the IntroShowcase composable, the .introShowCaseTarget() modifier for designating sequence steps, and IntroShowcaseState for managing the walkthrough flow.

Tokens
2K
Snippets
8
Records
9
Agent score
70%

What's inside compose-intro-showcase

  1. Overview of Intro Showcase View

    master
    Intro Showcase View is an Android library designed to highlight different features of an app built using Jetpack Compose. It is inspired by TapTargetView (which is intended for legacy views) but specifically tailored for the Jetpack Compose ecosystem.
  2. Implement IntroShowcase in Jetpack Compose

    master

    To create an onboarding or feature highlight flow, wrap your UI components within the IntroShowcase composable.

    IntroShowcase manages the visibility of the showcase and provides a callback when the sequence is finished. Use the showIntroShowCase boolean to control when the intro starts and onShowCaseCompleted to handle the state change once the user has finished interacting with the highlights.

    @Composable
    fun ShowcaseSample() {
        var showAppIntro by remember {
            mutableStateOf(true)
        }
        
        IntroShowcase(
            showIntroShowCase = showAppIntro,
            dismissOnClickOutside = false,
            onShowCaseCompleted = {
                //App Intro finished!!
                showAppIntro = false
            },
        ) {
            // Target components go here
        }
    }
  3. Highlight features using the introShowCaseTarget modifier

    master

    Use the .introShowCaseTarget() modifier on any Composable to designate it as a step in the showcase sequence.

    Key parameters for the modifier:

    • index: The order of this step in the showcase sequence (starting from 0).
    • style: A ShowcaseStyle object (e.g., ShowcaseStyle.Default) used to customize the appearance of the highlight circle and background. You can use .copy() to override properties like backgroundColor, backgroundAlpha, and targetCircleColor.
    • content: A composable lambda that defines the instructional text, icons, or UI elements shown to the user during this specific step.

    Note: The IntroShowcase wrapper also accepts backgroundColor and contentColor parameters to style the overlay.

    FloatingActionButton(
        onClick = {},
        modifier = Modifier.introShowCaseTarget(
            index = 0,
            style = ShowcaseStyle.Default.copy(
                backgroundColor = Color(0xFF1C0A00),
                backgroundAlpha = 0.98f,
                targetCircleColor = Color.White
            ),
            content = {
                Column {
                    Text(text = "Check emails", color = Color.White)
                    Text(text = "Click here to check/send emails", color = Color.White)
                }
            }
        ),
        backgroundColor = ThemeColor,
        contentColor = Color.White
    ) {
        Icon(Icons.Filled.Email, contentDescription = "Email")
    }
  4. Use IntroShowcase to implement a feature walkthrough

    master

    The IntroShowcase Composable is the primary entrypoint for displaying a guided walkthrough. It wraps your existing UI content and overlays a ShowcasePopup when showIntroShowCase is true.

    To use it:

    1. Manage the visibility with the showIntroShowCase boolean.
    2. Provide a callback via onShowCaseCompleted to handle the end of the walkthrough.
    3. Use the IntroShowcaseScope provided in the content lambda to attach targets to your UI elements.
    4. Use rememberIntroShowcaseState() to manage the lifecycle and current step of the showcase.
    IntroShowcase(
        showIntroShowCase = isWalkthroughVisible,
        onShowCaseCompleted = { isWalkthroughVisible = false },
        state = rememberIntroShowcaseState(),
        dismissOnClickOutside = true
    ) {
        // Your existing UI content goes here
        Button(
            onClick = { /* ... */ },
            modifier = Modifier.introShowCaseTarget(
                index = 0,
                style = ShowcaseStyle.Default
            ) {
                // Content for the target scope
            }
        )
    }
  5. Initialize IntroShowcaseState with rememberIntroShowcaseState

    master

    To manage the state of your showcase flow, use the rememberIntroShowcaseState composable function. This creates an IntroShowcaseState instance that is remembered across recompositions.

    Note that changing the initialIndex parameter after the initial composition will not recreate or update the existing state.

    val showcaseState = rememberIntroShowcaseState(initialIndex = 0)
  6. Manage showcase flow with IntroShowcaseState

    master

    The IntroShowcaseState class tracks the progress of the showcase. It maintains a map of targets and the index of the currently active target.

    Key properties and methods:

    • currentTargetIndex: The index of the target currently being showcased.
    • currentTarget: Returns the IntroShowcaseTargets object for the current index, or null if no target exists at that index.
    • reset(): Resets the currentTargetIndex to 0, effectively restarting the showcase flow.
    // Accessing the current target
    val target = showcaseState.currentTarget
    
    // Restarting the showcase
    showcaseState.reset()
  7. Display showcase overlays with ShowcaseWindow

    master

    Use the ShowcaseWindow Composable to display an overlay content on top of your existing UI. It manages the lifecycle of a separate window, ensuring that the provided content is shown when the Composable enters the composition and is dismissed when it leaves. It automatically handles the connection to the parent's CompositionContext, LifecycleOwner, ViewModelStoreOwner, and SavedStateRegistryOwner to ensure Compose state and lifecycle-aware components work correctly within the overlay.

    ShowcaseWindow {
        // Your showcase UI content goes here
        Text("This is an overlay!")
    }
  8. Mark UI elements as showcase targets with introShowCaseTarget

    master

    Within the IntroShowcase content block, you can use the introShowCaseTarget extension function on Modifier to designate specific UI components as steps in the walkthrough.

    Parameters:

    • index: The sequential order of the step in the showcase.
    • style: The visual style of the highlight (defaults to ShowcaseStyle.Default).
    • content: A @Composable BoxScope.() -> Unit block used to define the target's scope.
    Modifier.introShowCaseTarget(
        index = 1,
        style = ShowcaseStyle.Default
    ) {
        // Target content
    }