TextInputService

Class

Common

Deprecated Use PlatformTextInputModifierNode instead.

open class TextInputService(private val platformTextInputService: PlatformTextInputService)

Handles communication with the IME. Informs about the IME changes via EditCommands and provides utilities for working with software keyboard.

This class is responsible for ensuring there is only one open TextInputSession which will interact with software keyboards. Start new a TextInputSession by calling startInput and close it with stopInput.

Functions

open fun startInput(
        value: TextFieldValue,
        imeOptions: ImeOptions,
        onEditCommand: (List<EditCommand>) -> Unit,
        onImeActionPerformed: (ImeAction) -> Unit,
    ): TextInputSession

Start text input session for given client.

If there is a previous TextInputSession open, it will immediately be closed by this call to startInput.

Parameters

valueinitial TextFieldValue
imeOptionsIME configuration
onEditCommandcallback to inform about changes requested by IME
onImeActionPerformedcallback to inform if an IME action such as ImeAction.Done etc occurred.
@InternalTextApi
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    fun startInput()

Restart input and show the keyboard. This should only be called when starting a new PlatformTextInputModifierNode.textInputSession.

open fun stopInput(session: TextInputSession)

Stop text input session.

If the session is not the currently open session, no action will occur.

Parameters

sessionthe session returned by startInput call.
@InternalTextApi
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    fun stopInput()
fun showSoftwareKeyboard()

Request showing onscreen keyboard.

This call will be ignored if there is not an open TextInputSession, as it means there is nothing that will accept typed input. The most common way to open a TextInputSession is to set the focus to an editable text composable.

There is no guarantee that the keyboard will be shown. The software keyboard or system service may silently ignore this request.

fun hideSoftwareKeyboard(): Unit

Hide onscreen keyboard.