-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ASPrimitiveTraitCollection] Always treat preferredContentSize as a potential nil #trivial #757
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ ASDISPLAYNODE_INLINE UIContentSizeCategory AS_UIContentSizeCategoryUnspecified() | |
} | ||
} | ||
|
||
ASDISPLAYNODE_INLINE ASPrimitiveContentSizeCategory safePrimitiveContentSizeCategory(ASPrimitiveContentSizeCategory sizeCategory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still should prefix this functions with AS |
||
if (sizeCategory) { | ||
return sizeCategory; | ||
} else { | ||
return AS_UIContentSizeCategoryUnspecified(); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, feel free to ignore this: It's a bit shorter to use ternary operator here, i.e:
|
||
|
||
ASPrimitiveContentSizeCategory ASPrimitiveContentSizeCategoryMake(UIContentSizeCategory sizeCategory) { | ||
if ([sizeCategory isEqualToString:UIContentSizeCategoryExtraSmall]) { | ||
return UIContentSizeCategoryExtraSmall; | ||
|
@@ -92,7 +100,7 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionMakeDefault() { | |
.displayGamut = UIDisplayGamutUnspecified, | ||
.userInterfaceIdiom = UIUserInterfaceIdiomUnspecified, | ||
.layoutDirection = UITraitEnvironmentLayoutDirectionUnspecified, | ||
.preferredContentSizeCategory = ASPrimitiveContentSizeCategoryMake(AS_UIContentSizeCategoryUnspecified()), | ||
.preferredContentSizeCategory = AS_UIContentSizeCategoryUnspecified(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove the |
||
.containerSize = CGSizeZero, | ||
}; | ||
} | ||
|
@@ -115,13 +123,15 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionFromUITraitCollection(UITra | |
#if TARGET_OS_TV | ||
environmentTraitCollection.userInterfaceStyle = traitCollection.userInterfaceStyle; | ||
#endif | ||
} else { | ||
environmentTraitCollection.displayGamut = UIDisplayGamutSRGB; // We're on iOS 9 or lower, so this is not a P3 device. | ||
} | ||
return environmentTraitCollection; | ||
} | ||
|
||
BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTraitCollection lhs, ASPrimitiveTraitCollection rhs) { | ||
UIContentSizeCategory leftSizeCategory = (UIContentSizeCategory)lhs.preferredContentSizeCategory; | ||
UIContentSizeCategory rightSizeCategory = (UIContentSizeCategory)rhs.preferredContentSizeCategory; | ||
UIContentSizeCategory leftSizeCategory = (UIContentSizeCategory)safePrimitiveContentSizeCategory(lhs.preferredContentSizeCategory); | ||
UIContentSizeCategory rightSizeCategory = (UIContentSizeCategory)safePrimitiveContentSizeCategory(rhs.preferredContentSizeCategory); | ||
|
||
return | ||
lhs.verticalSizeClass == rhs.verticalSizeClass && | ||
|
@@ -230,7 +240,7 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr | |
#if TARGET_OS_TV | ||
[props addObject:@{ @"userInterfaceStyle": AS_NSStringFromUIUserInterfaceStyle(traits.userInterfaceStyle) }]; | ||
#endif | ||
[props addObject:@{ @"preferredContentSizeCategory": (UIContentSizeCategory)traits.preferredContentSizeCategory }]; | ||
[props addObject:@{ @"preferredContentSizeCategory": (UIContentSizeCategory)safePrimitiveContentSizeCategory(traits.preferredContentSizeCategory) }]; | ||
[props addObject:@{ @"containerSize": NSStringFromCGSize(traits.containerSize) }]; | ||
return ASObjectDescriptionMakeWithoutObject(props); | ||
} | ||
|
@@ -249,7 +259,7 @@ - (instancetype)initWithHorizontalSizeClass:(UIUserInterfaceSizeClass)horizontal | |
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
layoutDirection:(UITraitEnvironmentLayoutDirection)layoutDirection | ||
userInterfaceStyle:(UIUserInterfaceStyle)userInterfaceStyle | ||
preferredContentSizeCategory:(UIContentSizeCategory)preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)preferredContentSizeCategory | ||
containerSize:(CGSize)windowSize | ||
{ | ||
self = [super init]; | ||
|
@@ -276,7 +286,7 @@ + (instancetype)traitCollectionWithHorizontalSizeClass:(UIUserInterfaceSizeClass | |
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
layoutDirection:(UITraitEnvironmentLayoutDirection)layoutDirection | ||
userInterfaceStyle:(UIUserInterfaceStyle)userInterfaceStyle | ||
preferredContentSizeCategory:(UIContentSizeCategory)preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)preferredContentSizeCategory | ||
containerSize:(CGSize)windowSize | ||
{ | ||
return [[self alloc] initWithHorizontalSizeClass:horizontalSizeClass | ||
|
@@ -300,7 +310,7 @@ - (instancetype)initWithHorizontalSizeClass:(UIUserInterfaceSizeClass)horizontal | |
userInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom | ||
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
layoutDirection:(UITraitEnvironmentLayoutDirection)layoutDirection | ||
preferredContentSizeCategory:(UIContentSizeCategory)preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)preferredContentSizeCategory | ||
containerSize:(CGSize)windowSize | ||
{ | ||
self = [super init]; | ||
|
@@ -325,7 +335,7 @@ + (instancetype)traitCollectionWithHorizontalSizeClass:(UIUserInterfaceSizeClass | |
userInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom | ||
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
layoutDirection:(UITraitEnvironmentLayoutDirection)layoutDirection | ||
preferredContentSizeCategory:(UIContentSizeCategory)preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)preferredContentSizeCategory | ||
containerSize:(CGSize)windowSize | ||
{ | ||
return [[self alloc] initWithHorizontalSizeClass:horizontalSizeClass | ||
|
@@ -383,7 +393,7 @@ + (instancetype)traitCollectionWithASPrimitiveTraitCollection:(ASPrimitiveTraitC | |
forceTouchCapability:traits.forceTouchCapability | ||
layoutDirection:traits.layoutDirection | ||
userInterfaceStyle:traits.userInterfaceStyle | ||
preferredContentSizeCategory:(UIContentSizeCategory)traits.preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)safePrimitiveContentSizeCategory(traits.preferredContentSizeCategory) | ||
containerSize:traits.containerSize]; | ||
#else | ||
return [self traitCollectionWithHorizontalSizeClass:traits.horizontalSizeClass | ||
|
@@ -393,7 +403,7 @@ + (instancetype)traitCollectionWithASPrimitiveTraitCollection:(ASPrimitiveTraitC | |
userInterfaceIdiom:traits.userInterfaceIdiom | ||
forceTouchCapability:traits.forceTouchCapability | ||
layoutDirection:traits.layoutDirection | ||
preferredContentSizeCategory:(UIContentSizeCategory)traits.preferredContentSizeCategory | ||
preferredContentSizeCategory:(UIContentSizeCategory _Nonnull)safePrimitiveContentSizeCategory(traits.preferredContentSizeCategory) | ||
containerSize:traits.containerSize]; | ||
#endif | ||
} | ||
|
@@ -409,7 +419,7 @@ + (instancetype)traitCollectionWithUITraitCollection:(UITraitCollection *)traitC | |
|
||
+ (instancetype)traitCollectionWithUITraitCollection:(UITraitCollection *)traitCollection | ||
containerSize:(CGSize)windowSize | ||
fallbackContentSizeCategory:(UIContentSizeCategory)fallbackContentSizeCategory | ||
fallbackContentSizeCategory:(UIContentSizeCategory _Nonnull)fallbackContentSizeCategory | ||
{ | ||
UIDisplayGamut displayGamut; | ||
UITraitEnvironmentLayoutDirection layoutDirection; | ||
|
@@ -425,7 +435,7 @@ + (instancetype)traitCollectionWithUITraitCollection:(UITraitCollection *)traitC | |
userInterfaceStyle = traitCollection.userInterfaceStyle; | ||
#endif | ||
} else { | ||
displayGamut = UIDisplayGamutUnspecified; | ||
displayGamut = UIDisplayGamutSRGB; // We're on iOS 9 or lower, so this is not a P3 device. | ||
layoutDirection = UITraitEnvironmentLayoutDirectionUnspecified; | ||
sizeCategory = fallbackContentSizeCategory; | ||
#if TARGET_OS_TV | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need
_Nonnull
annotations since we already useNS_ASSUME_NONNULL_BEGIN
at the beginning of this file (here). It's always good to be defensive and guard against unexpected values in the implementation though.