The SDK provides several states that can be observed for seamless UI integration.
Listen for state changes to automatically update the user interface.
ConstellationSdk.State definition: (in com.pega.constellation.sdk.kmp.core)
interface ConstellationSdk {
sealed class State {
data object Initial : State()
data object Loading : State()
data class Ready(val environmentInfo: EnvironmentInfo, val root: RootContainerComponent) : State()
data class Error(val error: EngineError) : State()
data class Finished(val successMessage: String?) : State()
data object Cancelled : State()
}
}
use fun C.Render() for Ready state rendering. (in com.pega.constellation.sdk.kmp.ui.renderer.cmp)
Example code:
@Composable
fun PegaForm(sdk: ConstellationSdk) {
val state by sdk.state.collectAsState()
when (val s = state) {
is ConstellationSdk.State.Initial -> {}
is ConstellationSdk.State.Loading -> SomeLoader()
is ConstellationSdk.State.Ready -> s.root.Render()
is ConstellationSdk.State.Error -> SomeErrorSnackBar()
is ConstellationSdk.State.Finished -> SomeSnackBar()
is ConstellationSdk.State.Cancelled -> SomeCancelSnackBar()
}
}
SomeLoader() is any loader in compose.
SomeErrorSnackBar() is any snackbar with error message.
SomeSnackBar() is any snackbar showing successMessage message.
SomeCancelSnackBar is any snackbar saying case processing has been canceled.