Skip to content

Commit

Permalink
[ASPrimitiveTraitCollection] Always treat preferredContentSize as a p…
Browse files Browse the repository at this point in the history
…otential nil #trivial (TextureGroup#757)

* Fix ASPrimitiveTraitCollection initialization on iOS 9.
Add nil-value checks for preferredContentSizeCategory.

* * Mark -[ASTraitCollection init] as deprecated.
* Mark [ASViewController overrideDisplayTraitsWithWindowSize] as deprecated.

Code review changes:
* Remove unneeded nonnull annotations
* Add null check in ASTraitCollection constructor implementation
* Codestyle
* Add some documentation about ASPrimitiveTraitCollection vs ASTraitCollection usage

* Rename safeContentSizeCategory to AS_safeContentSizeCategory.

Remove safePrimitiveContentSizeCategory in favour of AS_safeContentSizeCategory.
  • Loading branch information
ypogribnyi authored and bernieperez committed Apr 25, 2018
1 parent 9a52e20 commit e8eba32
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Source/ASViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Set this block to customize the ASDisplayTraits returned when the VC transitions to the given window size.
*/
@property (nonatomic, copy) ASDisplayTraitsForTraitWindowSizeBlock overrideDisplayTraitsWithWindowSize;
@property (nonatomic, copy) ASDisplayTraitsForTraitWindowSizeBlock overrideDisplayTraitsWithWindowSize ASDISPLAYNODE_DEPRECATED_MSG("This property is actually never accessed inside the framework");

/**
* @abstract Passthrough property to the the .interfaceState of the node.
Expand Down
36 changes: 30 additions & 6 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ extern ASPrimitiveContentSizeCategory ASPrimitiveContentSizeCategoryMake(UIConte

#pragma mark - ASPrimitiveTraitCollection

/**
* @abstract This is an internal struct-representation of ASTraitCollection.
*
* @discussion This struct is for internal use only. Framework users should always use ASTraitCollection.
*
* If you use ASPrimitiveTraitCollection, please do make sure to initialize it with ASPrimitiveTraitCollectionMakeDefault()
* or ASPrimitiveTraitCollectionFromUITraitCollection(UITraitCollection*).
*/
typedef struct ASPrimitiveTraitCollection {
UIUserInterfaceSizeClass horizontalSizeClass;
UIUserInterfaceSizeClass verticalSizeClass;
Expand Down Expand Up @@ -112,17 +120,23 @@ ASDISPLAYNODE_EXTERN_C_END
@protocol ASTraitEnvironment <NSObject>

/**
* Returns a struct-representation of the environment's ASEnvironmentDisplayTraits. This only exists as a internal
* convenience method. Users should access the trait collections through the NSObject based asyncTraitCollection API
* @abstract Returns a struct-representation of the environment's ASEnvironmentDisplayTraits.
*
* @discussion This only exists as an internal convenience method. Users should access the trait collections through
* the NSObject based asyncTraitCollection API
*/
- (ASPrimitiveTraitCollection)primitiveTraitCollection;

/**
* Sets a trait collection on this environment state.
* @abstract Sets a trait collection on this environment state.
*
* @discussion This only exists as an internal convenience method. Users should not override trait collection using it.
* Use [ASViewController overrideDisplayTraitsWithTraitCollection] block instead.
*/
- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection;

/**
* @abstract Returns the thread-safe UITraitCollection equivalent.
*/
- (ASTraitCollection *)asyncTraitCollection;

Expand Down Expand Up @@ -179,8 +193,6 @@ AS_SUBCLASSING_RESTRICTED

@property (nonatomic, assign, readonly) CGSize containerSize;

+ (ASTraitCollection *)traitCollectionWithASPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traits;

+ (ASTraitCollection *)traitCollectionWithUITraitCollection:(UITraitCollection *)traitCollection
containerSize:(CGSize)windowSize;

Expand Down Expand Up @@ -211,13 +223,25 @@ AS_SUBCLASSING_RESTRICTED
containerSize:(CGSize)windowSize;
#endif

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

@end

/**
* These are internal helper methods. Should never be called by the framework users.
*/
@interface ASTraitCollection (PrimitiveTraits)

+ (ASTraitCollection *)traitCollectionWithASPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traits;

- (ASPrimitiveTraitCollection)primitiveTraitCollection;

@end

@interface ASTraitCollection (Deprecated)

- (instancetype)init ASDISPLAYNODE_DEPRECATED_MSG("The default constructor of this class is going to become unavailable. Use other constructors instead.");

+ (ASTraitCollection *)traitCollectionWithDisplayScale:(CGFloat)displayScale
userInterfaceIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom
horizontalSizeClass:(UIUserInterfaceSizeClass)horizontalSizeClass
Expand Down
Loading

0 comments on commit e8eba32

Please sign in to comment.