Revert "Initial commit to throw an exception if manually adding / removing subnodes if node has automaticallyManagesSubnodes enabled (#2214)"

This reverts commit 0d8518912e.
This commit is contained in:
Adlai Holler
2016-09-14 11:10:38 -07:00
parent a4b6942f00
commit ff8ec4d510
4 changed files with 7 additions and 72 deletions

View File

@@ -1572,12 +1572,6 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
}
- (void)addSubnode:(ASDisplayNode *)subnode
{
ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually add subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode);
[self _addSubnode:subnode];
}
- (void)_addSubnode:(ASDisplayNode *)subnode
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(__instanceLock__);
@@ -1593,7 +1587,7 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
if (isMovingEquivalentParents) {
[subnode __incrementVisibilityNotificationsDisabled];
}
[subnode _removeFromSupernode];
[subnode removeFromSupernode];
if (!_subnodes) {
_subnodes = [[NSMutableArray alloc] init];
@@ -1649,8 +1643,8 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
[subnode __incrementVisibilityNotificationsDisabled];
}
[subnode _removeFromSupernode];
[oldSubnode _removeFromSupernode];
[subnode removeFromSupernode];
[oldSubnode removeFromSupernode];
if (!_subnodes)
_subnodes = [[NSMutableArray alloc] init];
@@ -1686,12 +1680,6 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
}
- (void)replaceSubnode:(ASDisplayNode *)oldSubnode withSubnode:(ASDisplayNode *)replacementSubnode
{
ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually replace old node with replacement node to node with automaticallyManagesSubnodes=YES. Old Node: %@, replacement node: %@", oldSubnode, replacementSubnode);
[self _replaceSubnode:oldSubnode withSubnode:replacementSubnode];
}
- (void)_replaceSubnode:(ASDisplayNode *)oldSubnode withSubnode:(ASDisplayNode *)replacementSubnode
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(__instanceLock__);
@@ -1722,12 +1710,6 @@ static NSInteger incrementIfFound(NSInteger i) {
}
- (void)insertSubnode:(ASDisplayNode *)subnode belowSubnode:(ASDisplayNode *)below
{
ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode);
[self _insertSubnode:subnode belowSubnode:below];
}
- (void)_insertSubnode:(ASDisplayNode *)subnode belowSubnode:(ASDisplayNode *)below
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(__instanceLock__);
@@ -1773,12 +1755,6 @@ static NSInteger incrementIfFound(NSInteger i) {
}
- (void)insertSubnode:(ASDisplayNode *)subnode aboveSubnode:(ASDisplayNode *)above
{
ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode);
[self _insertSubnode:subnode aboveSubnode:above];
}
- (void)_insertSubnode:(ASDisplayNode *)subnode aboveSubnode:(ASDisplayNode *)above
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(__instanceLock__);
@@ -1827,12 +1803,6 @@ static NSInteger incrementIfFound(NSInteger i) {
}
- (void)insertSubnode:(ASDisplayNode *)subnode atIndex:(NSInteger)idx
{
ASDisplayNodeAssert(self.automaticallyManagesSubnodes == NO, @"Attempt to manually insert subnode to node with automaticallyManagesSubnodes=YES. Node: %@", subnode);
[self _insertSubnode:subnode atIndex:idx];
}
- (void)_insertSubnode:(ASDisplayNode *)subnode atIndex:(NSInteger)idx
{
ASDisplayNodeAssertThreadAffinity(self);
ASDN::MutexLocker l(__instanceLock__);
@@ -1903,18 +1873,10 @@ static NSInteger incrementIfFound(NSInteger i) {
[subnode __setSupernode:nil];
}
// NOTE: You must not called this method while holding the receiver's property lock. This may cause deadlocks.
- (void)removeFromSupernode
{
ASDisplayNodeAssert(self.supernode.automaticallyManagesSubnodes == NO, @"Attempt to manually remove subnode from node with automaticallyManagesSubnodes=YES. Node: %@", self);
[self _removeFromSupernode];
}
// NOTE: You must not called this method while holding the receiver's property lock. This may cause deadlocks.
- (void)_removeFromSupernode
{
ASDisplayNodeAssertThreadAffinity(self);
__instanceLock__.lock();
__weak ASDisplayNode *supernode = _supernode;
__weak UIView *view = _view;

View File

@@ -209,17 +209,6 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
- (void)__layout;
- (void)__setSupernode:(ASDisplayNode *)supernode;
/**
Internal method to add / replace / insert subnode and remove from supernode without checking if
node has automaticallyManagesSubnodes set to YES.
*/
- (void)_addSubnode:(ASDisplayNode *)subnode;
- (void)_replaceSubnode:(ASDisplayNode *)oldSubnode withSubnode:(ASDisplayNode *)replacementSubnode;
- (void)_insertSubnode:(ASDisplayNode *)subnode belowSubnode:(ASDisplayNode *)below;
- (void)_insertSubnode:(ASDisplayNode *)subnode aboveSubnode:(ASDisplayNode *)above;
- (void)_insertSubnode:(ASDisplayNode *)subnode atIndex:(NSInteger)idx;
- (void)_removeFromSupernode;
// Private API for helper functions / unit tests. Use ASDisplayNodeDisableHierarchyNotifications() to control this.
- (BOOL)__visibilityNotificationsDisabled;
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled;

View File

@@ -92,7 +92,7 @@ static inline BOOL ASLayoutCanTransitionAsynchronous(ASLayout *layout) {
NSUInteger i = 0;
for (ASDisplayNode *node in _insertedSubnodes) {
NSUInteger p = _insertedSubnodePositions[i];
[_node _insertSubnode:node atIndex:p];
[_node insertSubnode:node atIndex:p];
i += 1;
}
}
@@ -102,7 +102,7 @@ static inline BOOL ASLayoutCanTransitionAsynchronous(ASLayout *layout) {
ASDN::MutexSharedLocker l(__instanceLock__);
[self calculateSubnodeOperationsIfNeeded];
for (ASDisplayNode *subnode in _removedSubnodes) {
[subnode _removeFromSupernode];
[subnode removeFromSupernode];
}
}

View File

@@ -18,7 +18,6 @@
#import "ASStaticLayoutSpec.h"
#import "ASStackLayoutSpec.h"
#import "ASInsetLayoutSpec.h"
@interface ASSpecTestDisplayNode : ASDisplayNode
@@ -118,24 +117,9 @@
XCTAssertEqual(node.subnodes[2], node2);
}
- (void)testLayoutTransitionWillThrowForManualSubnodeManagement
{
ASDisplayNode *node1 = [[ASDisplayNode alloc] init];
node1.name = @"node1";
ASSpecTestDisplayNode *node = [[ASSpecTestDisplayNode alloc] init];
node.automaticallyManagesSubnodes = YES;
node.layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode *weakNode, ASSizeRange constrainedSize){
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[node1]];
};
XCTAssertNoThrow([node layoutThatFits:ASSizeRangeMake(CGSizeZero)]);
XCTAssertThrows([node1 removeFromSupernode]);
}
- (void)testLayoutTransitionMeasurementCompletionBlockIsCalledOnMainThread
{
ASDisplayNode *displayNode = [[ASDisplayNode alloc] init];
ASDisplayNode *displayNode = [ASDisplayNode new];
// Trigger explicit view creation to be able to use the Transition API
[displayNode view];