Skip to content

feat: add getCaretRect command and onCaretRectChange event#234

Merged
hryhoriiK97 merged 2 commits intomainfrom
feat/caret-rect-api
Apr 10, 2026
Merged

feat: add getCaretRect command and onCaretRectChange event#234
hryhoriiK97 merged 2 commits intomainfrom
feat/caret-rect-api

Conversation

@hryhoriiK97
Copy link
Copy Markdown
Collaborator

@hryhoriiK97 hryhoriiK97 commented Apr 10, 2026

What/Why?

Fixes: #233

Add onCaretRectChange callback and imperative getCaretRect() command to EnrichedMarkdownInput.

When the input is used with scrollEnabled={false} inside an outer ScrollView (e.g., a post composer), there's no built-in way to know where the caret is in pixel coordinates — onChangeSelection only provides character offsets, which aren't enough to determine screen position with word-wrapped lines.

onCaretRectChange fires whenever the caret moves (typing, selection change, content reflow) and returns { x, y, width, height } in dp relative to the input's top-left corner. The native side diffs the rect before emitting to avoid redundant bridge traffic. getCaretRect() provides the same data as a one-off Promise-based query.

Both APIs surface caret geometry that the native text systems already track internally (UITextView.caretRectForPosition on iOS, Layout.getLineForOffset/getLineTop/getPrimaryHorizontal on Android).

Testing

PR Checklist

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes

@hryhoriiK97 hryhoriiK97 merged commit adce6d9 into main Apr 10, 2026
5 checks passed
@hryhoriiK97 hryhoriiK97 deleted the feat/caret-rect-api branch April 10, 2026 10:34
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.

Feature request: onCaretRectChange callback for outer ScrollView coordination

1 participant