@@ -158,6 +158,8 @@ - (void)uiManagerWillPerformMounting
158
158
[attributedText insertAttributedString: propertyAttributedText atIndex: 0 ];
159
159
}
160
160
161
+ [self postprocessAttributedText: attributedText];
162
+
161
163
NSAttributedString *newAttributedText;
162
164
if (![_previousAttributedText isEqualToAttributedString: attributedText]) {
163
165
// We have to follow `set prop` pattern:
@@ -191,6 +193,52 @@ - (void)uiManagerWillPerformMounting
191
193
}];
192
194
}
193
195
196
+ - (void )postprocessAttributedText : (NSMutableAttributedString *)attributedText
197
+ {
198
+ __block CGFloat maximumLineHeight = 0 ;
199
+
200
+ [attributedText enumerateAttribute: NSParagraphStyleAttributeName
201
+ inRange: NSMakeRange (0 , attributedText.length)
202
+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
203
+ usingBlock: ^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
204
+ if (!paragraphStyle) {
205
+ return ;
206
+ }
207
+
208
+ maximumLineHeight = MAX (paragraphStyle.maximumLineHeight , maximumLineHeight);
209
+ }];
210
+
211
+ if (maximumLineHeight == 0 ) {
212
+ // `lineHeight` was not specified, nothing to do.
213
+ return ;
214
+ }
215
+
216
+ __block CGFloat maximumFontLineHeight = 0 ;
217
+
218
+ [attributedText enumerateAttribute: NSFontAttributeName
219
+ inRange: NSMakeRange (0 , attributedText.length)
220
+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
221
+ usingBlock: ^(UIFont *font, NSRange range, __unused BOOL *stop) {
222
+ if (!font) {
223
+ return ;
224
+ }
225
+
226
+ if (maximumFontLineHeight <= font.lineHeight ) {
227
+ maximumFontLineHeight = font.lineHeight ;
228
+ }
229
+ }];
230
+
231
+ if (maximumLineHeight < maximumFontLineHeight) {
232
+ return ;
233
+ }
234
+
235
+ CGFloat baseLineOffset = maximumLineHeight / 2.0 - maximumFontLineHeight / 2.0 ;
236
+
237
+ [attributedText addAttribute: NSBaselineOffsetAttributeName
238
+ value: @(baseLineOffset)
239
+ range: NSMakeRange (0 , attributedText.length)];
240
+ }
241
+
194
242
#pragma mark -
195
243
196
244
- (NSAttributedString *)measurableAttributedText
0 commit comments