Configure the Experience

The SDK offers a simple interface that allows you to offer Experiences to your users in few lines of code.

An app can be configured to exist as an embed within a written article, rather like a widget. But you can also set the same app to display full page with its header and footer.

This section covers the available options:


Manage Dynamic Sizing

By default, the SDK will respect the height specified within your application and display a scrollbar when necessary so the user can navigate the full content.

However, the SDK can automatically manage the height of the view for you, by respecting the width set and updating the height to match that of the content in the app:

...
val config = ExperienceConfiguration(
    autoresizesHeight = true
)

val experienceView = Launcher.default.getExperience(context, config)
...

Respond to Resizing

Additionally, the SDK lets you listen to changes in the intrinsic size of the web page, so you can handle the resize with your preferred approach:

...
val experienceViewListener = object: ExperienceViewListener {
  override fun onIntrinsicSizeChanged(
      experienceView: ExperienceView, 
      width: Float, 
      height: Float
  ) {
    // Here you can update your size as needed
  }
}

val experienceView = Launcher.default.getExperience(context, config).apply {
  listener = experienceViewListener
}

Launch a Specific Event

By default, the SDK will launch the app without specifying a specific event and will use the project's default Event.

If you want to launch to a specific event, you can do so by specifying the Event ID using the example below. To retrieve and determine the event you want, refer to Getting and displaying Events

...
val config = ExperienceConfiguration(
    eventId = "<event id>"
)

val experienceView = Launcher.default.getExperience(context, config)
...

Provide Custom Parameters

The SDK allows you to provide custom query parameters in LauncherKit to customise the app you embed. How the app responds depends on how it was created so this is general feature available for developers.

You can use it as follows:

...
val config = ExperienceConfiguration(
    parameters = hashMapOf("customKey" to "customValue")
)

val experienceView = Launcher.default.getExperience(context,config)
...

Loading and Error Views

By default, the SDK will use the loading view from the app itself. You can enable a custom loading / error view by setting supportsLoadingState to true.

Loading and error views are not supported when using the ExperienceActivity and ExperienceFragment classes rather than ExperienceView as we can't parcelise the view providers.

Use instead an ExperienceView or wrap it with your own Activity or Fragment.

...
val config = ExperienceConfiguration(
    supportsLoadingState = true
)

val experienceView = Launcher.default.getExperience(context, config)
...

When enabled, a simple black-on-white loading screen is displayed so as to avoid having a blank screen whilst the app is loaded.

You can customise these views by passing via ExperienceConfiguration a ViewProvider, which is responsible to create a view to display instead of the default loading/error views.

...
val loadingView = View.inflate(context, R.layout.loading_view, null)
val errorView = View.inflate(context, R.layout.loading_view, null)

val config = ExperienceConfiguration(
    loadingViewProvider = { loadingView },
    errorViewProvider = { errorMessage -> errorView }
)

val experienceView = Launcher.default.getExperience(context, config)
...

Customise Loading Timeout

To customise how long the loading view is displayed before transitioning to either the main app view or an error view, you can specify a timeout parameter in your ExperienceConfiguration.

...
val config = ExperienceConfiguration(
    dismissLoadingViewTimeout = 10.seconds
)

val experienceView = Launcher.default.getExperience(context, config)
...

Customise Background

To customise the background during the loading of the experience, add a background colour parameter to your ExperienceConfiguration. This optional setting lets you modify the webview's background appearance. If not specified, the system default will be used.

...
import android.graphics.Color

val config = ExperienceConfiguration(
  backgroundColor = Color.BLACK
)

val experienceView = Launcher.default.getExperience(context, config)
...

By default, the SDK assumes that the parent application will be displaying its own header and footer, and therefore we hide the app's default header if one exists. You can override this behaviour and present the header and footer of the app by using the following snippet:

...
val config = ExperienceConfiguration(
  hidesHeadersAndFooters = false
)

val experienceView = Launcher.default.getExperience(context, config)
...

By default, the SDK does not open hyperlinks externally in the web browser. You can override this behaviour and allow for any link containing the blank target to open in an external app by using the following snippet:

...
val config = ExperienceConfiguration(
  launchesURLsWithBlankTargetToChrome = true
)

val experienceView = Launcher.default.getExperience(context, config)
...

Last updated