fix: support Text selectable prop on macOS with Fabric#2845
fix: support Text selectable prop on macOS with Fabric#2845kessenma wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…ure)
The `selectable` prop on `<Text>` was completely ignored on macOS when
using Fabric. The `isSelectable` handling in `updateProps` was gated
behind `#if !TARGET_OS_OSX`, so on macOS no selection support was enabled.
This adds macOS text selection support to `RCTParagraphComponentView` by
using an `NSTextView` overlay (similar to the old architecture's approach
in `RCTTextView.mm`). When `selectable={true}`:
- An `NSTextView` is created and added as a subview for selection handling
- The `NSTextView`'s text storage is synced from `RCTTextLayoutManager`
- `RCTParagraphTextView` skips its own drawing to avoid double-rendering
- Mouse events (click-drag, double/triple-click, right-click) are
forwarded to the `NSTextView` for native selection behavior
When `selectable={false}` (default), behavior is unchanged — no
`NSTextView` is created and rendering works exactly as before.
Fixes microsoft#2844
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
@microsoft-github-policy-service agree |
|
Curious, did you intend this to be a copy of #2673 ? Did you do any testing to make sure it works? |
|
I made this PR because I noticed I was not able to copy text in the latest version of the repo on my personal project and yes I did test. I put this in the PR description Tested in RNTester macOS app: |
Summary
Fixes #2844
The
selectableprop on<Text>was completely ignored on macOS when using Fabric (New Architecture). TheisSelectablehandling inRCTParagraphComponentView.updateProps:was gated behind#if !TARGET_OS_OSX, so on macOS no selection support was ever enabled.This adds macOS text selection support by using an
NSTextViewfor both rendering and selection (matching the pattern used by the old architecture inRCTTextView.mm):RCTParagraphTextViewskips itsdrawRect:and theNSTextViewhandles all text rendering via its ownNSLayoutManagerselectable={false}(default), noNSTextViewis created and behavior is completely unchangedNSTextViewis torn down inprepareForRecycleKey implementation details
RCTParagraphSelectionTextView(NSTextView subclass withcanBecomeKeyView = NO) prevents double-focusRCTTextLayoutManager.getTextStorageForAttributedString:(existing macOS-only API)hitTest:,mouseDown:,rightMouseDown:) ported from old arch'sRCTTextView.mmresignFirstResponderprevents losing focus during active selection trackingTest plan
#if TARGET_OS_OSXguarded)🤖 Generated with Claude Code