Repository navigation
Conversation
…or consistent paragraph rendering
|
This is quite a change in behaviour. Should these be separate properties so developers can choose which one they want? |
|
@javache it does change the behavior, but I don’t think it introduces a second valid selection mode that needs an opt-in.
An app that intentionally wants “long press copies this whole block” has clearer, explicit ways to implement that interaction (for example, a long-press handler that copies a known string). And implementing this correctly still allows for the previous behavior: you can select the entire block of text and still copy it—so not really a “breaking” change, though slightly different in the UX. It is behavior-changing for apps that may have relied on it, but it’s appropriately a fix: it brings the documented native-selection affordance into line with Android and normal iOS expectations. |
|
I was about to say the exact same thing. Adding a new prop will add a lot of additional work if we consider that approach. P.S. - Solved the CI error, which trimmed the code by a few lines |
|
Lets make the changelog entry here more explicit, and call out that the default behaviour for selectable is quite different with this change. |
Abbondanzo
left a comment
There was a problem hiding this comment.
@javache's comment is fair--this is bringing iOS to parity with Android but should be marked as a breaking change just so we can call it out in the changelog. I was poking through and found some rendering issues with the new approach that should get fixed up first (especially pressable text)
…electableTextView for improved text selection handling
|
Good catch. The cause was one thing: the Split those two jobs:
Your review also turned up a regression I had missed: removing the old Added P.S. - Update the changelog please check |
|
I solved the merge conflicts, and it seems the CI didn't fail due to my changes |
|
Created a patch fix based on this PR and ran it in a production app on React Native 0.86.3, Expo SDK 57. Body text there is one Where the nested nodes are styling only, selection works: handles, and Copy, Look Up, Translate, Search Web and Share acting on the selected range. A paragraph holding a nested pressable One change did not fit 0.86.3. That release has neither Happy to retest once pressable text is sorted. Looking forward to seeing this merged. |
|
@ivannzme thank you for patching this into a real app and testing it. That report found a genuine defect, and it would not have shown up in the examples I had. The cause. A press on a nested paints a highlight, which changed the attributed string. The selection view rebuilt itself in the middle of the touch, so UITextView lost the long press it had already started. The fix. The rebuild now follows the layout string instead of the painted one, so a paint-only change no longer recreates the view. That exposed a second problem: onPress fired while selecting, because React Native's touch handler and the selection gesture track the same touch. The paragraph now gives up the touch once a selection shows. Checked by hand on RNTester, iOS 18.6: pressable children select, decorations survive, scrolling and ordinary link taps still work. @ivannzme a retest would be helpfu |
|
Retested the updated branch on React Native 0.86.3, Expo SDK 57. The pressable-text fix works: a paragraph carrying a nested pressable One new problem, on recycled views. It reads as intermittency from the outside. After a fresh launch the first article selects fine. Once enough screens have been visited for the view pool to warm up, every paragraph is dead, including articles opened for the first time. Creating the layout manager lazily in if (_selectionLayoutManager == nil) {
_selectionLayoutManager = [RCTTextLayoutManager new];
}Eight of eight paragraphs across four article opens after that, including a re-opened article and one with an inline link. |
…add corresponding test
|
@ivannzme thanks, I updated the PR |
|
@Abbondanzo are we good with the changes? Is anything pending on my end? |
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D122903141. |
Abbondanzo
left a comment
There was a problem hiding this comment.
@raajnadar Received some fair feedback internally that I'd like to pass along:
- Could you split out the new
RCTSelectableTextViewinterface and implementation into a separate file(s)? - Could you put this change behind a feature gate? The existing behavior should be retained when the gate is off (default off for now). We can run an experiment in turn across our apps to ensure this is rolled out safely
|
@Abbondanzo, thanks for passing this along. Both points are done:
Now, as the PR is non-breaking, I updated the title and the changelog entry |
|
As 0.88.0 is released, I think we can put this on a minor release |
cortinico
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
cipolleschi
left a comment
There was a problem hiding this comment.
Thanks for working on this, partial text selection on iOS is a long-standing request, and having it behind a feature flag is the right call.
I left some inline comments. My main concerns are touch handling (inline children, pointerEvents, concurrent touches), backgrounds covering the selection highlight, and the cost of a second TextKit stack for every selectable paragraph. Could you also add the missing tests and some perf measurements to the Test Plan?
| if (_selectableTextView.selectedRange.length > 0) { | ||
| return nullptr; | ||
| } |
There was a problem hiding this comment.
While there's a selection, this returns a null emitter for any touch on the paragraph, wherever it lands. Is that intended? For example, take a padded paragraph inside a Pressable. A tap in the padding, outside the selection view, doesn't fall back to the parent. Dismissing the selection on release can't restore the emitter captured on touch down either.
What about W3C pointer events? Pointer dispatch calls this getter again for pointerUp and pointerCancel, but the selection only resets the touch handler. If the selection becomes non-empty after pointerDown, isn't the final pointer event dropped? Can you verify the callback ordering and the pointer-capture cleanup on a device?
There was a problem hiding this comment.
Both fixed.
-
The guard now covers only a touch on the selected text or its handles. A tap in the padding presses as before.
-
The selection view cancels first and raises the guard after, so the selecting pointer gets its pointerCancel.
I checked the event order on the simulator with W3C dispatch on. I couldn't check on a device
| XCTAssertNil(attributes[NSUnderlineStyleAttributeName]); | ||
| XCTAssertNil(attributes[NSStrikethroughStyleAttributeName]); | ||
| XCTAssertNil(attributes[NSShadowAttributeName]); |
There was a problem hiding this comment.
A few gaps in the tests:
- The paint-stripping assertions don't prove much. The fixture uses a wavy decoration (our custom attribute) and no shadow, so the native underline, strikethrough and shadow attributes are
nilfrom the start. Could we add fixtures with a solid decoration and a real shadow, and first assert that the input contains them? - The layout fixtures use default paragraph attributes and a synthetic size, and they don't compare the selection rects with the painted glyphs. How do we know the two match with
adjustsFontSizeToFit/minimumFontScale, truncation, or a compressedlineHeight? - Hiding the
UITextViewstops VoiceOver from reading the text twice (testSelectionTextViewIsHiddenFromAccessibility), but the existing accessibility elements don't expose the selection. Can a VoiceOver user start, adjust and copy a selection? Can you verify that?
There was a problem hiding this comment.
-
Paint stripping: the fixture now has a solid underline, a strikethrough, a shadow and a background, and the test first asserts they're in the input.
-
Layout: three testSelectionLayoutMatchesTheDrawingWith... tests compare the selection layout with the drawing glyph by glyph, for adjustsFontSizeToFit, truncation, and a compressed lineHeight.
-
VoiceOver: I couldn't test this; the simulator has no VoiceOver and I can't deploy to a device. Could someone on your side check it?
Visual regressionNo visual differences at android: no capture |
…/ios-partial-text-selection
…he selection view
Summary:
On iOS,
<Text selectable>can only copy the whole paragraph. There is no highlight and no drag handles, so you cannot select part of it. Android has allowed this since the prop was added.Fixes #13938, open since 2017. Also covers #55187, which reports the same gap as an iOS 26 regression. It is not a regression: iOS selection has always copied the whole block.
How it works, behind
enableIOSPartialTextSelection(default off):RCTParagraphTextViewstill draws the paragraph. Nothing changes in the painting.UITextViewbelow the glyphs handles selection only. It gets the same text with the paint attributes removed, laid out by the sameRCTTextLayoutManagermethod as the drawing.main.Changelog:
[IOS] [ADDED] - Add the
enableIOSPartialTextSelectionfeature flag. When the flag is on, a long press on<Text selectable>selects a range of text, and Copy copies only that range.Test Plan:
All runs: RNTester, iOS 18.6 simulator, Xcode 16.4, x86_64 Debug.
Unit tests
React/Testsis in no installed pod, so I added the test file to theRNTesterUnitTeststarget locally to run it.yarn featureflags --verify-unchangedpasses.Manual checks, flag on
onPresson a nested<Text>lineHeight,numberOfLinesPressablepointerEvents="box-none"pointerEvents="box-only"pointerdown › pointercancel. Handle drag: no events. Tap in the padding:pointerdown › pointerup › pressUITextViewPerformance
200 rich paragraphs of about 700 characters each, median time for all 200, flag off / flag on:
So the cost comes only with a touch: about 10.6 ms once, and about 0.72 MB retained for each touched paragraph. Scrolling a 300-row list of these paragraphs showed no visible change with the flag on.
These numbers are from a Debug simulator build before the latest merge of
main, so read them as a comparison, not as absolute values.