-
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
[ASTraitCollection] Add missing properties to ASTraitCollection #625
Merged
nguyenhuy
merged 7 commits into
TextureGroup:master
from
ypogribnyi:ASTraitCollection-missing-properties
Jan 16, 2018
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70fbac1
[ASTraitCollection] Add missing properties to ASTraitCollection
ypogribnyi 5afe689
Merge branch 'master' into ASTraitCollection-missing-properties
ypogribnyi e0c395e
* Remove enum ASContentSizeCategory.
ypogribnyi 185a139
Added ASPrimitiveTraitCollection lifetime test
ypogribnyi 10f3d8f
Merge branch 'master' of https://github.com/TextureGroup/Texture into…
ypogribnyi 663d272
Changes requested at code review:
ypogribnyi 11dc888
Fix failing test
ypogribnyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import <AsyncDisplayKit/ASBaseDefines.h> | ||
|
||
@class ASTraitCollection; | ||
|
@@ -27,14 +28,51 @@ NS_ASSUME_NONNULL_BEGIN | |
|
||
ASDISPLAYNODE_EXTERN_C_BEGIN | ||
|
||
#pragma mark - ASPrimitiveContentSizeCategory | ||
|
||
/** | ||
* ASPrimitiveContentSizeCategory is a UIContentSizeCategory that can be used inside a struct. | ||
* | ||
* We need an unretained pointer because ARC can't manage struct memory. | ||
* | ||
* WARNING: DO NOT cast UIContentSizeCategory values to ASPrimitiveContentSizeCategory directly. | ||
* Use ASPrimitiveContentSizeCategoryMake(UIContentSizeCategory) instead. | ||
* This is because we make some assumptions about the lifetime of the object it points to. | ||
* Also note that cast from ASPrimitiveContentSizeCategory to UIContentSizeCategory is always safe. | ||
*/ | ||
typedef __unsafe_unretained UIContentSizeCategory ASPrimitiveContentSizeCategory; | ||
|
||
/** | ||
* Safely casts from UIContentSizeCategory to ASPrimitiveContentSizeCategory. | ||
* | ||
* The UIKit documentation doesn't specify if we can receive a copy of the UIContentSizeCategory constant. While getting | ||
* copies is fine with ARC, usage of unretained pointers requires us to ensure the lifetime of the object it points to. | ||
* Manual retain&release of the UIContentSizeCategory object is not an option because it would require us to do that | ||
* everywhere ASPrimitiveTraitCollection is used. This is error-prone and can lead to crashes and memory leaks. So, we | ||
* explicitly limit possible values of ASPrimitiveContentSizeCategory to the predetermined set of global constants with | ||
* known lifetime. | ||
* | ||
* @return a pointer to one of the UIContentSizeCategory constants. | ||
*/ | ||
extern ASPrimitiveContentSizeCategory ASPrimitiveContentSizeCategoryMake(UIContentSizeCategory sizeCategory); | ||
|
||
#pragma mark - ASPrimitiveTraitCollection | ||
|
||
typedef struct ASPrimitiveTraitCollection { | ||
CGFloat displayScale; | ||
UIUserInterfaceSizeClass horizontalSizeClass; | ||
UIUserInterfaceIdiom userInterfaceIdiom; | ||
UIUserInterfaceSizeClass verticalSizeClass; | ||
|
||
CGFloat displayScale; | ||
UIDisplayGamut displayGamut; | ||
|
||
UIUserInterfaceIdiom userInterfaceIdiom; | ||
UIForceTouchCapability forceTouchCapability; | ||
UITraitEnvironmentLayoutDirection layoutDirection; | ||
#if TARGET_OS_TV | ||
UIUserInterfaceStyle userInterfaceStyle; | ||
#endif | ||
|
||
ASPrimitiveContentSizeCategory preferredContentSizeCategory; | ||
|
||
CGSize containerSize; | ||
} ASPrimitiveTraitCollection; | ||
|
@@ -124,25 +162,45 @@ ASDISPLAYNODE_EXTERN_C_END | |
AS_SUBCLASSING_RESTRICTED | ||
@interface ASTraitCollection : NSObject | ||
|
||
@property (nonatomic, assign, readonly) CGFloat displayScale; | ||
@property (nonatomic, assign, readonly) UIUserInterfaceSizeClass horizontalSizeClass; | ||
@property (nonatomic, assign, readonly) UIUserInterfaceIdiom userInterfaceIdiom; | ||
@property (nonatomic, assign, readonly) UIUserInterfaceSizeClass verticalSizeClass; | ||
|
||
@property (nonatomic, assign, readonly) CGFloat displayScale; | ||
@property (nonatomic, assign, readonly) UIDisplayGamut displayGamut; | ||
|
||
@property (nonatomic, assign, readonly) UIUserInterfaceIdiom userInterfaceIdiom; | ||
@property (nonatomic, assign, readonly) UIForceTouchCapability forceTouchCapability; | ||
@property (nonatomic, assign, readonly) UITraitEnvironmentLayoutDirection layoutDirection; | ||
#if TARGET_OS_TV | ||
@property (nonatomic, assign, readonly) UIUserInterfaceStyle userInterfaceStyle; | ||
#endif | ||
|
||
@property (nonatomic, assign, readonly) UIContentSizeCategory preferredContentSizeCategory; | ||
|
||
@property (nonatomic, assign, readonly) CGSize containerSize; | ||
|
||
+ (ASTraitCollection *)traitCollectionWithASPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traits; | ||
|
||
+ (ASTraitCollection *)traitCollectionWithUITraitCollection:(UITraitCollection *)traitCollection | ||
containerSize:(CGSize)windowSize; | ||
|
||
|
||
+ (ASTraitCollection *)traitCollectionWithDisplayScale:(CGFloat)displayScale | ||
userInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom | ||
horizontalSizeClass:(UIUserInterfaceSizeClass)horizontalSizeClass | ||
verticalSizeClass:(UIUserInterfaceSizeClass)verticalSizeClass | ||
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
containerSize:(CGSize)windowSize; | ||
+ (ASTraitCollection *)traitCollectionWithUITraitCollection:(UITraitCollection *)traitCollection | ||
containerSize:(CGSize)windowSize | ||
fallbackContentSizeCategory:(UIContentSizeCategory)fallbackContentSizeCategory; | ||
|
||
|
||
+ (ASTraitCollection *)traitCollectionWithHorizontalSizeClass:(UIUserInterfaceSizeClass)horizontalSizeClass | ||
verticalSizeClass:(UIUserInterfaceSizeClass)verticalSizeClass | ||
displayScale:(CGFloat)displayScale | ||
displayGamut:(UIDisplayGamut)displayGamut | ||
userInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom | ||
forceTouchCapability:(UIForceTouchCapability)forceTouchCapability | ||
layoutDirection:(UITraitEnvironmentLayoutDirection)layoutDirection | ||
#if TARGET_OS_TV | ||
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 understand your reasoning here. However, for maintainability, I think it's best to declare a separate API for tvOS with this extra param. |
||
userInterfaceStyle:(UIUserInterfaceStyle)userInterfaceStyle | ||
#endif | ||
preferredContentSizeCategory:(UIContentSizeCategory)preferredContentSizeCategory | ||
containerSize:(CGSize)windowSize; | ||
|
||
|
||
- (ASPrimitiveTraitCollection)primitiveTraitCollection; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be considered a breaking API change. Instead, I think we should preserve this API and call the full version internally with default values. We can also deprecate it, but that's as far as we can go for now, IMHO.