Skip to content
AppDues
Log in
Contact salesSign up

Slide to Unlock in Jetpack Compose: A Slide-to-Purchase Guide

A drag-to-confirm control puts a small physical step between a tap and a transaction, which cuts down on stray taps and makes the buyer's intent explicit. This guide walks through the open-source slide-to-unlock library: adding it to a Compose or Kotlin Multiplatform project, connecting the slider to an in-app purchase, and layering it over a paywall built in the Paywall Editor.

What the slide-to-unlock library gives you

The library is built for Kotlin Multiplatform, so the same component can be used in Android and KMP projects. The core composable is SlideToUnlock: you hold a Boolean state at the call site, pass it in, and flip it when the slide completes. The component exposes customization for colors, the thumb, hint text, gesture behavior, and slide-fraction tracking, and you can supply your own composables for the thumb and hint. A separate purchases artifact adds SlideToPurchases, which triggers an in-app purchase when the slide finishes.

Choose the right component before you code

Use this short decision list to pick the integration path:

  • You only need a slide gesture to gate a local action: use SlideToUnlock with your own state and callback.
  • You want the slide itself to start an in-app purchase: use SlideToPurchases and pass a Package, StoreProduct, SubscriptionOption, PromotionalOffer, or WinBackOffer.
  • You already have a paywall built in the Paywall Editor and want the slider over it: build the paywall without a footer, leave bottom space, fetch the current offering, and overlay SlideToUnlock at the bottom.
  • You need UI the Paywall Editor does not support: fetch offerings manually and render your own screen.

Add the dependency

For a standard Android project, add the slide-to-unlock artifact to your Gradle file. For Kotlin Multiplatform, add the library to the commonMain source set of your module's build.gradle.kts. The exact dependency lines are in the accompanying code modules and should be copied as supplied.

Wire SlideToUnlock with local state

The simplest integration keeps a mutable Boolean at the call site. Pass it as isSlided, give the composable a width modifier, and set the Boolean to true inside onSlideCompleted. That pattern is enough when the slide only needs to reveal or confirm something in your own UI.

Trigger an in-app purchase with SlideToPurchases

SlideToPurchases takes the purchase target and reports progress through onPurchaseStateChanged. A typical flow fetches offerings, picks the monthly package, and passes it to the composable. The callback receives a PurchaseState value, which you can branch on: Loading for a progress indicator, Success for navigation to a success screen, Error for an error message, and null for the initial state. The library provides overloads for product types, subscription upgrades, and promotional offers, so the purchase logic stays inside the component.

Overlay the slider on a custom paywall

The Paywall Editor builds paywalls from a server-driven UI, but it does not officially support Slide to Unlock. The workaround is to create a paywall without a footer and leave room at the bottom. Then fetch the current offering, place the Paywall composable in a Box, and align SlideToUnlock at the bottom center with padding. When the slide completes, set the state and call your purchase handler with the first available package and the current Activity. The full source is available in the Cat Paywall Compose paywalls directory.

A field and control map

Use this map to check inputs and outputs before wiring the components:

  • SlideToUnlock inputs: isSlided (Boolean state), modifier, onSlideCompleted callback, optional hintTexts, and customization parameters for colors, thumb, and gesture behavior.
  • SlideToUnlock output: the onSlideCompleted callback, which you use to update your own state.
  • SlideToPurchases inputs: a purchase target such as a Package, plus a modifier and onPurchaseStateChanged callback.
  • SlideToPurchases output: PurchaseState values Loading, Success, Error, or null.
  • Offering fetch: Purchases.sharedInstance.awaitOfferings() returns an Offerings object; current exposes the active offering, and getPackage("monthly") selects a package by identifier.

Distinguish a completed slide from a completed purchase

A finished slide does not mean the purchase succeeded. In the SlideToUnlock overlay pattern, onSlideCompleted only sets isSlided and forwards the event to your purchase handler. In SlideToPurchases, the purchase outcome arrives separately through onPurchaseStateChanged. Treat the slide as user intent and the PurchaseState as the transaction result; show loading, success, and error UI from the state rather than from the gesture.

Where this fits in a subscription flow

A slider is one design choice among many that shape a subscription screen, and it sits alongside clear value messaging, layout, and price presentation rather than replacing them. What it changes is the moment of commitment: the buyer has to complete a short gesture instead of tapping a button, so the action reads as a decision rather than a slip. Whether that helps your funnel is an empirical question. Run it against a plain button in your own experiment and judge it on your own conversion data instead of assuming the pattern wins by default.

Frequently asked questions

Does SlideToUnlock work in a Kotlin Multiplatform project?

Yes. The library is designed for Kotlin Multiplatform and can be used in Android and KMP projects. For KMP, add the dependency to the commonMain source set of your module's build.gradle.kts.

What is the difference between SlideToUnlock and SlideToPurchases?

SlideToUnlock only reports that the slide completed and leaves the action to your own callback. SlideToPurchases starts an in-app purchase when the slide finishes and reports progress through PurchaseState values.

Can I put Slide to Unlock inside a paywall built in the Paywall Editor?

Not officially. The Paywall Editor does not support Slide to Unlock directly. The workaround is to build a paywall without a footer, leave bottom space, fetch the current offering, and overlay SlideToUnlock at the bottom of a Box that also contains the Paywall composable.

Which purchase targets can SlideToPurchases accept?

The library provides overloads for StoreProduct, Package, SubscriptionOption, PromotionalOffer, and WinBackOffer, covering product types, subscription upgrades, and promotional offers.