Skip to content

fix(iOS, Android): ZWS parity fixes - #860

Open
szydlovsky wants to merge 3 commits into
@kacperzolkiewski/fix-onlink-detectedfrom
@szydlovsky/ios-zws-parity
Open

szydlovsky wants to merge 3 commits into
@kacperzolkiewski/fix-onlink-detectedfrom
@szydlovsky/ios-zws-parity

Conversation

@szydlovsky

@szydlovsky szydlovsky commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

iOS stores a zero-width space (\u200B) in every empty list / quote / code block / checkbox paragraph. JS never sees these characters: onChangeText strips them. But most iOS events and commands that take or report a range counted them anyway. With an empty styled line above, iOS indices were shifted by one per empty line and didn't match the onChangeText value or Android.

Android already converts everywhere; this PR brings iOS in line and fixes a related setLink issue on Android:

  • Added shared helpers to ZeroWidthSpaceUtils to strip zero-width spaces and convert between visible (JS) and actual (native side) indices and ranges.
  • Outgoing: onChangeSelection, onLinkDetected and onContextMenuItemPress now report visible indices, and their text fields no longer include \u200B.
  • Incoming: setLink and removeLink now convert visible indices, as setSelection already did. All three go through the same helper.
  • onChangeText / onSubmitEditing use the shared strip helper (no behaviour change).
  • iOS addLink compares the given link text with the selected content stripped of zero-width spaces. Text coming from JS never contains them, so before, a selection spanning an empty styled line didn't match and was replaced, losing its formatting, paragraph styles and those spaces. Now only the link is added. The cursor is also placed at the end of the linked range rather than start + text.length, which fell short by one character per empty line.
  • Android setLinkSpan always replaced the selected text, even when it was identical, with the same result: formatting and paragraph styles were lost. It now replaces the text only when it differs (ignoring zero-width spaces), and otherwise just adds the link.

Inputs and outputs are changed together on purpose: iOS was raw on both sides, so flows like onChangeSelection → setLink kept working and must keep working.

Test Plan

Set the value to <ul><li></li><li></li></ul><p><a href="https://swmansion.com">foo</a> bar</p> and check on iOS and Android that the values match:

  • cursor after foo → onChangeSelection 5–5; Select All → 0–9 with text length 9
  • cursor in foo → onLinkDetected 2–5
  • foo selected → context menu item gets 2–5 and "foo"
  • setLink(6, 9, 'bar', url) links exactly bar; removeLink(2, 5) unlinks the whole foo
  • setSelection(5, 2) selects foo
  • editing a link through the example app's link modal still works
  • without empty styled paragraphs, all values are unchanged

Screenshots / Videos

--

Compatibility

OS Implemented
iOS ✅
Android ✅
Web ❌

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@szydlovsky
szydlovsky requested review from exploIF and a balanced review from Copilot November 10, 2026 11:52
@szydlovsky
szydlovsky changed the base branch from main to @kacperzolkiewski/fix-onlink-detected November 10, 2026 11:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Linking a selection that spans an empty styled paragraph can replace the selected content instead of only adding link metadata, losing mixed formatting and paragraph styles.

1 open issue
What changed in this PR

Aligns iOS rich-text indices with JavaScript-visible text and Android by excluding internal zero-width spaces from event payloads and converting incoming command ranges.

Changes:

  • Adds shared helpers for stripping zero-width spaces and converting indices and ranges.
  • Updates selection, link, and context-menu events to report visible text and ranges.
  • Applies shared conversion to selection and link commands, and reuses stripping helpers for text-change and submit events.
File Description
ios/​utils/​ZeroWidthSpaceUtils.mm Implements shared text-stripping and index-conversion helpers.
ios/​utils/​ZeroWidthSpaceUtils.h Declares the new helper APIs.
ios/​EnrichedTextInputView.mm Integrates helpers into outgoing events and incoming commands.

Review effort: Balanced

Comment thread ios/EnrichedTextInputView.mm Resolved
@szydlovsky szydlovsky changed the title fix(iOS): ZWS parity fixes fix(iOS, Android): ZWS parity fixes Nov 10, 2026

This branch has not been deployed

No deployments
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.

3 participants