[tvOS] Fixes errors when building against tvOS SDK (#728)

* [tvOS] Fixes errors when building against tvOS SDK

* Update CHANGELOG.md

* [tvOS] Fixes implicit conversion between UIViewAnimationCurve +
UIViewAnimationOptions

* Enable tvOS deployment target in Texture.podspec (for CI)

* [ASMultiplexImageNode] Fixes typo

* [tvOS] Fixes warnings related to @available guards in Xcode 9
[ASMultiplexImageNode] Enables support for Photos framework on tvOS 10+

[ASMultiplexImageNode] Fixes comment depth

[ASAvailability] Adjust logic in AS_AVAILABLE_IOS_TVOS to account for
both versions
Adjusts API_AVAILABLE to minimum deployment target

* [ASAvailability] Update AS_AVAILABLE_XXX fallbacks to function more like
the built-in solution (more accurately target OS by checking target)
Change AS_AVAILABLE_IOS -> AS_AVAILABLE_IOS_TVOS in places that shoud
allow for both

[ASAvailability] Simplify AS_AVAILABLE_IOS_TVOS

* [ASControlNode] Adds missing 'super' call in -[ASControlNode didLoad]
when targeting tvOS

* Fix API_AVAILABLE iOS requirement

* [ASDisplayNode] Fixes last of the linker warnings related to category
overrides. Removes methods already implemented in
ASDisplayNode+UIViewBridge category.
[ASControlNode] Moves tvOS category declaration to ASControlNode header
[ASImageNode] Moves tvOS category declaration to ASImageNode header
[ASControlNode+Private] Adds private category for ASControlNode to
access private selectors

* [NSParagraphStyle+ASText] Fixes typo related to testing

* [ASControlNode] Re-add helpful comment

* [ASTextKitCoreTextAdditions] Adds mappings for kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierLineSpacingAdjustment when mapping CTParagraphStyle onto NSParagraphStyle
[ASTextNode] Uses CoreText-cleansed attributed string when assigning ascender/descender to avoid crash when a CTParagraphStyle is passed as an attribute

* [AsyncDisplayKit] Update project file to include new/deleted files

* [ASControlNode+tvOS] Add missing Foundation import (whoops!)
[ASImageNode+tvOS] Add missing Foundation import (whoops!)

* Update podspec to only link AssetsLibrary framework on iOS

* [ASTextKitCoreTextAdditions] If kCTParagraphStyleAttributeName key-value
evaluates to an NSParagraphStyle, pass through to cleansed attributes. This
fixes a bug that would occur if a CTParagraphStyle was passed as an
attribute _alone_ (would not be caught by unsupported attributes
check)

* [ASMultiplexImageNode] Bump availability check to support < Xcode 9

* [ASTraitCollection] Fixes typo that was causing build to fail

* Clean up formatting to adhere to character/line limit + braces
This commit is contained in:
Alex Hill
2018-03-11 16:37:27 -07:00
committed by Adlai Holler
parent e0d07d07ef
commit d9d9a29365
29 changed files with 244 additions and 180 deletions

View File

@@ -39,6 +39,7 @@ BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
kCTBaselineInfoAttributeName,
kCTBaselineReferenceInfoAttributeName,
kCTUnderlineColorAttributeName,
kCTParagraphStyleAttributeName,
nil];
});
return [coreTextAttributes containsObject:attributeName];
@@ -97,8 +98,13 @@ NSDictionary *NSAttributedStringAttributesForCoreTextAttributes(NSDictionary *co
cleanAttributes[NSForegroundColorAttributeName] = [UIColor colorWithCGColor:(CGColorRef)coreTextValue];
}
// kCTParagraphStyleAttributeName -> NSParagraphStyleAttributeName
else if ([coreTextKey isEqualToString:(NSString *)kCTParagraphStyleAttributeName] && ![coreTextValue isKindOfClass:[NSParagraphStyle class]]) {
cleanAttributes[NSParagraphStyleAttributeName] = [NSParagraphStyle paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)coreTextValue];
else if ([coreTextKey isEqualToString:(NSString *)kCTParagraphStyleAttributeName]) {
if ([coreTextValue isKindOfClass:[NSParagraphStyle class]]) {
cleanAttributes[NSParagraphStyleAttributeName] = (NSParagraphStyle *)coreTextValue;
}
else {
cleanAttributes[NSParagraphStyleAttributeName] = [NSParagraphStyle paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)coreTextValue];
}
}
// kCTStrokeWidthAttributeName -> NSStrokeWidthAttributeName
else if ([coreTextKey isEqualToString:(NSString *)kCTStrokeWidthAttributeName]) {
@@ -170,8 +176,9 @@ NSAttributedString *ASCleanseAttributedStringOfCoreTextAttributes(NSAttributedSt
{
NSMutableParagraphStyle *newParagraphStyle = [[NSMutableParagraphStyle alloc] init];
if (!coreTextParagraphStyle)
if (!coreTextParagraphStyle) {
return newParagraphStyle;
}
// The following paragraph style specifiers are not supported on NSParagraphStyle. Should they become available, we should add them.
/*
@@ -190,67 +197,145 @@ NSAttributedString *ASCleanseAttributedStringOfCoreTextAttributes(NSAttributedSt
// kCTParagraphStyleSpecifierAlignment -> alignment
CTTextAlignment coreTextAlignment;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierAlignment, sizeof(coreTextAlignment), &coreTextAlignment))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierAlignment,
sizeof(coreTextAlignment),
&coreTextAlignment)) {
newParagraphStyle.alignment = NSTextAlignmentFromCTTextAlignment(coreTextAlignment);
}
// kCTParagraphStyleSpecifierFirstLineHeadIndent -> firstLineHeadIndent
CGFloat firstLineHeadIndent;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(firstLineHeadIndent), &firstLineHeadIndent))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierFirstLineHeadIndent,
sizeof(firstLineHeadIndent),
&firstLineHeadIndent)) {
newParagraphStyle.firstLineHeadIndent = firstLineHeadIndent;
}
// kCTParagraphStyleSpecifierHeadIndent -> headIndent
CGFloat headIndent;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierHeadIndent, sizeof(headIndent), &headIndent))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierHeadIndent,
sizeof(headIndent),
&headIndent)) {
newParagraphStyle.headIndent = headIndent;
}
// kCTParagraphStyleSpecifierTailIndent -> tailIndent
CGFloat tailIndent;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierTailIndent, sizeof(tailIndent), &tailIndent))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierTailIndent,
sizeof(tailIndent),
&tailIndent)) {
newParagraphStyle.tailIndent = tailIndent;
}
// kCTParagraphStyleSpecifierLineBreakMode -> lineBreakMode
CTLineBreakMode coreTextLineBreakMode;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierLineBreakMode, sizeof(coreTextLineBreakMode), &coreTextLineBreakMode))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierLineBreakMode,
sizeof(coreTextLineBreakMode),
&coreTextLineBreakMode)) {
newParagraphStyle.lineBreakMode = (NSLineBreakMode)coreTextLineBreakMode; // They're the same enum.
}
// kCTParagraphStyleSpecifierLineHeightMultiple -> lineHeightMultiple
CGFloat lineHeightMultiple;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierLineHeightMultiple, sizeof(lineHeightMultiple), &lineHeightMultiple))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierLineHeightMultiple,
sizeof(lineHeightMultiple),
&lineHeightMultiple)) {
newParagraphStyle.lineHeightMultiple = lineHeightMultiple;
}
// kCTParagraphStyleSpecifierMaximumLineHeight -> maximumLineHeight
CGFloat maximumLineHeight;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(maximumLineHeight), &maximumLineHeight))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierMaximumLineHeight,
sizeof(maximumLineHeight),
&maximumLineHeight)) {
newParagraphStyle.maximumLineHeight = maximumLineHeight;
}
// kCTParagraphStyleSpecifierMinimumLineHeight -> minimumLineHeight
CGFloat minimumLineHeight;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(minimumLineHeight), &minimumLineHeight))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierMinimumLineHeight,
sizeof(minimumLineHeight),
&minimumLineHeight)) {
newParagraphStyle.minimumLineHeight = minimumLineHeight;
// kCTParagraphStyleSpecifierLineSpacing -> lineSpacing
// Note that kCTParagraphStyleSpecifierLineSpacing is deprecated and will die soon. We should not be using it.
}
CGFloat lineSpacing = 0;
#if TARGET_OS_IOS
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CGFloat lineSpacing;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing))
newParagraphStyle.lineSpacing = lineSpacing;
// kCTParagraphStyleSpecifierLineSpacing -> lineSpacing
// Note that kCTParagraphStyleSpecifierLineSpacing is deprecated and will die soon. We should not be using it.
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierLineSpacing,
sizeof(lineSpacing),
&lineSpacing)) {
newParagraphStyle.lineSpacing = lineSpacing;
}
#pragma clang diagnostic pop
#endif
// Attempt to weakly map the following onto -[NSParagraphStyle lineSpacing]:
// - kCTParagraphStyleSpecifierMinimumLineSpacing
// - kCTParagraphStyleSpecifierMaximumLineSpacing
// - kCTParagraphStyleSpecifierLineSpacingAdjustment
if (fabs(lineSpacing) <= FLT_EPSILON &&
CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierMinimumLineSpacing,
sizeof(lineSpacing),
&lineSpacing)) {
newParagraphStyle.lineSpacing = lineSpacing;
}
if (fabs(lineSpacing) <= FLT_EPSILON &&
CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierMaximumLineSpacing,
sizeof(lineSpacing),
&lineSpacing)) {
newParagraphStyle.lineSpacing = lineSpacing;
}
if (fabs(lineSpacing) <= FLT_EPSILON &&
CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierLineSpacingAdjustment,
sizeof(lineSpacing),
&lineSpacing)) {
newParagraphStyle.lineSpacing = lineSpacing;
}
// kCTParagraphStyleSpecifierParagraphSpacing -> paragraphSpacing
CGFloat paragraphSpacing;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierParagraphSpacing, sizeof(paragraphSpacing), &paragraphSpacing))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierParagraphSpacing,
sizeof(paragraphSpacing),
&paragraphSpacing)) {
newParagraphStyle.paragraphSpacing = paragraphSpacing;
}
// kCTParagraphStyleSpecifierParagraphSpacingBefore -> paragraphSpacingBefore
CGFloat paragraphSpacingBefore;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(paragraphSpacingBefore), &paragraphSpacingBefore))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierParagraphSpacingBefore,
sizeof(paragraphSpacingBefore),
&paragraphSpacingBefore)) {
newParagraphStyle.paragraphSpacingBefore = paragraphSpacingBefore;
}
// kCTParagraphStyleSpecifierBaseWritingDirection -> baseWritingDirection
CTWritingDirection coreTextBaseWritingDirection;
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle, kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(coreTextBaseWritingDirection), &coreTextBaseWritingDirection))
if (CTParagraphStyleGetValueForSpecifier(coreTextParagraphStyle,
kCTParagraphStyleSpecifierBaseWritingDirection,
sizeof(coreTextBaseWritingDirection),
&coreTextBaseWritingDirection)) {
newParagraphStyle.baseWritingDirection = (NSWritingDirection)coreTextBaseWritingDirection; // They're the same enum.
}
return newParagraphStyle;
}