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

[Layout] Remove finalLayoutElement #96

Merged
merged 3 commits into from
May 3, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- Update the rasterization API and un-deprecate it. [Adlai Holler](https://github.com/Adlai-Holler)[#82](https://github.com/TextureGroup/Texture/pull/49)
- Simplified & optimized hashing code. [Adlai Holler](https://github.com/Adlai-Holler) [#86](https://github.com/TextureGroup/Texture/pull/86)
- Improve the performance & safety of ASDisplayNode subnodes. [Adlai Holler](https://github.com/Adlai-Holler) [#223](https://github.com/TextureGroup/Texture/pull/223)
- Remove finalLayoutElement [Michael Schneider] (https://github.com/maicki)[#96](https://github.com/TextureGroup/Texture/pull/96)
2 changes: 1 addition & 1 deletion Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extern NSInteger const ASDefaultDrawingPriority;
*
*/

@interface ASDisplayNode : NSObject <ASLayoutElementFinalLayoutElement>
@interface ASDisplayNode : NSObject

/** @name Initializing a node object */

Expand Down
2 changes: 0 additions & 2 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,6 @@ - (BOOL)canLayoutAsynchronous
return !self.isNodeLoaded;
}

ASLayoutElementFinalLayoutElementDefault

#pragma mark <ASDebugNameProvider>

- (NSString *)debugName
Expand Down
2 changes: 0 additions & 2 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ - (void)_repopulateSupplementaryNodesIntoMap:(ASMutableElementMap *)map
*
* @param kind The kind of the elements, e.g ASDataControllerRowNodeKind
* @param sections The sections that should be populated by new elements
* @param owningNode The node that owns the new elements.
* @param traitCollection The trait collection needed to initialize elements
* @param shouldFetchSizeRanges Whether constrained sizes should be fetched from data source
*/
Expand All @@ -360,7 +359,6 @@ - (void)_insertElementsIntoMap:(ASMutableElementMap *)map
* @param map The map to insert the elements into.
* @param kind The kind of the elements, e.g ASDataControllerRowNodeKind
* @param indexPaths The index paths at which new elements should be populated
* @param owningNode The node that owns the new elements.
* @param traitCollection The trait collection needed to initialize elements
* @param shouldFetchSizeRanges Whether constrained sizes should be fetched from data source
*/
Expand Down
39 changes: 0 additions & 39 deletions Source/Layout/ASLayoutElementPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,45 +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
* called by the end user and are only called internally. However, there may be a case where the methods are useful.
*/
@protocol ASLayoutElementFinalLayoutElement <NSObject>

/**
* @abstract This method can be used to give the user a chance to wrap an ASLayoutElement in an ASLayoutSpec
* just before it is added to a parent ASLayoutSpec. For example, if you wanted an ASTextNode that was always
* inside of an ASInsetLayoutSpec, you could subclass ASTextNode and implement finalLayoutElement so that it wraps
* itself in an inset spec.
*
* Note that any ASLayoutElement other than self that is returned MUST set isFinalLayoutElement to YES. Make sure
* to do this BEFORE adding a child to the ASLayoutElement.
*
* @return The layoutElement that will be added to the parent layout spec. Defaults to self.
*/
- (id<ASLayoutElement>)finalLayoutElement;

/**
* A flag to indicate that this ASLayoutElement was created in finalLayoutElement. This MUST be set to YES
* before adding a child to this layoutElement.
*/
@property (nonatomic, assign) BOOL isFinalLayoutElement;

@end

// Default implementation for ASLayoutElementPrivate that can be used in classes that comply to ASLayoutElementPrivate

#define ASLayoutElementFinalLayoutElementDefault \
\
@synthesize isFinalLayoutElement = _isFinalLayoutElement;\
\
- (id<ASLayoutElement>)finalLayoutElement\
{\
return self;\
}\


#pragma mark - ASLayoutElementExtensibility

Expand Down
21 changes: 0 additions & 21 deletions Source/Layout/ASLayoutSpec+Subclasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface ASLayoutSpec (Subclassing)

/**
* Helper method for finalLayoutElement support
*
* @warning If you are getting recursion crashes here after implementing finalLayoutElement, make sure
* that you are setting isFinalLayoutElement flag to YES. This must be one BEFORE adding a child
* to the new ASLayoutElement.
*
* For example:
* - (id<ASLayoutElement>)finalLayoutElement
* {
* ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
* insetSpec.insets = UIEdgeInsetsMake(10,10,10,10);
* insetSpec.isFinalLayoutElement = YES;
* [insetSpec setChild:self];
* return insetSpec;
* }
*
* @see finalLayoutElement
*/
- (id<ASLayoutElement>)layoutElementToAddFromLayoutElement:(id<ASLayoutElement>)child;

/**
* Adds a child with the given identifier to this layout spec.
*
Expand Down
16 changes: 1 addition & 15 deletions Source/Layout/ASLayoutSpec+Subclasses.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,13 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize

@implementation ASLayoutSpec (Subclassing)

#pragma mark - Final layoutElement

- (id<ASLayoutElement>)layoutElementToAddFromLayoutElement:(id<ASLayoutElement, ASLayoutElementFinalLayoutElement>)child
{
if (self.isFinalLayoutElement == NO) {
id<ASLayoutElement> finalLayoutElement = [child finalLayoutElement];
if (finalLayoutElement != child) {
finalLayoutElement.primitiveTraitCollection = child.primitiveTraitCollection;
return finalLayoutElement;
}
}
return child;
}

#pragma mark - Child with index

- (void)setChild:(id<ASLayoutElement>)child atIndex:(NSUInteger)index
{
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");

id<ASLayoutElement> layoutElement = child ? [self layoutElementToAddFromLayoutElement:child] : [ASNullLayoutSpec null];
id<ASLayoutElement> layoutElement = child ?: [ASNullLayoutSpec null];

if (child) {
if (_childrenArray.count < index) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Layout/ASLayoutSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* A layout spec is an immutable object that describes a layout, loosely inspired by React.
*/
@interface ASLayoutSpec : NSObject <ASLayoutElement, ASLayoutElementFinalLayoutElement, ASLayoutElementStylability, NSFastEnumeration>
@interface ASLayoutSpec : NSObject <ASLayoutElement, ASLayoutElementStylability, NSFastEnumeration>

/**
* Creation of a layout spec should only happen by a user in layoutSpecThatFits:. During that method, a
Expand Down
11 changes: 2 additions & 9 deletions Source/Layout/ASLayoutSpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ - (BOOL)canLayoutAsynchronous
return YES;
}

#pragma mark - Final LayoutElement

ASLayoutElementFinalLayoutElementDefault

#pragma mark - Style

- (ASLayoutElementStyle *)style
Expand Down Expand Up @@ -109,10 +105,7 @@ - (void)setChild:(id<ASLayoutElement>)child
ASDisplayNodeAssert(_childrenArray.count < 2, @"This layout spec does not support more than one child. Use the setChildren: or the setChild:AtIndex: API");

if (child) {
id<ASLayoutElement> finalLayoutElement = [self layoutElementToAddFromLayoutElement:child];
if (finalLayoutElement) {
_childrenArray[0] = finalLayoutElement;
}
_childrenArray[0] = child;
} else {
if (_childrenArray.count) {
[_childrenArray removeObjectAtIndex:0];
Expand All @@ -138,7 +131,7 @@ - (void)setChildren:(NSArray<id<ASLayoutElement>> *)children
NSUInteger i = 0;
for (id<ASLayoutElement> child in children) {
ASDisplayNodeAssert([child conformsToProtocol:NSProtocolFromString(@"ASLayoutElement")], @"Child %@ of spec %@ is not an ASLayoutElement!", child, self);
_childrenArray[i] = [self layoutElementToAddFromLayoutElement:child];
_childrenArray[i] = child;
i += 1;
}
}
Expand Down