forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathRCTParagraphComponentView.mm
More file actions
678 lines (555 loc) · 21.6 KB
/
RCTParagraphComponentView.mm
File metadata and controls
678 lines (555 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/*
* 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 "RCTParagraphComponentView.h"
#import "RCTParagraphComponentAccessibilityProvider.h"
#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/UTCoreTypes.h>
#endif // [macOS]
#if TARGET_OS_OSX // [macOS
#import <QuartzCore/CAShapeLayer.h>
#import <React/RCTTouchHandler.h>
#endif // macOS]
#import <React/RCTViewAccessibilityElement.h>
#import <react/renderer/components/text/ParagraphComponentDescriptor.h>
#import <react/renderer/components/text/ParagraphProps.h>
#import <react/renderer/components/text/ParagraphState.h>
#import <react/renderer/components/text/RawTextComponentDescriptor.h>
#import <react/renderer/components/text/TextComponentDescriptor.h>
#import <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
#import <react/renderer/textlayoutmanager/RCTTextLayoutManager.h>
#import <react/renderer/textlayoutmanager/TextLayoutManager.h>
#import <react/utils/ManagedObjectWrapper.h>
#import "RCTConversions.h"
#import "RCTFabricComponentsPlugins.h"
using namespace facebook::react;
// 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]
@property (nonatomic) ParagraphShadowNode::ConcreteState::Shared state;
@property (nonatomic) ParagraphAttributes paragraphAttributes;
@property (nonatomic) LayoutMetrics layoutMetrics;
#if TARGET_OS_OSX // [macOS
@property (nonatomic) BOOL drawingDisabled;
#endif // macOS]
@end
#if TARGET_OS_OSX // [macOS
// Prevent this NSTextView from participating in the key view loop directly.
// The parent RCTParagraphComponentView manages focus instead.
@interface RCTParagraphSelectionTextView : NSTextView
@end
@implementation RCTParagraphSelectionTextView
- (BOOL)canBecomeKeyView
{
return NO;
}
@end
#endif // macOS]
#if !TARGET_OS_OSX // [macOS]
@interface RCTParagraphComponentView () <UIEditMenuInteractionDelegate>
@property (nonatomic, nullable) UIEditMenuInteraction *editMenuInteraction API_AVAILABLE(ios(16.0));
@end
#else // [macOS
@interface RCTParagraphComponentView () <NSTextViewDelegate>
@end
#endif // [macOS]
@implementation RCTParagraphComponentView {
ParagraphAttributes _paragraphAttributes;
RCTParagraphComponentAccessibilityProvider *_accessibilityProvider;
#if !TARGET_OS_OSX // [macOS]
UILongPressGestureRecognizer *_longPressGestureRecognizer;
#else // [macOS
NSTextView *_selectableTextView;
#endif // macOS]
RCTParagraphTextView *_textView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
_props = ParagraphShadowNode::defaultSharedProps();
#if !TARGET_OS_OSX // [macOS]
self.opaque = NO;
#endif // [macOS]
_textView = [RCTParagraphTextView new];
_textView.backgroundColor = RCTUIColor.clearColor; // [macOS]
self.contentView = _textView;
}
return self;
}
- (NSString *)description
{
NSString *superDescription = [super description];
// Cutting the last `>` character.
if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') {
superDescription = [superDescription substringToIndex:superDescription.length - 1];
}
return [NSString stringWithFormat:@"%@; attributedText = %@>", superDescription, self.attributedText];
}
- (NSAttributedString *_Nullable)attributedText
{
if (!_textView.state) {
return nil;
}
return RCTNSAttributedStringFromAttributedString(_textView.state->getData().attributedString);
}
#pragma mark - RCTComponentViewProtocol
+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<ParagraphComponentDescriptor>();
}
+ (std::vector<facebook::react::ComponentDescriptorProvider>)supplementalComponentDescriptorProviders
{
return {
concreteComponentDescriptorProvider<RawTextComponentDescriptor>(),
concreteComponentDescriptorProvider<TextComponentDescriptor>()};
}
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
{
const auto &oldParagraphProps = static_cast<const ParagraphProps &>(*_props);
const auto &newParagraphProps = static_cast<const ParagraphProps &>(*props);
_paragraphAttributes = newParagraphProps.paragraphAttributes;
_textView.paragraphAttributes = _paragraphAttributes;
if (newParagraphProps.isSelectable != oldParagraphProps.isSelectable) {
#if !TARGET_OS_OSX // [macOS]
if (newParagraphProps.isSelectable) {
[self enableContextMenu];
} else {
[self disableContextMenu];
}
#else // [macOS
if (newParagraphProps.isSelectable) {
[self _enableSelection];
} else {
[self _disableSelection];
}
#endif // macOS]
}
[super updateProps:props oldProps:oldProps];
}
- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
{
_textView.state = std::static_pointer_cast<const ParagraphShadowNode::ConcreteState>(state);
[_textView setNeedsDisplay];
[self setNeedsLayout];
#if TARGET_OS_OSX // [macOS
[self _updateSelectableTextViewIfNeeded];
#endif // macOS]
}
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
{
// Using stored `_layoutMetrics` as `oldLayoutMetrics` here to avoid
// re-applying individual sub-values which weren't changed.
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:_layoutMetrics];
_textView.layoutMetrics = _layoutMetrics;
[_textView setNeedsDisplay];
[self setNeedsLayout];
}
- (void)prepareForRecycle
{
[super prepareForRecycle];
_textView.state = nullptr;
_accessibilityProvider = nil;
#if TARGET_OS_OSX // [macOS
[self _disableSelection];
#endif // macOS]
}
- (void)layoutSubviews
{
[super layoutSubviews];
_textView.frame = self.bounds;
#if TARGET_OS_OSX // [macOS
if (_selectableTextView) {
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
_selectableTextView.frame = frame;
}
#endif // macOS]
}
#pragma mark - Accessibility
- (NSString *)accessibilityLabel
{
NSString *label = super.accessibilityLabel;
if ([label length] > 0) {
return label;
}
return self.attributedText.string;
}
- (NSString *)accessibilityLabelForCoopting
{
return self.accessibilityLabel;
}
- (BOOL)isAccessibilityElement
{
// All accessibility functionality of the component is implemented in `accessibilityElements` method below.
// Hence to avoid calling all other methods from `UIAccessibilityContainer` protocol (most of them have default
// implementations), we return here `NO`.
return NO;
}
#if !TARGET_OS_OSX // [macOS
- (NSArray *)accessibilityElements
{
const auto ¶graphProps = static_cast<const ParagraphProps &>(*_props);
// If the component is not `accessible`, we return an empty array.
// We do this because logically all nested <Text> components represent the content of the <Paragraph> component;
// in other words, all nested <Text> components individually have no sense without the <Paragraph>.
if (!_textView.state || !paragraphProps.accessible) {
return [NSArray new];
}
auto &data = _textView.state->getData();
if (![_accessibilityProvider isUpToDate:data.attributedString]) {
auto textLayoutManager = data.layoutManager.lock();
if (textLayoutManager) {
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
_accessibilityProvider =
[[RCTParagraphComponentAccessibilityProvider alloc] initWithString:data.attributedString
layoutManager:nativeTextLayoutManager
paragraphAttributes:data.paragraphAttributes
frame:frame
view:self];
}
}
NSArray<UIAccessibilityElement *> *elements = _accessibilityProvider.accessibilityElements;
if ([elements count] > 0) {
elements[0].isAccessibilityElement =
elements[0].accessibilityTraits & UIAccessibilityTraitLink || ![self isAccessibilityCoopted];
}
return elements;
}
- (BOOL)isAccessibilityCoopted
{
UIView *ancestor = self.superview;
NSMutableSet<UIView *> *cooptingCandidates = [NSMutableSet new];
while (ancestor) {
if ([ancestor isKindOfClass:[RCTViewComponentView class]]) {
if ([((RCTViewComponentView *)ancestor) accessibilityLabelForCoopting]) {
// We found a label above us. That would be coopted before we would be
return NO;
} else if ([((RCTViewComponentView *)ancestor) wantsToCooptLabel]) {
// We found an view that is looking to coopt a label below it
[cooptingCandidates addObject:ancestor];
}
NSArray *elements = ancestor.accessibilityElements;
if ([elements count] > 0 && [cooptingCandidates count] > 0) {
for (NSObject *element in elements) {
if ([element isKindOfClass:[UIView class]] && [cooptingCandidates containsObject:((UIView *)element)]) {
return YES;
} else if (
[element isKindOfClass:[RCTViewAccessibilityElement class]] &&
[cooptingCandidates containsObject:((RCTViewAccessibilityElement *)element).view]) {
return YES;
}
}
}
} else if (![ancestor isKindOfClass:[RCTViewComponentView class]] && ancestor.accessibilityLabel) {
// Same as above, for UIView case. Cannot call this on RCTViewComponentView
// as it is recursive and quite expensive.
return NO;
}
ancestor = ancestor.superview;
}
return NO;
}
- (UIAccessibilityTraits)accessibilityTraits
{
return [super accessibilityTraits] | UIAccessibilityTraitStaticText;
}
#else // [macOS
- (NSAccessibilityRole)accessibilityRole
{
return [super accessibilityRole] ?: NSAccessibilityStaticTextRole;
}
#endif // macOS]
#pragma mark - RCTTouchableComponentViewProtocol
- (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
{
const auto &state = _textView.state;
if (!state) {
return _eventEmitter;
}
const auto &stateData = state->getData();
auto textLayoutManager = stateData.layoutManager.lock();
if (!textLayoutManager) {
return _eventEmitter;
}
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
auto eventEmitter = [nativeTextLayoutManager getEventEmitterWithAttributeString:stateData.attributedString
paragraphAttributes:_paragraphAttributes
frame:frame
atPoint:point];
if (!eventEmitter) {
return _eventEmitter;
}
assert(std::dynamic_pointer_cast<const TouchEventEmitter>(eventEmitter));
return std::static_pointer_cast<const TouchEventEmitter>(eventEmitter);
}
#pragma mark - Context Menu
#if !TARGET_OS_OSX // [macOS]
- (void)enableContextMenu
{
_longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPress:)];
if (@available(iOS 16.0, *)) {
_editMenuInteraction = [[UIEditMenuInteraction alloc] initWithDelegate:self];
[self addInteraction:_editMenuInteraction];
}
[self addGestureRecognizer:_longPressGestureRecognizer];
}
- (void)disableContextMenu
{
[self removeGestureRecognizer:_longPressGestureRecognizer];
if (@available(iOS 16.0, *)) {
[self removeInteraction:_editMenuInteraction];
_editMenuInteraction = nil;
}
_longPressGestureRecognizer = nil;
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
{
if (@available(iOS 16.0, macCatalyst 16.0, *)) {
CGPoint location = [gesture locationInView:self];
UIEditMenuConfiguration *config = [UIEditMenuConfiguration configurationWithIdentifier:nil sourcePoint:location];
if (_editMenuInteraction) {
[_editMenuInteraction presentEditMenuWithConfiguration:config];
}
} else {
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController.isMenuVisible) {
return;
}
[menuController showMenuFromView:self rect:self.bounds];
}
}
#endif // [macOS]
- (BOOL)canBecomeFirstResponder
{
const auto ¶graphProps = static_cast<const ParagraphProps &>(*_props);
return paragraphProps.isSelectable;
}
#if !TARGET_OS_OSX // [macOS]
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
const auto ¶graphProps = static_cast<const ParagraphProps &>(*_props);
if (paragraphProps.isSelectable && action == @selector(copy:)) {
return YES;
}
return [self.nextResponder canPerformAction:action withSender:sender];
}
#endif // [macOS]
- (void)copy:(id)sender
{
NSAttributedString *attributedText = self.attributedText;
NSMutableDictionary *item = [NSMutableDictionary new];
NSData *rtf = [attributedText dataFromRange:NSMakeRange(0, attributedText.length)
documentAttributes:@{NSDocumentTypeDocumentAttribute : NSRTFDTextDocumentType}
error:nil];
if (rtf) {
[item setObject:rtf forKey:(id)kUTTypeFlatRTFD];
}
[item setObject:attributedText.string forKey:(id)kUTTypeUTF8PlainText];
#if !TARGET_OS_OSX // [macOS]
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.items = @[ item ];
#else // [macOS
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard setData:rtf forType:NSPasteboardTypeRTFD];
#endif // macOS]
}
#pragma mark - macOS Selection Support
#if TARGET_OS_OSX // [macOS
- (void)_enableSelection
{
if (_selectableTextView) {
return;
}
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
_selectableTextView = [[RCTParagraphSelectionTextView alloc] initWithFrame:frame];
_selectableTextView.delegate = self;
_selectableTextView.usesFontPanel = NO;
_selectableTextView.drawsBackground = NO;
_selectableTextView.editable = NO;
_selectableTextView.selectable = YES;
_selectableTextView.verticallyResizable = NO;
_selectableTextView.layoutManager.usesFontLeading = NO;
// Disable the NSTextView's own drawing — RCTParagraphTextView handles rendering.
// The NSTextView is only used for selection and cursor management.
_selectableTextView.textContainerInset = NSZeroSize;
_selectableTextView.textContainer.lineFragmentPadding = 0.0;
[self addSubview:_selectableTextView];
[self _updateSelectableTextViewIfNeeded];
self.focusable = YES;
}
- (void)_disableSelection
{
if (!_selectableTextView) {
return;
}
[_selectableTextView removeFromSuperview];
_selectableTextView = nil;
_textView.drawingDisabled = NO;
[_textView setNeedsDisplay];
}
- (void)_updateSelectableTextViewIfNeeded
{
if (!_selectableTextView || !_textView.state) {
return;
}
const auto &stateData = _textView.state->getData();
auto textLayoutManager = stateData.layoutManager.lock();
if (!textLayoutManager) {
return;
}
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
NSTextStorage *textStorage = [nativeTextLayoutManager getTextStorageForAttributedString:stateData.attributedString
paragraphAttributes:_paragraphAttributes
size:frame.size];
// Replace the text container so the NSTextView uses the same layout as our rendering.
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
[_selectableTextView replaceTextContainer:textContainer];
// Sync the text content into the NSTextView's own text storage.
_selectableTextView.textStorage.attributedString = textStorage;
_selectableTextView.minSize = frame.size;
_selectableTextView.maxSize = frame.size;
_selectableTextView.frame = frame;
// Now that the NSTextView handles rendering, disable RCTParagraphTextView drawing.
_textView.drawingDisabled = YES;
[_textView setNeedsDisplay];
}
#pragma mark - macOS Mouse Event Handling
- (NSView *)hitTest:(NSPoint)point
{
NSView *hitView = [super hitTest:point];
if (!_selectableTextView) {
return hitView;
}
// Intercept clicks on the NSTextView so we can manage selection ourselves,
// preventing it from swallowing events that may be handled in JS (e.g. onPress).
NSEventType eventType = NSApp.currentEvent.type;
BOOL isMouseClickEvent = NSEvent.pressedMouseButtons > 0;
BOOL isMouseMoveEventType = eventType == NSEventTypeMouseMoved ||
eventType == NSEventTypeMouseEntered ||
eventType == NSEventTypeMouseExited ||
eventType == NSEventTypeCursorUpdate;
BOOL isMouseMoveEvent = !isMouseClickEvent && isMouseMoveEventType;
BOOL isTextViewClick = (hitView && hitView == _selectableTextView) && !isMouseMoveEvent;
return isTextViewClick ? self : hitView;
}
- (void)rightMouseDown:(NSEvent *)event
{
if (!_selectableTextView) {
[super rightMouseDown:event];
return;
}
[[RCTTouchHandler touchHandlerForView:self] cancelTouchWithEvent:event];
[_selectableTextView rightMouseDown:event];
}
- (void)mouseDown:(NSEvent *)event
{
if (!_selectableTextView) {
[super mouseDown:event];
return;
}
// Double/triple-clicks should be forwarded to the NSTextView for word/line selection.
BOOL shouldForward = event.clickCount > 1;
if (!shouldForward) {
// Peek at next event to know if a drag (selection) is beginning.
NSEvent *nextEvent = [self.window nextEventMatchingMask:NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged
untilDate:[NSDate distantFuture]
inMode:NSEventTrackingRunLoopMode
dequeue:NO];
shouldForward = nextEvent.type == NSEventTypeLeftMouseDragged;
}
if (shouldForward) {
NSView *contentView = self.window.contentView;
NSPoint point = [contentView.superview convertPoint:event.locationInWindow fromView:nil];
if ([contentView hitTest:point] == self) {
[[RCTTouchHandler touchHandlerForView:self] cancelTouchWithEvent:event];
[self.window makeFirstResponder:_selectableTextView];
[_selectableTextView mouseDown:event];
}
} else {
// Clear selection for single clicks.
_selectableTextView.selectedRange = NSMakeRange(NSNotFound, 0);
}
}
#pragma mark - NSTextViewDelegate
- (void)textDidEndEditing:(NSNotification *)notification
{
_selectableTextView.selectedRange = NSMakeRange(NSNotFound, 0);
}
#pragma mark - macOS Responder Chain
- (BOOL)acceptsFirstResponder
{
const auto ¶graphProps = static_cast<const ParagraphProps &>(*_props);
return paragraphProps.isSelectable || [super acceptsFirstResponder];
}
- (BOOL)resignFirstResponder
{
// Don't relinquish first responder while selecting text.
if (_selectableTextView && NSRunLoop.currentRunLoop.currentMode == NSEventTrackingRunLoopMode) {
return NO;
}
return [super resignFirstResponder];
}
#endif // macOS]
@end
Class<RCTComponentViewProtocol> RCTParagraphCls(void)
{
return RCTParagraphComponentView.class;
}
@implementation RCTParagraphTextView {
CAShapeLayer *_highlightLayer;
}
- (RCTUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
return nil;
}
- (void)drawRect:(CGRect)rect
{
if (!_state) {
return;
}
#if TARGET_OS_OSX // [macOS
// When an NSTextView is handling rendering for selection support,
// skip drawing here to avoid double-rendering.
if (_drawingDisabled) {
return;
}
#endif // macOS]
const auto &stateData = _state->getData();
auto textLayoutManager = stateData.layoutManager.lock();
if (!textLayoutManager) {
return;
}
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
[nativeTextLayoutManager drawAttributedString:stateData.attributedString
paragraphAttributes:_paragraphAttributes
frame:frame
drawHighlightPath:^(UIBezierPath *highlightPath) {
if (highlightPath) {
if (!self->_highlightLayer) {
self->_highlightLayer = [CAShapeLayer layer];
self->_highlightLayer.fillColor = [RCTUIColor colorWithWhite:0 alpha:0.25].CGColor; // [macOS]
[self.layer addSublayer:self->_highlightLayer];
}
self->_highlightLayer.position = frame.origin;
self->_highlightLayer.path = highlightPath.CGPath;
} else {
[self->_highlightLayer removeFromSuperlayer];
self->_highlightLayer = nil;
}
}];
}
@end