Repository navigation
feat: support partial text selection on iOS <Text selectable> with feature flag #58363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
raajnadar
wants to merge
28
commits into
react:main
Choose a base branch
from
raajnadar:fix/ios-partial-text-selection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,702
−94
Open
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
face14d
feat: implement selectable text view and update text layout manager f…
raajnadar bfb22e7
fix: add textStorageForNSAttributedString method to RCTTextLayoutManager
raajnadar d185a90
fix: enhance RCTSelectableTextView for improved text selection handling
raajnadar 2dbe5b7
fix: add sourceAttributedText property and update copy method in RCTS…
raajnadar ef3e8d7
Merge branch 'main' into fix/ios-partial-text-selection
raajnadar a401293
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 061745c
remove redundant comments in RCTParagraphComponentView.mm for clarity
raajnadar 1c80a02
fix: text selection handling in RCTParagraphComponentView and add tes…
raajnadar 06858b5
fix: improve selection text view handling in recycled paragraphs and …
raajnadar cfff5db
feat: split RCTSelectableTextView to add it behind feature flag
raajnadar 804fc55
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar ec3503a
fix: build the selectable text view in finalizeUpdates after layoutSu…
raajnadar d974ca1
feat: put partial text selection behind the enableIOSPartialTextSelec…
raajnadar 44645fc
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 8c28b3f
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 089b0b1
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar fdb5bc7
Merge branch 'main' of https://github.com/react/react-native into fix…
raajnadar 354dbf4
test(iOS): prove the selection text view strips native painting attri…
raajnadar cf789ab
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 8aff841
fix: build the selection text view on the first touch
raajnadar bff1c36
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 1355738
fix: lay out the selection text in the same container size as the dra…
raajnadar 4e07d1e
fix: cancel only the selection touch and scope the emitter guard to t…
raajnadar 5913659
fix: enhance paragraph selection tests for layout consistency and fon…
raajnadar 422d8c0
fix: keep a touch on the selection handles out of React Native from s…
raajnadar e4cf607
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar 799b274
fix: clear the selection on a tap on an inline view
raajnadar ee174cf
Merge remote-tracking branch 'upstream/main' into fix/ios-partial-tex…
raajnadar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...s/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTSelectableTextView+Internal.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
|
|
||
| #import <React/RCTDefines.h> | ||
|
|
||
| #if !TARGET_OS_TV | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| /* | ||
| * Strips every attribute that paints, and keeps every attribute that lays out. | ||
| * | ||
| * `RCTTextLayoutManager` draws the paragraph itself, and it draws effects UIKit | ||
| * knows nothing about: wavy, dotted and dashed decorations, and the pressed | ||
| * highlight of a nested pressable <Text>. The selection text view must lay the | ||
| * same glyphs out, because that is what places the selection rects, but it must | ||
| * not paint them. So the font, the kerning, the paragraph style and the | ||
| * attachments stay, and the colors, the decorations and the shadow go. | ||
| */ | ||
| RCT_EXTERN NSAttributedString *RCTUnpaintedAttributedString(NSAttributedString *attributedString); | ||
|
|
||
| /* | ||
| * A non-editable `UITextView` that provides selection for a paragraph, and | ||
| * nothing else. | ||
| * | ||
| * It is created with the very `NSTextContainer` that `RCTTextLayoutManager` | ||
| * measured the paragraph with, so its layout matches the measurement by | ||
| * construction rather than by coincidence. UIKit performs the selection; it | ||
| * never performs the layout, and it never paints the text. | ||
| */ | ||
| @interface RCTSelectableTextView : UITextView <UITextViewDelegate> | ||
|
|
||
| /* | ||
| * The paragraph as it is painted, before `RCTUnpaintedAttributedString` strips | ||
| * it. The text view lays the stripped copy out, so `copy:` must read the range | ||
| * from this string instead, or the pasteboard receives clear text with no | ||
| * decorations. Both strings hold the same characters, so the range maps | ||
| * directly from one to the other. | ||
| */ | ||
| @property (nonatomic, copy, nullable) NSAttributedString *sourceAttributedText; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
|
|
||
| #endif // !TARGET_OS_TV |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
pointerUpandpointerCancel, but the selection only resets the touch handler. If the selection becomes non-empty afterpointerDown, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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