Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup from recent changes #1647

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions Source/ASDisplayNode+Subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,17 @@ AS_CATEGORY_IMPLEMENTABLE
* @discussion Subclasses can override this method to react to a trait collection change.
*/
AS_CATEGORY_IMPLEMENTABLE
- (void)asyncTraitCollectionDidChange ASDISPLAYNODE_REQUIRES_SUPER;
- (void)asyncTraitCollectionDidChange ASDISPLAYNODE_REQUIRES_SUPER ASDISPLAYNODE_DEPRECATED_MSG("Use asyncTraitCollectionDidChangeWithPreviousTraitCollection: instead.");


/**
* @abstract Called when the node's ASTraitCollection changes
*
* @discussion Subclasses can override this method to react to a trait collection change. Use `ASExperimentalTraitCollectionDidChangeWithPreviousCollection` to have this method called instead of `asyncTraitCollectionDidChange`.
* @discussion Subclasses can override this method to react to a trait collection change.
*
* @param previousTraitCollection The ASPrimitiveTraitCollection object before the interface environment changed.
*
* @note Enable `ASExperimentalTraitCollectionDidChangeWithPreviousCollection` experiment to have this method called instead of `asyncTraitCollectionDidChange`.
*/
AS_CATEGORY_IMPLEMENTABLE
- (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTraitCollection)previousTraitCollection ASDISPLAYNODE_REQUIRES_SUPER;
Expand Down
60 changes: 28 additions & 32 deletions Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ @interface ASImageNodeDrawParameters : NSObject {
ASDisplayNodeContextModifier _willDisplayNodeContentWithRenderingContext;
ASDisplayNodeContextModifier _didDisplayNodeContentWithRenderingContext;
ASImageNodeDrawParametersBlock _didDrawBlock;
#if AS_BUILD_UIUSERINTERFACESTYLE
UIUserInterfaceStyle userInterfaceStyle;
#endif
UIUserInterfaceStyle userInterfaceStyle API_AVAILABLE(tvos(10.0), ios(12.0));
}

@end
Expand All @@ -77,9 +75,7 @@ @interface ASImageNodeContentsKey : NSObject
@property (nonatomic) ASDisplayNodeContextModifier willDisplayNodeContentWithRenderingContext;
@property (nonatomic) ASDisplayNodeContextModifier didDisplayNodeContentWithRenderingContext;
@property (nonatomic) asimagenode_modification_block_t imageModificationBlock;
#if AS_BUILD_UIUSERINTERFACESTYLE
@property UIUserInterfaceStyle userInterfaceStyle API_AVAILABLE(tvos(10.0), ios(12.0));
#endif
@end

@implementation ASImageNodeContentsKey
Expand All @@ -96,18 +92,22 @@ - (BOOL)isEqual:(id)object
// overheard of our caching, so it's likely not high-impact.
if ([object isKindOfClass:[ASImageNodeContentsKey class]]) {
ASImageNodeContentsKey *other = (ASImageNodeContentsKey *)object;
return [_image isEqual:other.image]
&& CGSizeEqualToSize(_backingSize, other.backingSize)
&& CGRectEqualToRect(_imageDrawRect, other.imageDrawRect)
&& _isOpaque == other.isOpaque
&& [_backgroundColor isEqual:other.backgroundColor]
&& [_tintColor isEqual:other.tintColor]
&& _willDisplayNodeContentWithRenderingContext == other.willDisplayNodeContentWithRenderingContext
&& _didDisplayNodeContentWithRenderingContext == other.didDisplayNodeContentWithRenderingContext
#if AS_BUILD_UIUSERINTERFACESTYLE
&& _userInterfaceStyle == other.userInterfaceStyle
#endif
&& _imageModificationBlock == other.imageModificationBlock;
BOOL areKeysEqual = [_image isEqual:other.image]
&& CGSizeEqualToSize(_backingSize, other.backingSize)
&& CGRectEqualToRect(_imageDrawRect, other.imageDrawRect)
&& _isOpaque == other.isOpaque
&& [_backgroundColor isEqual:other.backgroundColor]
&& [_tintColor isEqual:other.tintColor]
&& _willDisplayNodeContentWithRenderingContext == other.willDisplayNodeContentWithRenderingContext
&& _didDisplayNodeContentWithRenderingContext == other.didDisplayNodeContentWithRenderingContext
&& _imageModificationBlock == other.imageModificationBlock;
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
// iOS 12, tvOS 10 and later (userInterfaceStyle only available in iOS12+)
return areKeysEqual && _userInterfaceStyle == other.userInterfaceStyle;
} else {
// iOS 11 and earlier
return areKeysEqual;
rahul-malik marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
return NO;
}
Expand Down Expand Up @@ -150,7 +150,6 @@ @implementation ASImageNode
UIImage *_image;
ASWeakMapEntry *_weakCacheEntry; // Holds a reference that keeps our contents in cache.
UIColor *_placeholderColor;
UIColor *_tintColor; // Used to cache color information for layer backed nodes. View backed will use UIViewBridge

