A Comprehensive Guide to Adding Walkthroughs in Jetpack Compose Apps

Jyoti Sheoran
2 min readFeb 19, 2024

--

Walkthroughs or spotlights are essential in many mobile applications to guide users through the app’s features. Integrating spotlights into Jetpack Compose apps can enhance user experience and facilitate navigation. In this article, we’ll explore how to integrate spotlights into Jetpack Compose apps using the Spotlight Compose Library.

Overview of Spotlight Compose Library:

The Spotlight Compose Library provides a convenient way to add spotlights to Jetpack Compose apps. It offers functionalities highlighting specific views and guiding users through the app’s interface seamlessly.

Getting Started:

To integrate the Spotlight Compose Library into your Jetpack Compose app, follow these steps:

  1. Add the library dependencies to your Gradle project.
  • Add the JitPack repository to your build file. Insert the following code at the end of your root build.gradle within the repositories block:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
  • Add the library dependency.
dependencies {
implementation 'com.github.JyotiBhambhu:spotlight_compose_library:1.0.0.1'
}

2. Use the provided functions and modifiers to identify the views to be highlighted and display the spotlights accordingly.

Example Project:

For a hands-on demonstration, you can explore the complete example project in the walkthrough_demo repository. This repository contains a fully functional Jetpack Compose app showcasing the integration of spotlights using the Spotlight Compose Library.

Implementation Steps:

In the example project, you’ll find the following implementation steps:

  1. Adding the Spotlight Compose Library dependency, as mentioned above.

2. Identify the highlighted views using Modifier.onGloballyPositioned { coordinates -> }.

Like it did in the example project

modifier = Modifier
.fillMaxWidth()
.onGloballyPositioned { coordinates ->
when (i) {
1 -> cordsUpdated(
WalkthroughScreen
.Home(TargetHome.TARGET_1)
.getTarget(),
coordinates
)

5 -> cordsUpdated(
WalkthroughScreen
.Home(TargetHome.TARGET_5)
.getTarget(),
coordinates
)

10 -> cordsUpdated(
WalkthroughScreen
.Home(TargetHome.TARGET_10)
.getTarget(),
coordinates
)
}
}

3. Displaying the spotlights using the RenderSpotlight() function with appropriate parameters.

if (spotlightState.showSpotlight) {
RenderSpotlight(
spotLightIndex = spotlightState.currentTargetIndex,
targets = spotlightState.targets,
scrollState = scrollState,
spotlightActions = SpotlightActions(
removeTarget = {
spotlightViewModel.onIntent(
SpotlightMviIntent.RemoveTarget(it)
)
},
showNextTarget = {
spotlightViewModel.onIntent(
SpotlightMviIntent.ShowNextTarget(it)
)
},
showPrevTarget = {
spotlightViewModel.onIntent(
SpotlightMviIntent.ShowPrevTarget(it)
)
}
)
)
}

4. Handling spotlight actions such as removing targets or navigating to the next/previous target. You can take a reference from the demo project, to manage states for spotlight targets.

Conclusion:

Integrating spotlights into Jetpack Compose apps enhances user engagement and facilitates navigation, especially for new users. Following the steps outlined in this article and exploring the example project, you can seamlessly integrate spotlights into your Jetpack Compose app and provide an intuitive user experience.

Stay Connected:

To stay updated with the latest developments and tutorials, follow me on GitHub and Medium.

References:

Thank you for reading! Happy coding!

--

--

Jyoti Sheoran
Jyoti Sheoran

No responses yet