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

ASLayoutSpec to use more default implementations #trivial #73

Merged
merged 1 commit into from
Apr 27, 2017
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
10 changes: 10 additions & 0 deletions Source/Details/ASTraitCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ ASDISPLAYNODE_EXTERN_C_END

@end

#define ASPrimitiveTraitCollectionDefaults \
- (ASPrimitiveTraitCollection)primitiveTraitCollection\
{\
return _primitiveTraitCollection;\
}\
- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\
{\
_primitiveTraitCollection = traitCollection;\
}\

#define ASPrimitiveTraitCollectionDeprecatedImplementation \
- (ASEnvironmentTraitCollection)environmentTraitCollection\
{\
Expand Down
14 changes: 7 additions & 7 deletions Source/Layout/ASLayoutElementPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ extern void ASLayoutElementClearCurrentContext();
#define ASLayoutElementLayoutCalculationDefaults \
- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize\
{\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")\
/* For now we just call the deprecated measureWithSizeRange: method to not break old API */ \
return [self measureWithSizeRange:constrainedSize]; \
_Pragma("clang diagnostic pop")\
} \
return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max];\
}\
\
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize\
{\
return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max];\
}\
\
- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)parentSize\
{\
return [self calculateLayoutThatFits:constrainedSize restrictedToSize:self.style.size relativeToParentSize:parentSize];\
}\
\
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize\
restrictedToSize:(ASLayoutElementSize)size\
relativeToParentSize:(CGSize)parentSize\
Expand All @@ -69,7 +70,6 @@ extern void ASLayoutElementClearCurrentContext();
return [self calculateLayoutThatFits:resolvedRange];\
}\


#pragma mark - ASLayoutElementFinalLayoutElement
/**
* The base protocol for ASLayoutElementFinalLayoutElement. Generally the methods/properties in this class do not need to be
Expand Down
36 changes: 2 additions & 34 deletions Source/Layout/ASLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,7 @@ - (instancetype)styledWithBlock:(AS_NOESCAPE void (^)(__kindof ASLayoutElementSt

#pragma mark - Layout

- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize
{
return [self layoutThatFits:constrainedSize parentSize:constrainedSize.max];
}

- (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)parentSize
{
return [self calculateLayoutThatFits:constrainedSize restrictedToSize:self.style.size relativeToParentSize:parentSize];
}

- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
restrictedToSize:(ASLayoutElementSize)size
relativeToParentSize:(CGSize)parentSize
{
const ASSizeRange resolvedRange = ASSizeRangeIntersect(constrainedSize, ASLayoutElementSizeResolve(self.style.size, parentSize));
return [self calculateLayoutThatFits:resolvedRange];
}
ASLayoutElementLayoutCalculationDefaults

- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
Expand Down Expand Up @@ -178,22 +162,13 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object

#pragma mark - ASTraitEnvironment

- (ASPrimitiveTraitCollection)primitiveTraitCollection
{
return _primitiveTraitCollection;
}

- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection
{
_primitiveTraitCollection = traitCollection;
}

- (ASTraitCollection *)asyncTraitCollection
{
ASDN::MutexLocker l(__instanceLock__);
return [ASTraitCollection traitCollectionWithASPrimitiveTraitCollection:self.primitiveTraitCollection];
}

ASPrimitiveTraitCollectionDefaults
ASPrimitiveTraitCollectionDeprecatedImplementation

#pragma mark - ASLayoutElementStyleExtensibility
Expand Down Expand Up @@ -261,13 +236,6 @@ - (void)setDebugName:(NSString *)debugName
}
}

#pragma mark - Deprecated

- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
{
return [self layoutThatFits:constrainedSize];
}

@end

#pragma mark - ASWrapperLayoutSpec
Expand Down