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

Adds support for new iOS 13 traits #1568

Merged
merged 2 commits into from
Jan 2, 2020
Merged
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
8 changes: 8 additions & 0 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ typedef struct {
unowned UIContentSizeCategory preferredContentSizeCategory API_AVAILABLE(ios(10.0));

CGSize containerSize;

jparise marked this conversation as resolved.
Show resolved Hide resolved
UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0));
UIAccessibilityContrast accessibilityContrast API_AVAILABLE(ios(13.0));
UILegibilityWeight legibilityWeight API_AVAILABLE(ios(13.0));
} ASPrimitiveTraitCollection;
#pragma clang diagnostic pop

Expand Down Expand Up @@ -148,6 +152,10 @@ AS_SUBCLASSING_RESTRICTED

@property (readonly) CGSize containerSize;

@property (readonly) UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0));
@property (readonly) UIAccessibilityContrast accessibilityContrast API_AVAILABLE(ios(13.0));
@property (readonly) UILegibilityWeight legibilityWeight API_AVAILABLE(ios(13.0));

- (BOOL)isEqualToTraitCollection:(ASTraitCollection *)traitCollection;

@end
Expand Down
69 changes: 69 additions & 0 deletions Source/Details/ASTraitCollection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionMakeDefault() {
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
tc.userInterfaceStyle = UIUserInterfaceStyleUnspecified;
}
if(AS_AVAILABLE_IOS(13)){
tc.userInterfaceLevel = UIUserInterfaceLevelUnspecified;
tc.accessibilityContrast = UIAccessibilityContrastUnspecified;
tc.legibilityWeight = UILegibilityWeightUnspecified;
}
return tc;
}

Expand All @@ -61,6 +66,11 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionFromUITraitCollection(UITra
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
environmentTraitCollection.userInterfaceStyle = traitCollection.userInterfaceStyle;
}
if(AS_AVAILABLE_IOS(13)){
environmentTraitCollection.userInterfaceLevel = traitCollection.userInterfaceLevel;
environmentTraitCollection.accessibilityContrast = traitCollection.accessibilityContrast;
environmentTraitCollection.legibilityWeight = traitCollection.legibilityWeight;
}
return environmentTraitCollection;
}

Expand Down Expand Up @@ -169,6 +179,47 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
}
}

// Named so as not to conflict with a hidden Apple function, in case compiler decides not to inline
API_AVAILABLE(ios(13))
ASDISPLAYNODE_INLINE NSString *AS_NSStringFromUITraitEnvironmentUserInterfaceLevel(UIUserInterfaceLevel userInterfaceLevel) {
switch (userInterfaceLevel) {
case UIUserInterfaceLevelBase:
return @"Base";
case UIUserInterfaceLevelElevated:
return @"Elevated";
default:
return @"Unspecified";
}
}

// Named so as not to conflict with a hidden Apple function, in case compiler decides not to inline
API_AVAILABLE(ios(13))
ASDISPLAYNODE_INLINE NSString *AS_NSStringFromUITraitEnvironmentAccessibilityContrast(UIAccessibilityContrast accessibilityContrast) {
switch (accessibilityContrast) {
case UIAccessibilityContrastNormal:
return @"Normal";
case UIAccessibilityContrastHigh:
return @"High";
default:
return @"Unspecified";
}
}

// Named so as not to conflict with a hidden Apple function, in case compiler decides not to inline
API_AVAILABLE(ios(13))
ASDISPLAYNODE_INLINE NSString *AS_NSStringFromUITraitEnvironmentLegibilityWeight(UILegibilityWeight legibilityWeight) {
switch (legibilityWeight) {
case UILegibilityWeightRegular:
return @"Regular";
case UILegibilityWeightBold:
return @"Bold";
default:
return @"Unspecified";
}
}



NSString *NSStringFromASPrimitiveTraitCollection(ASPrimitiveTraitCollection traits) {
NSMutableArray<NSDictionary *> *props = [NSMutableArray array];
[props addObject:@{ @"verticalSizeClass": AS_NSStringFromUIUserInterfaceSizeClass(traits.verticalSizeClass) }];
Expand All @@ -184,6 +235,11 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
[props addObject:@{ @"preferredContentSizeCategory": traits.preferredContentSizeCategory }];
[props addObject:@{ @"displayGamut": AS_NSStringFromUIDisplayGamut(traits.displayGamut) }];
}
if (AS_AVAILABLE_IOS(13)){
[props addObject:@{ @"userInterfaceLevel": AS_NSStringFromUITraitEnvironmentUserInterfaceLevel(traits.userInterfaceLevel) }];
[props addObject:@{ @"accessibilityContrast": AS_NSStringFromUITraitEnvironmentAccessibilityContrast(traits.accessibilityContrast) }];
[props addObject:@{ @"legibilityWeight": AS_NSStringFromUITraitEnvironmentLegibilityWeight(traits.legibilityWeight) }];
}
[props addObject:@{ @"containerSize": NSStringFromCGSize(traits.containerSize) }];
return ASObjectDescriptionMakeWithoutObject(props);
}
Expand Down Expand Up @@ -244,6 +300,19 @@ - (UIContentSizeCategory)preferredContentSizeCategory
{
return _prim.preferredContentSizeCategory;
}
- (UIUserInterfaceLevel)userInterfaceLevel
{
return _prim.userInterfaceLevel;
}
- (UIAccessibilityContrast)accessibilityContrast
{
return _prim.accessibilityContrast;
}
- (UILegibilityWeight)legibilityWeight
{
return _prim.legibilityWeight;
}

- (NSUInteger)hash {
return ASHashBytes(&_prim, sizeof(ASPrimitiveTraitCollection));
}
Expand Down