void (^_displayCompletionBlock)(BOOL canceled);

Expand Down Expand Up @@ -319,9 +318,9 @@ - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
drawParameters->_imageModificationBlock = _imageModificationBlock;
drawParameters->_willDisplayNodeContentWithRenderingContext = _willDisplayNodeContentWithRenderingContext;
drawParameters->_didDisplayNodeContentWithRenderingContext = _didDisplayNodeContentWithRenderingContext;
#if AS_BUILD_UIUSERINTERFACESTYLE
drawParameters->userInterfaceStyle = self.primitiveTraitCollection.userInterfaceStyle;
#endif
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
drawParameters->userInterfaceStyle = self.primitiveTraitCollection.userInterfaceStyle;
}


// Hack for now to retain the weak entry that was created while this drawing happened
Expand Down Expand Up @@ -414,12 +413,6 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameter isCancelled:(NS_NOESC
return nil;
}

#if AS_BUILD_UIUSERINTERFACESTYLE
UIUserInterfaceStyle userInterfaceStyle = drawParameter->userInterfaceStyle;
#endif



ASImageNodeContentsKey *contentsKey = [[ASImageNodeContentsKey alloc] init];
contentsKey.image = image;
contentsKey.backingSize = backingSize;
Expand All @@ -430,9 +423,12 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameter isCancelled:(NS_NOESC
contentsKey.willDisplayNodeContentWithRenderingContext = willDisplayNodeContentWithRenderingContext;
contentsKey.didDisplayNodeContentWithRenderingContext = didDisplayNodeContentWithRenderingContext;
contentsKey.imageModificationBlock = imageModificationBlock;
#if AS_BUILD_UIUSERINTERFACESTYLE
contentsKey.userInterfaceStyle = userInterfaceStyle;
#endif

if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
UIUserInterfaceStyle userInterfaceStyle = drawParameter->userInterfaceStyle;
contentsKey.userInterfaceStyle = userInterfaceStyle;
}

if (isCancelled()) {
return nil;
}
Expand Down Expand Up @@ -758,7 +754,6 @@ - (NSDictionary *)debugLabelAttributes
};
}

#if AS_BUILD_UIUSERINTERFACESTYLE
- (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTraitCollection)previousTraitCollection {
[super asyncTraitCollectionDidChangeWithPreviousTraitCollection:previousTraitCollection];

Expand All @@ -776,7 +771,8 @@ - (void)asyncTraitCollectionDidChangeWithPreviousTraitCollection:(ASPrimitiveTra
}
}
}
#endif


@end

#pragma mark - Extras
Expand Down
5 changes: 5 additions & 0 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,11 @@ - (NSUInteger)lineCount
return ASLockedSelf([[self _locked_renderer] lineCount]);
}

- (BOOL)textColorFollowsTintColor
{
return ASLockedSelf(_textColorFollowsTintColor);
}

#pragma mark - Truncation Message

- (void)_invalidateTruncationText
Expand Down
12 changes: 0 additions & 12 deletions Source/Base/ASBaseDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
#define AS_EXTERN FOUNDATION_EXTERN
#define unowned __unsafe_unretained

/**
* Hack to support building for iOS with Xcode 9. UIUserInterfaceStyle was previously tvOS-only,
* and it was added to iOS 12. Xcode 9 (iOS 11 SDK) will flat-out refuse to build anything that
* references this enum targeting iOS, even if it's guarded with the right availability macros,
* because it thinks the entire platform isn't compatible with the enum.
*/
#if TARGET_OS_TV || (defined(__IPHONE_12_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
#define AS_BUILD_UIUSERINTERFACESTYLE 1
rahul-malik marked this conversation as resolved.
Show resolved Hide resolved
#else
#define AS_BUILD_UIUSERINTERFACESTYLE 0
#endif

