Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 13a35c5

Browse files
committed
more comments
* allow nil for setChild/children * moved examples out of examples/
1 parent 01dbc86 commit 13a35c5

27 files changed

Lines changed: 59 additions & 1237 deletions

AsyncDisplayKit/ASCollectionNode.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "ASCollectionViewLayoutFacilitatorProtocol.h"
1212
#import "ASDisplayNode+Subclasses.h"
1313
#import "ASEnvironmentInternal.h"
14+
#import "ASInternalHelpers.h"
1415
#import "ASRangeControllerUpdateRangeProtocol+Beta.h"
1516
#include <vector>
1617

AsyncDisplayKit/ASTableNode.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
//
88

99
#import "ASEnvironmentInternal.h"
10-
#import "ASFlowLayoutController.h"
11-
#import "ASTableViewInternal.h"
1210
#import "ASDisplayNode+Subclasses.h"
11+
#import "ASFlowLayoutController.h"
12+
#import "ASInternalHelpers.h"
1313
#import "ASRangeControllerUpdateRangeProtocol+Beta.h"
14+
#import "ASTableViewInternal.h"
1415

1516
@interface _ASTablePendingState : NSObject
1617
@property (weak, nonatomic) id <ASTableDelegate> delegate;

AsyncDisplayKit/Details/ASEnvironment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ASDISPLAYNODE_EXTERN_C_END
156156
[super setEnvironmentState:environmentState];\
157157
ASEnvironmentTraitCollection currentTraits = environmentState.environmentTraitCollection;\
158158
if (ASEnvironmentTraitCollectionIsEqualToASEnvironmentTraitCollection(currentTraits, oldTraits) == NO) {\
159-
dispatch_async(dispatch_get_main_queue(), ^{\
159+
ASPerformBlockOnMainThread(^{\
160160
NSArray<NSArray <ASCellNode *> *> *completedNodes = [self.view.dataController completedNodes];\
161161
for (NSArray *sectionArray in completedNodes) {\
162162
for (ASCellNode *cellNode in sectionArray) {\

AsyncDisplayKit/Layout/ASLayoutSpec.mm

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (instancetype)init
4444
}
4545
_isMutable = YES;
4646
_environmentState = ASEnvironmentStateMakeDefault();
47-
47+
_children = [NSArray array];
4848
return self;
4949
}
5050

@@ -115,24 +115,35 @@ - (void)setParent:(id<ASLayoutable>)parent
115115
- (void)setChild:(id<ASLayoutable>)child
116116
{
117117
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
118-
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
119-
120-
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
121-
if (finalLayoutable) {
122-
_children = @[finalLayoutable];
123-
[self propagateUpLayoutable:finalLayoutable];
118+
if (child) {
119+
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
120+
if (finalLayoutable) {
121+
_children = @[finalLayoutable];
122+
[self propagateUpLayoutable:finalLayoutable];
123+
}
124+
} else {
125+
// remove the only child
126+
_children = [NSArray array];
124127
}
125128
}
126129

127130
- (void)setChild:(id<ASLayoutable>)child forIdentifier:(NSString *)identifier
128131
{
129132
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
130-
ASDisplayNodeAssertNotNil(child, @"Child cannot be nil");
131-
132-
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
133-
self.childrenWithIdentifier[identifier] = finalLayoutable;
134-
if (finalLayoutable) {
135-
self.children = [self.children arrayByAddingObject:finalLayoutable];
133+
if (child) {
134+
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
135+
self.childrenWithIdentifier[identifier] = finalLayoutable;
136+
if (finalLayoutable) {
137+
_children = [_children arrayByAddingObject:finalLayoutable];
138+
}
139+
} else {
140+
id<ASLayoutable> oldChild = self.childrenWithIdentifier[identifier];
141+
if (oldChild) {
142+
self.childrenWithIdentifier[identifier] = nil;
143+
NSMutableArray *mutableChildren = [_children mutableCopy];
144+
[mutableChildren removeObject:oldChild];
145+
_children = [mutableChildren copy];
146+
}
136147
}
137148

138149
// TODO: Should we propagate up the layoutable at it could happen that multiple children will propagated up their
@@ -152,6 +163,8 @@ - (void)setChildren:(NSArray<id<ASLayoutable>> *)children
152163
_children = nil;
153164
if (finalChildren.size() > 0) {
154165
_children = [NSArray arrayWithObjects:&finalChildren[0] count:finalChildren.size()];
166+
} else {
167+
_children = [NSArray array];
155168
}
156169
}
157170

@@ -167,7 +180,7 @@ - (void)setChildren:(NSArray<id<ASLayoutable>> *)children
167180

168181
- (NSArray *)children
169182
{
170-
return [_children copy];
183+
return _children;
171184
}
172185

173186
- (void)setTraitCollection:(ASTraitCollection *)traitCollection

examples/ASTraitCollection/Podfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)