|
15 | 15 | #import "NSTextStorage+FontScaling.h"
|
16 | 16 | #import <React/RCTTextView.h>
|
17 | 17 |
|
| 18 | +// @Taskadev1 A custom layout manager to support gapless underlined text |
| 19 | +@interface CustomLayoutManager : NSLayoutManager { |
| 20 | +} |
| 21 | + - (void)drawUnderlineForRect:(CGRect)rect; |
| 22 | + - (void)drawUnderlineForGlyphRange:(NSRange)glyphRange |
| 23 | + underlineType:(NSUnderlineStyle)underlineVal |
| 24 | + baselineOffset:(CGFloat)baselineOffset |
| 25 | + lineFragmentRect:(CGRect)lineRect |
| 26 | + lineFragmentGlyphRange:(NSRange)lineGlyphRange |
| 27 | + containerOrigin:(CGPoint)containerOrigin; |
| 28 | +@end |
| 29 | + |
| 30 | +@implementation CustomLayoutManager |
| 31 | + |
| 32 | +- (void)drawUnderlineForRect:(CGRect)rect |
| 33 | +{ |
| 34 | + UIBezierPath *path = [UIBezierPath new]; |
| 35 | + path.lineWidth = 3.5; |
| 36 | + [path moveToPoint: CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect))]; |
| 37 | + [path addLineToPoint: CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect))]; |
| 38 | + [path stroke]; |
| 39 | +} |
| 40 | + |
| 41 | +- (void)drawUnderlineForGlyphRange:(NSRange)glyphRange |
| 42 | + underlineType:(NSUnderlineStyle)underlineVal |
| 43 | + baselineOffset:(CGFloat)baselineOffset |
| 44 | + lineFragmentRect:(CGRect)lineRect |
| 45 | + lineFragmentGlyphRange:(NSRange)lineGlyphRange |
| 46 | + containerOrigin:(CGPoint)containerOrigin |
| 47 | +{ |
| 48 | + NSTextContainer *textContainer = [self textContainerForGlyphAtIndex:glyphRange.location effectiveRange: nil]; |
| 49 | + CGRect boundingRect = [self boundingRectForGlyphRange:glyphRange inTextContainer:textContainer]; |
| 50 | + CGRect offsetRect = CGRectOffset(boundingRect, containerOrigin.x, containerOrigin.y ); |
| 51 | + UIColor *color = [self.textStorage attribute:NSUnderlineColorAttributeName atIndex:glyphRange.location effectiveRange: nil]; |
| 52 | + |
| 53 | + if (color) { |
| 54 | + [color setStroke]; |
| 55 | + } |
| 56 | + |
| 57 | + [self drawUnderlineForRect:offsetRect]; |
| 58 | +} |
| 59 | + |
| 60 | +@end |
| 61 | + |
18 | 62 | @implementation RCTTextShadowView
|
19 | 63 | {
|
20 | 64 | __weak RCTBridge *_bridge;
|
@@ -232,7 +276,7 @@ - (NSTextStorage *)textStorageAndLayoutManagerThatFitsSize:(CGSize)size
|
232 | 276 | _maximumNumberOfLines > 0 ? _lineBreakMode : NSLineBreakByClipping;
|
233 | 277 | textContainer.maximumNumberOfLines = _maximumNumberOfLines;
|
234 | 278 |
|
235 |
| - NSLayoutManager *layoutManager = [NSLayoutManager new]; |
| 279 | + CustomLayoutManager *layoutManager = [CustomLayoutManager new]; |
236 | 280 | layoutManager.usesFontLeading = NO;
|
237 | 281 | [layoutManager addTextContainer:textContainer];
|
238 | 282 |
|
|
0 commit comments