/**
* Decorates methods that clients can implement in categories on our base class. These methods
* will be stubbed with an empty implementation if no implementation is provided.
Expand Down
5 changes: 1 addition & 4 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ typedef struct {
UIUserInterfaceIdiom userInterfaceIdiom;
UIForceTouchCapability forceTouchCapability;
UITraitEnvironmentLayoutDirection layoutDirection API_AVAILABLE(ios(10.0));
#if AS_BUILD_UIUSERINTERFACESTYLE
UIUserInterfaceStyle userInterfaceStyle API_AVAILABLE(tvos(10.0), ios(12.0));
#endif


// NOTE: This must be a constant. We will assert.
unowned UIContentSizeCategory preferredContentSizeCategory API_AVAILABLE(ios(10.0));
Expand Down Expand Up @@ -139,9 +138,7 @@ AS_SUBCLASSING_RESTRICTED
@property (readonly) UIUserInterfaceIdiom userInterfaceIdiom;
@property (readonly) UIForceTouchCapability forceTouchCapability;
@property (readonly) UITraitEnvironmentLayoutDirection layoutDirection API_AVAILABLE(ios(10.0));
#if AS_BUILD_UIUSERINTERFACESTYLE
@property (readonly) UIUserInterfaceStyle userInterfaceStyle API_AVAILABLE(tvos(10.0), ios(12.0));
#endif
@property (readonly) UIContentSizeCategory preferredContentSizeCategory API_AVAILABLE(ios(10.0));

@property (readonly) CGSize containerSize;
Expand Down
12 changes: 2 additions & 10 deletions Source/Details/ASTraitCollection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionMakeDefault() {
tc.preferredContentSizeCategory = UIContentSizeCategoryUnspecified;
tc.layoutDirection = UITraitEnvironmentLayoutDirectionUnspecified;
}
#if AS_BUILD_UIUSERINTERFACESTYLE
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
tc.userInterfaceStyle = UIUserInterfaceStyleUnspecified;
}
#endif
return tc;
}

Expand All @@ -60,11 +58,9 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionFromUITraitCollection(UITra
ASDisplayNodeCAssertPermanent(traitCollection.preferredContentSizeCategory);
environmentTraitCollection.preferredContentSizeCategory = traitCollection.preferredContentSizeCategory;
}
#if AS_BUILD_UIUSERINTERFACESTYLE
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
environmentTraitCollection.userInterfaceStyle = traitCollection.userInterfaceStyle;
}
#endif
return environmentTraitCollection;
}

Expand Down Expand Up @@ -139,7 +135,6 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
}

// Named so as not to conflict with a hidden Apple function, in case compiler decides not to inline
#if AS_BUILD_UIUSERINTERFACESTYLE
API_AVAILABLE(tvos(10.0), ios(12.0))
ASDISPLAYNODE_INLINE NSString *AS_NSStringFromUIUserInterfaceStyle(UIUserInterfaceStyle userInterfaceStyle) {
switch (userInterfaceStyle) {
Expand All @@ -151,7 +146,6 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
return @"Unspecified";
}
}
#endif

NSString *NSStringFromASPrimitiveTraitCollection(ASPrimitiveTraitCollection traits) {
NSMutableArray<NSDictionary *> *props = [NSMutableArray array];
Expand All @@ -160,11 +154,9 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
[props addObject:@{ @"displayScale": [NSString stringWithFormat: @"%.0lf", (double)traits.displayScale] }];
[props addObject:@{ @"userInterfaceIdiom": AS_NSStringFromUIUserInterfaceIdiom(traits.userInterfaceIdiom) }];
[props addObject:@{ @"forceTouchCapability": AS_NSStringFromUIForceTouchCapability(traits.forceTouchCapability) }];
#if AS_BUILD_UIUSERINTERFACESTYLE
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
[props addObject:@{ @"userInterfaceStyle": AS_NSStringFromUIUserInterfaceStyle(traits.userInterfaceStyle) }];
}
#endif
if (AS_AVAILABLE_IOS(10)) {
[props addObject:@{ @"layoutDirection": AS_NSStringFromUITraitEnvironmentLayoutDirection(traits.layoutDirection) }];
[props addObject:@{ @"preferredContentSizeCategory": traits.preferredContentSizeCategory }];
Expand Down Expand Up @@ -220,12 +212,12 @@ - (CGSize)containerSize
{
return _prim.containerSize;
}
#if AS_BUILD_UIUSERINTERFACESTYLE

- (UIUserInterfaceStyle)userInterfaceStyle
{
return _prim.userInterfaceStyle;
}
#endif

- (UIContentSizeCategory)preferredContentSizeCategory
{
return _prim.preferredContentSizeCategory;
Expand Down
7 changes: 6 additions & 1 deletion Source/UIImage+ASConvenience.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ @implementation UIImage (ASDKFastImageNamed)
NSString *imageKey = imageName;
if (traitCollection) {
char imageKeyBuffer[256];
snprintf(imageKeyBuffer, sizeof(imageKeyBuffer), "%s|%ld|%ld|%ld", imageName.UTF8String, (long)traitCollection.horizontalSizeClass, (long)traitCollection.verticalSizeClass, (long)traitCollection.userInterfaceStyle);
if (@available(iOS 12.0, *)) {
snprintf(imageKeyBuffer, sizeof(imageKeyBuffer), "%s|%ld|%ld|%ld", imageName.UTF8String, (long)traitCollection.horizontalSizeClass, (long)traitCollection.verticalSizeClass, (long)traitCollection.userInterfaceStyle);
} else {
// Fallback on earlier versions
snprintf(imageKeyBuffer, sizeof(imageKeyBuffer), "%s|%ld|%ld", imageName.UTF8String, (long)traitCollection.horizontalSizeClass, (long)traitCollection.verticalSizeClass);
}
imageKey = [NSString stringWithUTF8String:imageKeyBuffer];
}

Expand Down