Skip to content

Commit 856cfaa

Browse files
committed
fix(iOS): properly modify frame for line height centering
- Rename calculateCenteredFrameWithAttributedText to adjustFrameForLineHeightCentering - Change method to accept CGRect pointer instead of passing by value - Properly modify frame using pointer dereferencing (frame->origin.y)
1 parent c7407af commit 856cfaa

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
374374
return nil;
375375
}
376376

377-
- (CGRect)calculateCenteredFrameWithAttributedText:(NSAttributedString *)attributedText
378-
frame:(CGRect)frame {
377+
- (void)adjustFrameForLineHeightCentering:(NSAttributedString *)attributedText
378+
frame:(CGRect *)frame {
379379
if (!attributedText || attributedText.length == 0) {
380-
return frame;
380+
return;
381381
}
382382

383383
UIFont *font = [attributedText attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
@@ -388,7 +388,7 @@ - (CGRect)calculateCenteredFrameWithAttributedText:(NSAttributedString *)attribu
388388
NSParagraphStyle *paragraphStyle = [attributedText attribute:NSParagraphStyleAttributeName atIndex:0 effectiveRange:NULL];
389389

390390
if (!paragraphStyle || paragraphStyle.minimumLineHeight == 0) {
391-
return frame;
391+
return;
392392
}
393393

394394
CGFloat lineHeight = paragraphStyle.minimumLineHeight;
@@ -400,9 +400,7 @@ - (CGRect)calculateCenteredFrameWithAttributedText:(NSAttributedString *)attribu
400400
CGFloat difference = MAX(0, textHeight - lineHeight);
401401
CGFloat verticalOffset = difference / 2.0;
402402

403-
frame.origin.y += verticalOffset;
404-
405-
return frame;
403+
frame->origin.y += verticalOffset;
406404
}
407405

408406
- (void)drawRect:(CGRect)rect
@@ -424,7 +422,7 @@ - (void)drawRect:(CGRect)rect
424422

425423
if (ReactNativeFeatureFlags::enableLineHeightCenteringOnIOS()) {
426424
NSAttributedString *attributedText = RCTNSAttributedStringFromAttributedString(_state->getData().attributedString);
427-
frame = [self calculateCenteredFrameWithAttributedText:attributedText frame:frame];
425+
[self adjustFrameForLineHeightCentering:attributedText frame:&frame];
428426
}
429427

430428
[nativeTextLayoutManager drawAttributedString:stateData.attributedString

0 commit comments

Comments
 (0)