Present onboardings in Kotlin Multiplatform SDK

If you’ve customized an onboarding using the builder, you don’t need to worry about rendering it in your Kotlin Multiplatform app code to display it to the user. Such an onboarding contains both what should be shown within the onboarding and how it should be shown.

Before you start, ensure that:

  1. You have installed Adapty Kotlin Multiplatform SDK 3.16.1 or later.
  2. You have created an onboarding.
  3. You have added the onboarding to a placement.

Adapty Kotlin Multiplatform SDK provides two ways to present onboardings:

  • With Compose Multiplatform
  • Without Compose Multiplatform

With Compose Multiplatform

To display an onboarding, use the view.present() method on the view created by the createOnboardingView method. Each view can only be used once. If you need to display the onboarding again, call createOnboardingView one more time to create a new view instance.

Reusing the same view without recreating it may result in an error.

import com.adapty.kmp.AdaptyUI
import kotlinx.coroutines.launch

viewModelScope.launch {
    AdaptyUI.createOnboardingView(onboarding = onboarding).onSuccess { view ->
        view.present()
    }.onError { error ->
        // handle the error
    }
}

Configure iOS presentation style

Configure how the onboarding is presented on iOS by passing the iosPresentationStyle parameter to the present() method. The parameter accepts AdaptyUIIOSPresentationStyle.FULLSCREEN (default) or AdaptyUIIOSPresentationStyle.PAGESHEET values.

import com.adapty.kmp.AdaptyUI
import com.adapty.kmp.models.AdaptyUIIOSPresentationStyle
import kotlinx.coroutines.launch

viewModelScope.launch {
    val view = AdaptyUI.createOnboardingView(onboarding = onboarding).getOrNull()
    view?.present(iosPresentationStyle = AdaptyUIIOSPresentationStyle.PAGESHEET)
}

By default, links in onboardings open in an in-app browser. This provides a seamless user experience by displaying web pages within your application, allowing users to view them without switching apps.

If you prefer to open links in an external browser instead, you can customize this behavior by setting the externalUrlsPresentation parameter to AdaptyWebPresentation.EXTERNAL_BROWSER:

import com.adapty.kmp.AdaptyUI
import com.adapty.kmp.models.AdaptyWebPresentation
import kotlinx.coroutines.launch

viewModelScope.launch {
    AdaptyUI.createOnboardingView(
        onboarding = onboarding,
        externalUrlsPresentation = AdaptyWebPresentation.EXTERNAL_BROWSER // default – IN_APP_BROWSER
    ).onSuccess { view ->
        view.present()
    }.onError { error ->
        // handle the error
    }
}

Without Compose Multiplatform

createNativeOnboardingView is part of the core io.adapty:adapty-kmp module. If your project does not use Compose Multiplatform, you don’t need the io.adapty:adapty-kmp-ui dependency.

To embed an onboarding without Compose Multiplatform, call createNativeOnboardingView. It returns an AdaptyNativeOnboardingView that you add to your layout:

Dispose the view

Call dispose() when removing the view from your layout. This unregisters the event listener and releases internal resources.

nativeView.dispose()