diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c8c16702..be0b6639c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Source/ASDisplayNode.h b/Source/ASDisplayNode.h index 53862ab7c6..ef78ad8456 100644 --- a/Source/ASDisplayNode.h +++ b/Source/ASDisplayNode.h @@ -121,7 +121,7 @@ extern NSInteger const ASDefaultDrawingPriority; * */ -@interface ASDisplayNode : NSObject +@interface ASDisplayNode : NSObject /** @name Initializing a node object */ diff --git a/Source/ASDisplayNode.mm b/Source/ASDisplayNode.mm index d10d646846..5e14b6389b 100644 --- a/Source/ASDisplayNode.mm +++ b/Source/ASDisplayNode.mm @@ -866,8 +866,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c) return !self.isNodeLoaded; } -ASLayoutElementFinalLayoutElementDefault - #pragma mark - (NSString *)debugName diff --git a/Source/Details/ASDataController.mm b/Source/Details/ASDataController.mm index 6f3ee8d2a8..1f2aca1361 100644 --- a/Source/Details/ASDataController.mm +++ b/Source/Details/ASDataController.mm @@ -334,7 +334,6 @@ typedef void (^ASDataControllerCompletionBlock)(NSArray * * * @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 */ @@ -360,7 +359,6 @@ typedef void (^ASDataControllerCompletionBlock)(NSArray * * @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 */ diff --git a/Source/Layout/ASLayoutElementPrivate.h b/Source/Layout/ASLayoutElementPrivate.h index a0855ed0b0..a7f4b16f1e 100644 --- a/Source/Layout/ASLayoutElementPrivate.h +++ b/Source/Layout/ASLayoutElementPrivate.h @@ -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 - -/** - * @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)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)finalLayoutElement\ -{\ - return self;\ -}\ - #pragma mark - ASLayoutElementExtensibility diff --git a/Source/Layout/ASLayoutSpec+Subclasses.h b/Source/Layout/ASLayoutSpec+Subclasses.h index 74eacaf44f..21c97cb8b6 100644 --- a/Source/Layout/ASLayoutSpec+Subclasses.h +++ b/Source/Layout/ASLayoutSpec+Subclasses.h @@ -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)finalLayoutElement - * { - * ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init]; - * insetSpec.insets = UIEdgeInsetsMake(10,10,10,10); - * insetSpec.isFinalLayoutElement = YES; - * [insetSpec setChild:self]; - * return insetSpec; - * } - * - * @see finalLayoutElement - */ -- (id)layoutElementToAddFromLayoutElement:(id)child; - /** * Adds a child with the given identifier to this layout spec. * diff --git a/Source/Layout/ASLayoutSpec+Subclasses.mm b/Source/Layout/ASLayoutSpec+Subclasses.mm index 605e7f5423..561d94e844 100644 --- a/Source/Layout/ASLayoutSpec+Subclasses.mm +++ b/Source/Layout/ASLayoutSpec+Subclasses.mm @@ -56,27 +56,13 @@ @implementation ASLayoutSpec (Subclassing) -#pragma mark - Final layoutElement - -- (id)layoutElementToAddFromLayoutElement:(id)child -{ - if (self.isFinalLayoutElement == NO) { - id finalLayoutElement = [child finalLayoutElement]; - if (finalLayoutElement != child) { - finalLayoutElement.primitiveTraitCollection = child.primitiveTraitCollection; - return finalLayoutElement; - } - } - return child; -} - #pragma mark - Child with index - (void)setChild:(id)child atIndex:(NSUInteger)index { ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable"); - id layoutElement = child ? [self layoutElementToAddFromLayoutElement:child] : [ASNullLayoutSpec null]; + id layoutElement = child ?: [ASNullLayoutSpec null]; if (child) { if (_childrenArray.count < index) { diff --git a/Source/Layout/ASLayoutSpec.h b/Source/Layout/ASLayoutSpec.h index 5cb6cb3f87..0ca4eba87b 100644 --- a/Source/Layout/ASLayoutSpec.h +++ b/Source/Layout/ASLayoutSpec.h @@ -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 +@interface ASLayoutSpec : NSObject /** * Creation of a layout spec should only happen by a user in layoutSpecThatFits:. During that method, a diff --git a/Source/Layout/ASLayoutSpec.mm b/Source/Layout/ASLayoutSpec.mm index fd37f9e6db..482edfacc7 100644 --- a/Source/Layout/ASLayoutSpec.mm +++ b/Source/Layout/ASLayoutSpec.mm @@ -71,10 +71,6 @@ return YES; } -#pragma mark - Final LayoutElement - -ASLayoutElementFinalLayoutElementDefault - #pragma mark - Style - (ASLayoutElementStyle *)style @@ -109,10 +105,7 @@ ASLayoutElementLayoutCalculationDefaults 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 finalLayoutElement = [self layoutElementToAddFromLayoutElement:child]; - if (finalLayoutElement) { - _childrenArray[0] = finalLayoutElement; - } + _childrenArray[0] = child; } else { if (_childrenArray.count) { [_childrenArray removeObjectAtIndex:0]; @@ -138,7 +131,7 @@ ASLayoutElementLayoutCalculationDefaults NSUInteger i = 0; for (id 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; } }