Skip to content

Discovery Service Activation

This screen is used to activate the application configuration from Discovery Service during the onboarding process.

Discovery Service

Definition

fun ActivationDiscoveryScreen(
    state: DiscoveryScreenState,
    activationScreenSettings: ActivationDiscoveryScreenSettings? = null,
    startButtonClickListener: ((String) -> Unit)? = null
) { ... }

class DiscoveryScreenState(email: String = "", error: String = "", busy: Boolean = false) {
    ...
}

@Composable
fun rememberDiscoveryScreenState(email: String = "", error: String = "", busy: Boolean = false)
        : DiscoveryScreenState { ... }

Besides the screen settings and the button click handling arguments, this screen has a state argument, which is used by the client code of this screen to change the UI states.

In most of the onboarding screens, the internal UI states can be handled by the screen itself. But for this screen, to show an error message on the screen, usually the error can be encountered only after an API call in the startButtonClickListener, which will be provided by the client code. If any errors are encountered, the client code can update the state argument value to update the UI states of this screen to show the error messages.

Example

@Composable
fun DiscoveryActivation(block: (appConfig: AppConfig) -> Unit) {
    val context = LocalContext.current
    val discoveryState = rememberDiscoveryScreenState()
    ActivationDiscoveryScreen(
        state = discoveryState,
        startButtonClickListener = { domain ->
            flowViewModel.viewModelScope.launch {
                discoveryState.busyState.value = true
                when (val result = DiscoveryService(context).retrieveAppConfig(
                    domain = domain,
                    applicationId = FlowContextRegistry.flowContext.appConfig.appID
                )) {
                    is ServiceResult.SUCCESS -> {
                        discoveryState.busyState.value = false
                        block(result.data!!)
                    }
                    is ServiceResult.FAILURE -> {
                        discoveryState.busyState.value = false
                        discoveryState.errorState.value = result.message
                    }
                }
            }
        }
    )
}

activationScreenSettings has a reference to IllustrationSettings to configure the icon on this screen, like what 'Activation Selection' screen does.


Last update: April 5, 2024