Skip to content

Expose textFieldValue and onTextFieldValueChange as public API#644

Open
tomkoptel wants to merge 1 commit intoMohamedRejeb:mainfrom
tomkoptel:feature/expose-textfield-value-change-api
Open

Expose textFieldValue and onTextFieldValueChange as public API#644
tomkoptel wants to merge 1 commit intoMohamedRejeb:mainfrom
tomkoptel:feature/expose-textfield-value-change-api

Conversation

@tomkoptel
Copy link
Copy Markdown

Summary

  • Make textFieldValue public (was internal) on RichTextState
  • Make onTextFieldValueChange public (was internal) on RichTextState

Motivation

When building mention/hashtag systems on top of BasicRichTextEditor, consumers need synchronous interception of text changes to protect mention tokens from partial deletion. For example, pressing backspace at the end of @John Doe should remove the entire mention in one go, not just the last character.

This behavior mirrors Compose Text 2's InputTransformation but for the old BasicTextField(value, onValueChange) API that BasicRichTextEditor wraps.

The typical pattern is to wrap BasicTextField directly with a custom onValueChange that inspects the change, modifies it if needed, then forwards to state.onTextFieldValueChange():

BasicTextField(
    value = state.textFieldValue,
    onValueChange = { newValue ->
        val corrected = interceptMentionDeletion(state.textFieldValue, newValue)
        state.onTextFieldValueChange(corrected ?: newValue)
    },
    visualTransformation = state.visualTransformation,
)

Without public access to these members, consumers must use reflection which is fragile across library versions and breaks with R8/ProGuard optimizations.

Changes

2 lines changed in RichTextState.kt:

  • Line 60: internal var textFieldValuepublic var textFieldValue
  • Line 1528: internal fun onTextFieldValueChangepublic fun onTextFieldValueChange

No behavioral changes. No new APIs. Just visibility.

Make `textFieldValue` and `onTextFieldValueChange` public on
`RichTextState` to enable custom `BasicTextField` wrappers that
intercept value changes before they are committed.

Use case: mention/hashtag systems need synchronous interception of
text changes to protect mention tokens from partial deletion (e.g.,
backspace at the end of "@john Doe" should remove the entire mention,
not just the last character). This behavior mirrors Compose Text 2's
`InputTransformation` but for the old `BasicTextField(value, onValueChange)`
API that `BasicRichTextEditor` wraps.

Without this, consumers must use reflection to access these members,
which is fragile across library versions and breaks with R8/ProGuard.

Changes:
- `internal var textFieldValue` → `public var textFieldValue`
- `internal fun onTextFieldValueChange` → `public fun onTextFieldValueChange`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant