mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
[react-native] Remove iOS-specific attributes from ART text
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
@interface RCTConvert (ART)
|
||||
|
||||
+ (CGPathRef)CGPath:(id)json;
|
||||
+ (CTFontRef)CTFont:(id)json;
|
||||
+ (CTTextAlignment)CTTextAlignment:(id)json;
|
||||
+ (ARTTextFrame)ARTTextFrame:(id)json;
|
||||
+ (ARTCGFloatArray)ARTCGFloatArray:(id)json;
|
||||
|
||||
@@ -64,18 +64,6 @@
|
||||
return (CGPathRef)CFAutorelease(path);
|
||||
}
|
||||
|
||||
+ (CTFontRef)CTFont:(id)json
|
||||
{
|
||||
NSDictionary *dict = [self NSDictionary:json];
|
||||
if (!dict) {
|
||||
return nil;
|
||||
}
|
||||
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)dict);
|
||||
CTFontRef font = CTFontCreateWithFontDescriptor(fontDescriptor, 0.0, NULL);
|
||||
CFRelease(fontDescriptor);
|
||||
return (CTFontRef)CFAutorelease(font);
|
||||
}
|
||||
|
||||
RCT_ENUM_CONVERTER(CTTextAlignment, (@{
|
||||
@"auto": @(kCTTextAlignmentNatural),
|
||||
@"left": @(kCTTextAlignmentLeft),
|
||||
@@ -98,7 +86,8 @@ RCT_ENUM_CONVERTER(CTTextAlignment, (@{
|
||||
return frame;
|
||||
}
|
||||
|
||||
CTFontRef font = [self CTFont:dict[@"font"]];
|
||||
NSDictionary *fontDict = dict[@"font"];
|
||||
CTFontRef font = (__bridge CTFontRef)[self UIFont:nil withFamily:fontDict[@"fontFamily"] size:fontDict[@"fontSize"] weight:fontDict[@"fontWeight"] style:fontDict[@"fontStyle"]];
|
||||
if (!font) {
|
||||
return frame;
|
||||
}
|
||||
|
||||
@@ -50,18 +50,11 @@ function fontAndLinesDiffer(a, b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var aTraits = a.font.NSCTFontTraitsAttribute;
|
||||
var bTraits = b.font.NSCTFontTraitsAttribute;
|
||||
|
||||
if (
|
||||
a.font.fontFamily !== b.font.fontFamily ||
|
||||
a.font.fontSize !== b.font.fontSize ||
|
||||
a.font.fontWeight !== b.font.fontWeight ||
|
||||
a.font.fontStyle !== b.font.fontStyle ||
|
||||
// TODO(6364240): remove iOS-specific attrs
|
||||
a.font.NSFontFamilyAttribute !== b.font.NSFontFamilyAttribute ||
|
||||
a.font.NSFontSizeAttribute !== b.font.NSFontSizeAttribute ||
|
||||
aTraits.NSCTFontSymbolicTrait !== bTraits.NSCTFontSymbolicTrait
|
||||
a.font.fontStyle !== b.font.fontStyle
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -418,14 +411,6 @@ var Shape = React.createClass({
|
||||
|
||||
var cachedFontObjectsFromString = {};
|
||||
|
||||
function extractFontTraits(isBold, isItalic) {
|
||||
var italic = isItalic ? 1 : 0;
|
||||
var bold = isBold ? 2 : 0;
|
||||
return {
|
||||
NSCTFontSymbolicTrait: italic | bold
|
||||
};
|
||||
}
|
||||
|
||||
var fontFamilyPrefix = /^[\s"']*/;
|
||||
var fontFamilySuffix = /[\s"']*$/;
|
||||
|
||||
@@ -456,10 +441,6 @@ function parseFontString(font) {
|
||||
fontSize: fontSize,
|
||||
fontWeight: isBold ? 'bold' : 'normal',
|
||||
fontStyle: isItalic ? 'italic' : 'normal',
|
||||
// TODO(6364240): remove iOS-specific attrs
|
||||
NSFontFamilyAttribute: fontFamily,
|
||||
NSFontSizeAttribute: fontSize,
|
||||
NSCTFontTraitsAttribute: extractFontTraits(isBold, isItalic)
|
||||
};
|
||||
return cachedFontObjectsFromString[font];
|
||||
}
|
||||
@@ -479,13 +460,6 @@ function extractFont(font) {
|
||||
fontSize: fontSize,
|
||||
fontWeight: font.fontWeight,
|
||||
fontStyle: font.fontStyle,
|
||||
// TODO(6364240): remove iOS-specific attrs
|
||||
NSFontFamilyAttribute: fontFamily,
|
||||
NSFontSizeAttribute: fontSize,
|
||||
NSCTFontTraitsAttribute: extractFontTraits(
|
||||
font.fontWeight === 'bold',
|
||||
font.fontStyle === 'italic'
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user