Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@

using namespace facebook::react;

#if !TARGET_OS_OSX // [macOS]

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, newarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, oldarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, newarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, hermes

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, oldarch, jsc

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, hermes

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, newarch, hermes

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, oldarch, hermes

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, newarch, hermes

unterminated conditional directive

Check failure on line 32 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, oldarch, hermes

unterminated conditional directive
// ParagraphTextView is an auxiliary view we set as contentView so the drawing
// can happen on top of the layers manipulated by RCTViewComponentView (the parent view)
@interface RCTParagraphTextView : RCTUIView // [macOS]
#else // [macOS
// On macOS, we also defer drawing to an NSTextView,
// in order to get more native behaviors like text selection.
@interface RCTParagraphTextView : NSTextView // [macOS]
#endif // macOS]

@property (nonatomic) ParagraphShadowNode::ConcreteState::Shared state;
@property (nonatomic) ParagraphAttributes paragraphAttributes;
@property (nonatomic) LayoutMetrics layoutMetrics;

#if TARGET_OS_OSX // [macOS]
/// UIKit compatibility shim that simply calls `[self setNeedsDisplay:YES]`
- (void)setNeedsDisplay;
#endif

@end
#else // [macOS
#if TARGET_OS_OSX // [macOS
// On macOS, we defer drawing to an NSTextView rather than a plan NSView, in order
// to get more native behaviors like text selection. We make sure this NSTextView
// does not take focus.
@interface RCTParagraphComponentUnfocusableTextView : NSTextView
@end
#endif // macOS]

#if !TARGET_OS_OSX // [macOS]
@interface RCTParagraphComponentView () <UIEditMenuInteractionDelegate>
Expand All @@ -64,8 +62,10 @@
RCTParagraphComponentAccessibilityProvider *_accessibilityProvider;
#if !TARGET_OS_OSX // [macOS]
UILongPressGestureRecognizer *_longPressGestureRecognizer;
#endif // macOS]
RCTParagraphTextView *_textView;
#else // [macOS
RCTParagraphComponentUnfocusableTextView *_textView;
#endif // macOS]
}

- (instancetype)initWithFrame:(CGRect)frame
Expand All @@ -77,14 +77,15 @@
self.opaque = NO;
_textView = [RCTParagraphTextView new];
_textView.backgroundColor = RCTUIColor.clearColor; // [macOS]
self.contentView = _textView;
#else // [macOS
// Make the RCTParagraphComponentView accessible and available in the a11y hierarchy.
self.accessibilityElement = YES;
self.accessibilityRole = NSAccessibilityStaticTextRole;
// Fix blurry text on non-retina displays.
self.canDrawSubviewsIntoLayer = YES;
// The NSTextView is responsible for drawing text and managing selection.
_textView = [[RCTParagraphTextView alloc] initWithFrame:self.bounds];
_textView = [[RCTParagraphComponentUnfocusableTextView alloc] initWithFrame:self.bounds];
// The RCTParagraphComponentUnfocusableTextView is only used for rendering and should not appear in the a11y hierarchy.
_textView.accessibilityElement = NO;
_textView.usesFontPanel = NO;
Expand All @@ -97,7 +98,6 @@
self.contentView = _textView;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
#endif // macOS]
self.contentView = _textView;
}

return self;
Expand Down Expand Up @@ -144,7 +144,7 @@
const auto &newParagraphProps = static_cast<const ParagraphProps &>(*props);

_paragraphAttributes = newParagraphProps.paragraphAttributes;
_textView.paragraphAttributes = _paragraphAttributes;

Check failure on line 147 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, jsc

property 'paragraphAttributes' not found on object of type 'RCTParagraphComponentUnfocusableTextView *'

Check failure on line 147 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, jsc

property 'paragraphAttributes' not found on object of type 'RCTParagraphComponentUnfocusableTextView *'

Check failure on line 147 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, hermes

property 'paragraphAttributes' not found on object of type 'RCTParagraphComponentUnfocusableTextView *'

Check failure on line 147 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, hermes

property 'paragraphAttributes' not found on object of type 'RCTParagraphComponentUnfocusableTextView *'

if (newParagraphProps.isSelectable != oldParagraphProps.isSelectable) {
#if !TARGET_OS_OSX // [macOS]
Expand All @@ -164,9 +164,12 @@
- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
_state = std::static_pointer_cast<const ParagraphShadowNode::ConcreteState>(state);
#if !TARGET_OS_OSX // [macOS]
_textView.state = _state;
[_textView setNeedsDisplay];
[self setNeedsLayout];
[self _updateTextView];
#endif // macOS]
}

- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
Expand All @@ -175,11 +178,54 @@
// Using stored `_layoutMetrics` as `oldLayoutMetrics` here to avoid
// re-applying individual sub-values which weren't changed.
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:_layoutMetrics];
#if !TARGET_OS_OSX // [macOS]
_textView.layoutMetrics = _layoutMetrics;
[_textView setNeedsDisplay];
[self setNeedsLayout];
#else // [macOS
[self _updateTextView];
#endif // macOS]
}

#if TARGET_OS_OSX // [macOS
- (void)_updateTextView
{
if (!_state) {
return;
}

auto textLayoutManager = _state->getData().paragraphLayoutManager.getTextLayoutManager();

Check failure on line 197 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, jsc

no member named 'paragraphLayoutManager' in 'facebook::react::ParagraphState'

Check failure on line 197 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, jsc

no member named 'paragraphLayoutManager' in 'facebook::react::ParagraphState'

Check failure on line 197 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, hermes

no member named 'paragraphLayoutManager' in 'facebook::react::ParagraphState'

Check failure on line 197 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, hermes

no member named 'paragraphLayoutManager' in 'facebook::react::ParagraphState'

if (!textLayoutManager) {
return;
}

RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());

CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());

NSTextStorage *textStorage = [nativeTextLayoutManager getTextStorageForAttributedString:_state->getData().attributedString paragraphAttributes:_paragraphAttributes frame:frame];

Check failure on line 208 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, jsc

no visible @interface for 'RCTTextLayoutManager' declares the selector 'getTextStorageForAttributedString:paragraphAttributes:frame:'

Check failure on line 208 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, jsc

no visible @interface for 'RCTTextLayoutManager' declares the selector 'getTextStorageForAttributedString:paragraphAttributes:frame:'

Check failure on line 208 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, hermes

no visible @interface for 'RCTTextLayoutManager' declares the selector 'getTextStorageForAttributedString:paragraphAttributes:frame:'

Check failure on line 208 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, hermes

no visible @interface for 'RCTTextLayoutManager' declares the selector 'getTextStorageForAttributedString:paragraphAttributes:frame:'

NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

[_textView replaceTextContainer:textContainer];

NSArray<NSLayoutManager *> *managers = [[textStorage layoutManagers] copy];
for (NSLayoutManager *manager in managers) {
[textStorage removeLayoutManager:manager];
}

_textView.minSize = frame.size;
_textView.maxSize = frame.size;
_textView.frame = frame;
_textView.textStorage.attributedString = textStorage;

[self setNeedsDisplay];
}
#endif // macOS]

- (void)prepareForRecycle
{
[super prepareForRecycle];
Expand Down Expand Up @@ -381,10 +427,9 @@
return RCTParagraphComponentView.class;
}

@implementation RCTParagraphTextView {
#if !TARGET_OS_OSX // [macOS]

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, newarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, oldarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, newarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, oldarch, hermes

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, oldarch, jsc

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / macos, newarch, hermes

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, newarch, hermes

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / ios, oldarch, hermes

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, newarch, hermes

unterminated conditional directive

Check failure on line 430 in packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

View workflow job for this annotation

GitHub Actions / Build RNTester / visionos, oldarch, hermes

unterminated conditional directive
@implementation RCTParagraphTextView {
CAShapeLayer *_highlightLayer;
#endif // macOS]
}

- (RCTUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS]
Expand All @@ -409,7 +454,6 @@

CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());

#if !TARGET_OS_OSX // [macOS]
[nativeTextLayoutManager drawAttributedString:_state->getData().attributedString
paragraphAttributes:_paragraphAttributes
frame:frame
Expand All @@ -427,33 +471,12 @@
self->_highlightLayer = nil;
}
}];
#else // [macOS
NSTextStorage *textStorage = [nativeTextLayoutManager getTextStorageForAttributedString:_state->getData().attributedString paragraphAttributes:_paragraphAttributes size:frame.size];

NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

[self replaceTextContainer:textContainer];

NSArray<NSLayoutManager *> *managers = [[textStorage layoutManagers] copy];
for (NSLayoutManager *manager in managers) {
[textStorage removeLayoutManager:manager];
}

self.minSize = frame.size;
self.maxSize = frame.size;
self.frame = frame;
[[self textStorage] setAttributedString:textStorage];

[super drawRect:rect];
#endif
}

@end
#else // [macOS
#if TARGET_OS_OSX // [macOS
- (void)setNeedsDisplay
{
[self setNeedsDisplay:YES];
}
@implementation RCTParagraphComponentUnfocusableTextView

- (BOOL)canBecomeKeyView
{
Expand All @@ -469,6 +492,6 @@

return [super resignFirstResponder];
}
#endif // macOS]

@end
#endif // macOS]
Loading