---
title: "TextInputSession"
description: "Represents a input session for interactions between a soft keyboard and editable text.

This session may be closed at any time by [TextInputService] or by calling [dispose], after which
[isOpen] will return false and all further calls will have no effect."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


> **Deprecated** Use PlatformTextInputModifierNode instead.

```kotlin
class TextInputSession(
    private val textInputService: TextInputService,
    private val platformTextInputService: PlatformTextInputService,
)
```


Represents a input session for interactions between a soft keyboard and editable text.

This session may be closed at any time by `TextInputService` or by calling `dispose`, after which
`isOpen` will return false and all further calls will have no effect.


## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val isOpen: Boolean
```


If this session is currently open.

A session may be closed at any time by `TextInputService` or by calling `dispose`.



## Functions

```kotlin
fun dispose()
```


Close this input session.

All further calls to this object will have no effect, and `isOpen` will return false.

Note, `TextInputService` may also close this input session at any time without calling
dispose. Calling dispose after this session has been closed has no effect.


```kotlin
fun notifyFocusedRect(rect: Rect): Boolean
```


Notify the focused rectangle to the system.

The system can ignore this information or use it to for additional functionality.

For example, desktop systems show a popup near the focused input area (for some languages).

If the session is not open, no action will be performed.

#### Parameters

| | |
| --- | --- |
| rect | the rectangle that describes the boundaries on the screen that requires focus |


#### Returns

| | |
| --- | --- |
|  | false if this session expired and no action was performed |



```kotlin
fun updateTextLayoutResult(
        textFieldValue: TextFieldValue,
        offsetMapping: OffsetMapping,
        textLayoutResult: TextLayoutResult,
        textFieldToRootTransform: (Matrix) -> Unit,
        innerTextFieldBounds: Rect,
        decorationBoxBounds: Rect,
    ) = ensureOpenSession {
        platformTextInputService.updateTextLayoutResult(
            textFieldValue,
            offsetMapping,
            textLayoutResult,
            textFieldToRootTransform,
            innerTextFieldBounds,
            decorationBoxBounds,
        )
    }
```


Notify the input service of layout and position changes.

#### Parameters

| | |
| --- | --- |
| textFieldValue | the text field's `TextFieldValue` |
| offsetMapping | the offset mapping for the visual transformation |
| textLayoutResult | the text field's `TextLayoutResult` |
| textFieldToRootTransform | function that modifies a matrix to be a transformation matrix from local coordinates to the root composable coordinates |
| innerTextFieldBounds | visible bounds of the text field in text layout coordinates, or an empty rectangle if the text field is not visible |
| decorationBoxBounds | visible bounds of the decoration box in text layout coordinates, or an empty rectangle if the decoration box is not visible |



```kotlin
fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue): Boolean
```


Notify IME about the new `TextFieldValue` and latest state of the editing buffer. `oldValue`
is the state of the buffer before the changes applied by the `newValue`.

`oldValue` represents the changes that was requested by IME on the buffer, and `newValue` is
the final state of the editing buffer that was requested by the application. In cases where
`oldValue` is not equal to `newValue`, it would mean the IME suggested value is rejected, and
the IME connection will be restarted with the newValue.

If the session is not open, action will be performed.

#### Parameters

| | |
| --- | --- |
| oldValue | the value that was requested by IME on the buffer |
| newValue | final state of the editing buffer that was requested by the application |


#### Returns

| | |
| --- | --- |
|  | false if this session expired and no action was performed |



```kotlin
fun showSoftwareKeyboard(): Boolean
```


Request showing onscreen keyboard.

This call will have no effect if this session is not open.

This should be used instead of `TextInputService.showSoftwareKeyboard` when implementing a
new editable text composable to show the keyboard in response to events related to that
composable.

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

#### Returns

| | |
| --- | --- |
|  | false if this session expired and no action was performed |



```kotlin
fun hideSoftwareKeyboard(): Boolean
```


Hide onscreen keyboard for a specific `TextInputSession`.

This call will have no effect if this session is not open.

This should be used instead of `TextInputService.showSoftwareKeyboard` when implementing a
new editable text composable to hide the keyboard in response to events related to that
composable.

#### Returns

| | |
| --- | --- |
|  | false if this session expired and no action was performed |




