Skip to content

Commit

Permalink
Vertically center iOS text if lineHeight is set
Browse files Browse the repository at this point in the history
Summary:
First PR!!

This fixes facebook#2991 :)
Closes facebook#7603

Differential Revision: D3417257

fbshipit-source-id: 074d56c1dfc0a9ba713e59c804286fd915589eeb
  • Loading branch information
tuckerconnelly authored and Facebook Github Bot 3 committed Jun 10, 2016
1 parent d43e0db commit 33dfc9d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
}
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;

// vertically center text
CGFloat fontSize = _fontSize && !isnan(_fontSize) ? _fontSize : UIFont.systemFontSize;
fontSize *= fontSizeMultiplier;

[attributedString addAttribute:NSBaselineOffsetAttributeName
value:@(lineHeight/2 - fontSize/2)
range:(NSRange){0, attributedString.length}];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:(NSRange){0, attributedString.length}];
Expand Down

0 comments on commit 33dfc9d

Please sign in to comment.