|
9 | 9 | #import "ENRMSpoilerOverlayManager.h" |
10 | 10 | #import "ENRMSpoilerTapUtils.h" |
11 | 11 | #import "ENRMTailFadeInAnimator.h" |
12 | | -#import "ENRMUIKit.h" |
| 12 | +#import "ENRMTextViewSetup.h" |
13 | 13 | #import "EditMenuUtils.h" |
14 | 14 | #import "FontScaleObserver.h" |
15 | 15 | #import "FontUtils.h" |
16 | 16 | #import "HeightUpdateUtils.h" |
17 | | -#import "LastElementUtils.h" |
18 | 17 | #import "LinkTapUtils.h" |
19 | 18 | #import "MarkdownASTNode.h" |
20 | 19 | #import "MarkdownAccessibilityElementBuilder.h" |
21 | 20 | #import "MarkdownExtractor.h" |
22 | 21 | #import "ParagraphStyleUtils.h" |
23 | 22 | #import "RenderContext.h" |
24 | 23 | #import "RuntimeKeys.h" |
25 | | -#import "StyleConfig.h" |
26 | 24 | #import "StylePropsUtils.h" |
27 | 25 | #import "TaskListTapUtils.h" |
28 | | -#import "TextViewLayoutManager.h" |
29 | | -#import <React/RCTUtils.h> |
30 | | -#import <objc/runtime.h> |
31 | 26 |
|
32 | 27 | #import <ReactNativeEnrichedMarkdown/EnrichedMarkdownTextComponentDescriptor.h> |
33 | 28 | #import <ReactNativeEnrichedMarkdown/EventEmitters.h> |
@@ -98,35 +93,12 @@ + (ComponentDescriptorProvider)componentDescriptorProvider |
98 | 93 |
|
99 | 94 | - (CGSize)measureSize:(CGFloat)maxWidth |
100 | 95 | { |
101 | | - NSAttributedString *text = ENRMGetAttributedText(_textView); |
102 | | - CGFloat defaultHeight = UIFontLineHeight([UIFont systemFontOfSize:16.0]); |
103 | | - |
104 | | - if (text.length == 0) { |
| 96 | + CGSize size = ENRMMeasureMarkdownText(_textView, maxWidth, _config, _allowTrailingMargin, _lastElementMarginBottom); |
| 97 | + if (CGSizeEqualToSize(size, CGSizeZero)) { |
| 98 | + CGFloat defaultHeight = UIFontLineHeight([UIFont systemFontOfSize:16.0]); |
105 | 99 | return CGSizeMake(maxWidth, defaultHeight); |
106 | 100 | } |
107 | | - |
108 | | - ENRMTextLayoutResult layout = ENRMMeasureTextLayout(_textView, maxWidth); |
109 | | - |
110 | | - CGFloat measuredWidth = layout.usedRect.size.width; |
111 | | - CGFloat measuredHeight = layout.usedRect.size.height; |
112 | | - |
113 | | - if (!CGRectIsEmpty(layout.extraLineFragmentRect)) { |
114 | | - measuredHeight -= layout.extraLineFragmentRect.size.height; |
115 | | - } |
116 | | - |
117 | | - // Code block's bottom padding is a spacer \n with minimumLineHeight = codeBlockPadding. |
118 | | - // The layout manager may not size it accurately, so add the padding explicitly. |
119 | | - if (isLastElementCodeBlock(text)) { |
120 | | - measuredHeight += [_config codeBlockPadding]; |
121 | | - } |
122 | | - |
123 | | - if (_allowTrailingMargin && _lastElementMarginBottom > 0) { |
124 | | - measuredHeight += _lastElementMarginBottom; |
125 | | - } |
126 | | - |
127 | | - // Round to pixel boundaries to match React Native's <Text> measurement |
128 | | - CGFloat scale = RCTScreenScale(); |
129 | | - return CGSizeMake(ceil(measuredWidth * scale) / scale, ceil(measuredHeight * scale) / scale); |
| 101 | + return size; |
130 | 102 | } |
131 | 103 |
|
132 | 104 | - (BOOL)hasRenderedMarkdown:(NSString *)markdown |
@@ -250,28 +222,15 @@ - (void)didAddSubview:(RCTUIView *)subview |
250 | 222 |
|
251 | 223 | - (void)willRemoveSubview:(RCTUIView *)subview |
252 | 224 | { |
253 | | - if (subview == _textView && _textView.layoutManager != nil) { |
254 | | - NSLayoutManager *layoutManager = _textView.layoutManager; |
255 | | - if ([object_getClass(layoutManager) isEqual:[TextViewLayoutManager class]]) { |
256 | | - [layoutManager setValue:nil forKey:@"config"]; |
257 | | - object_setClass(layoutManager, [NSLayoutManager class]); |
258 | | - } |
| 225 | + if (subview == _textView) { |
| 226 | + ENRMDetachLayoutManager(_textView); |
259 | 227 | } |
260 | 228 | [super willRemoveSubview:subview]; |
261 | 229 | } |
262 | 230 |
|
263 | 231 | - (void)setupLayoutManager |
264 | 232 | { |
265 | | - // Custom layout manager handles drawing for code blocks, blockquotes, etc. |
266 | | - NSLayoutManager *layoutManager = _textView.layoutManager; |
267 | | - if (layoutManager != nil) { |
268 | | - layoutManager.allowsNonContiguousLayout = NO; // workaround for onScroll issue |
269 | | - object_setClass(layoutManager, [TextViewLayoutManager class]); |
270 | | - |
271 | | - if (_config != nil) { |
272 | | - [layoutManager setValue:_config forKey:@"config"]; |
273 | | - } |
274 | | - } |
| 233 | + ENRMAttachLayoutManager(_textView, _config); |
275 | 234 | } |
276 | 235 |
|
277 | 236 | - (void)renderMarkdownContent:(NSString *)markdownString |
|
0 commit comments