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

Only include UIUserInterfaceLevel in iOS target #1757

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

CGSize containerSize;

UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0));

#if TARGET_OS_IOS
UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);
#endif
UIAccessibilityContrast accessibilityContrast API_AVAILABLE(ios(13.0));
UILegibilityWeight legibilityWeight API_AVAILABLE(ios(13.0));
} ASPrimitiveTraitCollection;
Expand Down Expand Up @@ -152,7 +154,10 @@ AS_SUBCLASSING_RESTRICTED

@property (readonly) CGSize containerSize;

@property (readonly) UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0));
#if TARGET_OS_IOS
@property (readonly) UIUserInterfaceLevel userInterfaceLevel API_AVAILABLE(ios(13.0)) API_UNAVAILABLE(tvos);
#endif

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

Expand Down
25 changes: 24 additions & 1 deletion Source/Details/ASTraitCollection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionMakeDefault() {
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
tc.userInterfaceStyle = UIUserInterfaceStyleUnspecified;
}

#if TARGET_OS_IOS
if(AS_AVAILABLE_IOS(13)){
tc.userInterfaceLevel = UIUserInterfaceLevelUnspecified;
}
#endif

if (AS_AVAILABLE_IOS(13)) {
tc.accessibilityContrast = UIAccessibilityContrastUnspecified;
tc.legibilityWeight = UILegibilityWeightUnspecified;
}
Expand All @@ -66,8 +72,14 @@ ASPrimitiveTraitCollection ASPrimitiveTraitCollectionFromUITraitCollection(UITra
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
environmentTraitCollection.userInterfaceStyle = traitCollection.userInterfaceStyle;
}

#if TARGET_OS_IOS
if(AS_AVAILABLE_IOS(13)){
environmentTraitCollection.userInterfaceLevel = traitCollection.userInterfaceLevel;
}
#endif

if (AS_AVAILABLE_IOS(13)) {
environmentTraitCollection.accessibilityContrast = traitCollection.accessibilityContrast;
environmentTraitCollection.legibilityWeight = traitCollection.legibilityWeight;
}
Expand Down Expand Up @@ -180,7 +192,7 @@ 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))
API_AVAILABLE(ios(13)) API_UNAVAILABLE(tvos)
ASDISPLAYNODE_INLINE NSString *AS_NSStringFromUITraitEnvironmentUserInterfaceLevel(UIUserInterfaceLevel userInterfaceLevel) {
switch (userInterfaceLevel) {
case UIUserInterfaceLevelBase:
Expand Down Expand Up @@ -235,8 +247,14 @@ BOOL ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(ASPrimitiveTr
[props addObject:@{ @"preferredContentSizeCategory": traits.preferredContentSizeCategory }];
[props addObject:@{ @"displayGamut": AS_NSStringFromUIDisplayGamut(traits.displayGamut) }];
}

#if TARGET_OS_IOS
if (AS_AVAILABLE_IOS(13)){
[props addObject:@{ @"userInterfaceLevel": AS_NSStringFromUITraitEnvironmentUserInterfaceLevel(traits.userInterfaceLevel) }];
}
#endif

if (AS_AVAILABLE_IOS(13)) {
[props addObject:@{ @"accessibilityContrast": AS_NSStringFromUITraitEnvironmentAccessibilityContrast(traits.accessibilityContrast) }];
[props addObject:@{ @"legibilityWeight": AS_NSStringFromUITraitEnvironmentLegibilityWeight(traits.legibilityWeight) }];
}
Expand Down Expand Up @@ -300,14 +318,19 @@ - (UIContentSizeCategory)preferredContentSizeCategory
{
return _prim.preferredContentSizeCategory;
}

#if TARGET_OS_IOS
- (UIUserInterfaceLevel)userInterfaceLevel
{
return _prim.userInterfaceLevel;
}
#endif

- (UIAccessibilityContrast)accessibilityContrast
{
return _prim.accessibilityContrast;
}

- (UILegibilityWeight)legibilityWeight
{
return _prim.legibilityWeight;
Expand Down