PromptModel

Base model object for prompts.

Prompt is a UI dialog (typically a modal bottom sheet dialog) that asynchronous code can pop up merely by calling a specialized function like requestPassphrase (more generally PromptDialogModel.displayPrompt on a dialog model obtained through getDialogModel). Such function will pop up the dialog, and then suspend until user enters the input, performs the required action or dismisses the dialog. User input is then returned to the caller (or PromptDismissedException is thrown if the dialog is dismissed).

PromptModel must exist in the current CoroutineContext for prompt functions to work.

  • An instance of PromptModel can be added to the context using withContext.

  • There is a predefined coroutine scope promptModelScope that is bound to the context that contains this model (it can be used similar to ViewModel.viewModelScope on Android).

  • In Composable environment PromptModel can be used with rememberCoroutineScope like this:

      val myScope = rememberCoroutineScope { promptModel }

PromptModel is actually a holder object for individual dialog models PromptDialogModel. More dialog types can be registered by creating and registering PromptDialogModel classes in the platform PromptModel. Each dialog must be bound to its UI independently (see org.multipaz.compose.prompt.PromptDialogs in multipaz-compose for an example), in different UI scenarios a different set of dialogs may be supported.

This class is abstract, as each platform should generally implement its own variant, in particular by providing an appropriate promptModelScope.

Inheritors

Types

Link copied to clipboard
abstract class Builder(val toHumanReadable: ConvertToHumanReadableFn)

Builder for PromptModel.

Link copied to clipboard
object Companion
Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard
abstract val promptModelScope: CoroutineScope

Functions

Link copied to clipboard
open override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R
Link copied to clipboard
open operator override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E?
Link copied to clipboard
Link copied to clipboard
open suspend fun launchUi(dialogModel: PromptDialogModel<*, *>)

This method is called when there is no UI that is bound to a particular PromptDialogModel.

Link copied to clipboard
open override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext
Link copied to clipboard
open operator fun plus(context: CoroutineContext): CoroutineContext
Link copied to clipboard
suspend fun PromptModel.requestPassphrase(title: String, subtitle: String, passphraseConstraints: PassphraseConstraints, passphraseEvaluator: suspend (enteredPassphrase: String) -> PassphraseEvaluation?): String

Prompts user for authentication through a passphrase.