Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_UIFontTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)DISABLED_testWeight // task #7118691
- (void)testSize
{
{
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:18.5];
UIFont *expected = [UIFont systemFontOfSize:18.5];
UIFont *result = [RCTConvert UIFont:@{@"fontSize": @18.5}];
RCTAssertEqualFonts(expected, result);
}
Expand Down Expand Up @@ -69,12 +69,19 @@ - (void)testFamily
- (void)testStyle
{
{
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-Italic" size:14];
UIFont *font = [UIFont systemFontOfSize:14];
UIFontDescriptor *fontDescriptor = [font fontDescriptor];
UIFontDescriptorSymbolicTraits symbolicTraits =
fontDescriptor.symbolicTraits;
symbolicTraits |= UIFontDescriptorTraitItalic;
fontDescriptor =
[fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
UIFont *expected = [UIFont fontWithDescriptor:fontDescriptor size:14];
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"italic"}];
RCTAssertEqualFonts(expected, result);
}
{
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:14];
UIFont *expected = [UIFont systemFontOfSize:14];
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"normal"}];
RCTAssertEqualFonts(expected, result);
}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (BOOL)canBecomeFirstResponder

- (UIFont *)defaultPlaceholderFont
{
return [UIFont fontWithName:@"Helvetica" size:17];
return [UIFont systemFontOfSize:17];
}

- (UIColor *)defaultPlaceholderTextColor
Expand Down
54 changes: 53 additions & 1 deletion React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ + (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
size:(id)size weight:(id)weight style:(id)style
{
// Defaults
NSString *const RCTDefaultFontFamily = @"Helvetica Neue";
NSString *const RCTDefaultFontFamily = @"System";
const RCTFontWeight RCTDefaultFontWeight = UIFontWeightRegular;
const CGFloat RCTDefaultFontSize = 14;

Expand All @@ -757,7 +757,59 @@ + (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
BOOL isItalic = NO;
BOOL isCondensed = NO;

if ([[self NSString:family] isEqualToString:RCTDefaultFontFamily] ||
(!family && !font)) {
if (font) {
fontSize = font.pointSize ?: RCTDefaultFontSize;
fontWeight = RCTWeightOfFont(font);
isItalic = RCTFontIsItalic(font);
}

fontSize = [self CGFloat:size] ?: fontSize;

if (weight) {
fontWeight = [self RCTFontWeight:weight];
}

font = [UIFont systemFontOfSize:fontSize];

if (ABS(fontWeight - RCTDefaultFontWeight) < 0.01) {
UIFontDescriptor *fontDescriptor = [font fontDescriptor];
UIFontDescriptorSymbolicTraits symbolicTraits =
fontDescriptor.symbolicTraits;

if (style) {
isItalic = [self RCTFontStyle:style];
}
if (isItalic) {
symbolicTraits |= UIFontDescriptorTraitItalic;
fontDescriptor =
[fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
}
return [UIFont fontWithDescriptor:fontDescriptor size:fontSize];
}
}

if (font) {
if (!family && !weight) {
fontSize = font.pointSize ?: RCTDefaultFontSize;
fontSize = [self CGFloat:size] ?: fontSize;

UIFontDescriptor *fontDescriptor = [font fontDescriptor];
UIFontDescriptorSymbolicTraits symbolicTraits =
fontDescriptor.symbolicTraits;

if (style) {
isItalic = [self RCTFontStyle:style];
}
if (isItalic) {
symbolicTraits |= UIFontDescriptorTraitItalic;
fontDescriptor =
[fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
}
return [UIFont fontWithDescriptor:fontDescriptor size:fontSize];
}

familyName = font.familyName ?: RCTDefaultFontFamily;
fontSize = font.pointSize ?: RCTDefaultFontSize;
fontWeight = RCTWeightOfFont(font);
Expand Down