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.15.0 or later.
  2. You have created an onboarding.
  3. You have added the onboarding to a placement.

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 createPaywallView one more 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
    }
}