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

Commit 4d71887

Browse files
committed
Merge branch 'master' into releases/p6.9
2 parents 953e2db + e58136d commit 4d71887

11 files changed

Lines changed: 52 additions & 180 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214
69E1006F1CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */; };
215215
69E100701CA89CB600D88C1B /* ASEnvironmentInternal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */; };
216216
69F10C871C84C35D0026140C /* ASRangeControllerUpdateRangeProtocol+Beta.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F10C851C84C35D0026140C /* ASRangeControllerUpdateRangeProtocol+Beta.h */; settings = {ATTRIBUTES = (Public, ); }; };
217-
69F6058D1D3DA27E00C8CA38 /* ASLayoutSpec+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F6058C1D3DA27E00C8CA38 /* ASLayoutSpec+Private.h */; };
218217
7630FFA81C9E267E007A7C0E /* ASVideoNode.h in Headers */ = {isa = PBXBuildFile; fileRef = AEEC47DF1C20C2DD00EC1693 /* ASVideoNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
219218
764D83D51C8EA515009B4FB8 /* AsyncDisplayKit+Debug.h in Headers */ = {isa = PBXBuildFile; fileRef = 764D83D21C8EA515009B4FB8 /* AsyncDisplayKit+Debug.h */; settings = {ATTRIBUTES = (Public, ); }; };
220219
764D83D61C8EA515009B4FB8 /* AsyncDisplayKit+Debug.m in Sources */ = {isa = PBXBuildFile; fileRef = 764D83D31C8EA515009B4FB8 /* AsyncDisplayKit+Debug.m */; };
@@ -966,7 +965,6 @@
966965
69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASEnvironmentInternal.h; sourceTree = "<group>"; };
967966
69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASEnvironmentInternal.mm; sourceTree = "<group>"; };
968967
69F10C851C84C35D0026140C /* ASRangeControllerUpdateRangeProtocol+Beta.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASRangeControllerUpdateRangeProtocol+Beta.h"; sourceTree = "<group>"; };
969-
69F6058C1D3DA27E00C8CA38 /* ASLayoutSpec+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ASLayoutSpec+Private.h"; sourceTree = "<group>"; };
970968
6BDC61F51978FEA400E50D21 /* AsyncDisplayKit.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; path = AsyncDisplayKit.h; sourceTree = "<group>"; };
971969
764D83D21C8EA515009B4FB8 /* AsyncDisplayKit+Debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AsyncDisplayKit+Debug.h"; sourceTree = "<group>"; };
972970
764D83D31C8EA515009B4FB8 /* AsyncDisplayKit+Debug.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AsyncDisplayKit+Debug.m"; sourceTree = "<group>"; };
@@ -1472,8 +1470,6 @@
14721470
044285051BAA63FE00D16268 /* ASBatchFetching.h */,
14731471
044285061BAA63FE00D16268 /* ASBatchFetching.m */,
14741472
251B8EF61BBB3D690087C538 /* ASDataController+Subclasses.h */,
1475-
8B0768B11CE752EC002E1453 /* ASDefaultPlaybackButton.h */,
1476-
8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */,
14771473
AEB7B0181C5962EA00662EF4 /* ASDefaultPlayButton.h */,
14781474
AEB7B0191C5962EA00662EF4 /* ASDefaultPlayButton.m */,
14791475
058D0A08195D050800B7D73C /* ASDisplayNode+AsyncDisplay.mm */,
@@ -1482,17 +1478,16 @@
14821478
DE6EA3211C14000600183B10 /* ASDisplayNode+FrameworkPrivate.h */,
14831479
058D0A0B195D050800B7D73C /* ASDisplayNode+UIViewBridge.mm */,
14841480
058D0A0C195D050800B7D73C /* ASDisplayNodeInternal.h */,
1481+
E52405B41C8FEF16004DC8E7 /* ASLayoutTransition.h */,
1482+
E52405B21C8FEF03004DC8E7 /* ASLayoutTransition.mm */,
14851483
69E100691CA89CB600D88C1B /* ASEnvironmentInternal.h */,
14861484
69E1006A1CA89CB600D88C1B /* ASEnvironmentInternal.mm */,
1487-
68B8A4DB1CBD911D007E4543 /* ASImageNode+AnimatedImagePrivate.h */,
14881485
058D0A0D195D050800B7D73C /* ASImageNode+CGExtras.h */,
14891486
058D0A0E195D050800B7D73C /* ASImageNode+CGExtras.m */,
1487+
68B8A4DB1CBD911D007E4543 /* ASImageNode+AnimatedImagePrivate.h */,
14901488
ACF6ED431B17847A00DA7C62 /* ASInternalHelpers.h */,
14911489
ACF6ED441B17847A00DA7C62 /* ASInternalHelpers.m */,
1492-
69F6058C1D3DA27E00C8CA38 /* ASLayoutSpec+Private.h */,
14931490
ACF6ED451B17847A00DA7C62 /* ASLayoutSpecUtilities.h */,
1494-
E52405B41C8FEF16004DC8E7 /* ASLayoutTransition.h */,
1495-
E52405B21C8FEF03004DC8E7 /* ASLayoutTransition.mm */,
14961491
0442850B1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.h */,
14971492
0442850C1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.mm */,
14981493
CC3B20811C3F76D600798563 /* ASPendingStateController.h */,
@@ -1510,6 +1505,8 @@
15101505
CC3B20881C3F7A5400798563 /* ASWeakSet.m */,
15111506
DBC452D91C5BF64600B16017 /* NSArray+Diffing.h */,
15121507
DBC452DA1C5BF64600B16017 /* NSArray+Diffing.m */,
1508+
8B0768B11CE752EC002E1453 /* ASDefaultPlaybackButton.h */,
1509+
8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */,
15131510
);
15141511
path = Private;
15151512
sourceTree = "<group>";
@@ -1743,7 +1740,6 @@
17431740
B350625B1B010F070018CF92 /* ASEqualityHelpers.h in Headers */,
17441741
680346941CE4052A0009FEB4 /* ASNavigationController.h in Headers */,
17451742
B350621B1B010EFD0018CF92 /* ASFlowLayoutController.h in Headers */,
1746-
69F6058D1D3DA27E00C8CA38 /* ASLayoutSpec+Private.h in Headers */,
17471743
B350621D1B010EFD0018CF92 /* ASHighlightOverlayLayer.h in Headers */,
17481744
C78F7E2B1BF7809800CDEAFC /* ASTableNode.h in Headers */,
17491745
AC7A2C181BDE11DF0093FE1A /* ASTableViewInternal.h in Headers */,

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,15 +2981,6 @@ - (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentT
29812981
}
29822982
}
29832983

2984-
#pragma mark - NSFastEnumeration
2985-
2986-
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
2987-
objects:(id __unsafe_unretained [])stackbuf
2988-
count:(NSUInteger)stackbufLength
2989-
{
2990-
return [self.children countByEnumeratingWithState:state objects:stackbuf count:stackbufLength];
2991-
}
2992-
29932984
ASEnvironmentLayoutOptionsForwarding
29942985
ASEnvironmentLayoutExtensibilityForwarding
29952986

AsyncDisplayKit/ASViewController.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ - (void)progagateNewEnvironmentTraitCollection:(ASEnvironmentTraitCollection)env
289289
self.node.environmentState = environmentState;
290290
[self.node setNeedsLayout];
291291

292-
for (id<ASEnvironment> child in self.node) {
292+
NSArray<id<ASEnvironment>> *children = [self.node children];
293+
for (id<ASEnvironment> child in children) {
293294
ASEnvironmentStatePropagateDown(child, environmentState.environmentTraitCollection);
294295
}
295296
}

AsyncDisplayKit/Details/ASEnvironment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ASDISPLAYNODE_EXTERN_C_END
9999
* defined in an ASEnvironmentState up and down the ASEnvironment tree. To be able to define how merges of
100100
* States should happen, specific merge functions can be provided
101101
*/
102-
@protocol ASEnvironment <NSObject, NSFastEnumeration>
102+
@protocol ASEnvironment <NSObject>
103103

104104
/// The environment collection of an object which class conforms to the ASEnvironment protocol
105105
- (ASEnvironmentState)environmentState;
@@ -126,7 +126,6 @@ ASDISPLAYNODE_EXTERN_C_END
126126

127127
/// sets a trait collection on this environment state.
128128
- (void)setEnvironmentTraitCollection:(ASEnvironmentTraitCollection)environmentTraitCollection;
129-
130129
@end
131130

132131
// ASCollection/TableNodes don't actually have ASCellNodes as subnodes. Because of this we can't rely on display trait

AsyncDisplayKit/Layout/ASLayoutSpec.mm

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// of patent rights can be found in the PATENTS file in the same directory.
99
//
1010

11-
#import "ASLayoutSpec+Private.h"
11+
#import "ASLayoutSpec.h"
1212

1313
#import "ASAssert.h"
1414
#import "ASEnvironmentInternal.h"
@@ -17,13 +17,16 @@
1717
#import "ASThread.h"
1818
#import "ASTraitCollection.h"
1919

20+
#import <objc/runtime.h>
21+
#import <map>
2022
#import <vector>
2123

24+
typedef std::map<unsigned long, id<ASLayoutable>, std::less<unsigned long>> ASChildMap;
25+
2226
@interface ASLayoutSpec() {
2327
ASEnvironmentState _environmentState;
2428
ASDN::RecursiveMutex __instanceLock__;
25-
ASChildrenMap _childrenMap;
26-
unsigned long _mutations;
29+
ASChildMap _children;
2730
}
2831
@end
2932

@@ -32,7 +35,6 @@ @implementation ASLayoutSpec
3235
// these dynamic properties all defined in ASLayoutOptionsPrivate.m
3336
@dynamic spacingAfter, spacingBefore, flexGrow, flexShrink, flexBasis,
3437
alignSelf, ascender, descender, sizeRange, layoutPosition, layoutableType;
35-
@synthesize parent = _parent;
3638
@synthesize isFinalLayoutable = _isFinalLayoutable;
3739

3840
- (instancetype)init
@@ -42,7 +44,6 @@ - (instancetype)init
4244
}
4345
_isMutable = YES;
4446
_environmentState = ASEnvironmentStateMakeDefault();
45-
_mutations = 0;
4647
return self;
4748
}
4849

@@ -104,8 +105,6 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
104105
return child;
105106
}
106107

107-
#pragma mark - Parent
108-
109108
- (void)setParent:(id<ASLayoutable>)parent
110109
{
111110
// FIXME: Locking should be evaluated here. _parent is not widely used yet, though.
@@ -116,33 +115,30 @@ - (void)setParent:(id<ASLayoutable>)parent
116115
}
117116
}
118117

119-
- (id<ASLayoutable>)parent
120-
{
121-
return _parent;
122-
}
123-
124-
#pragma mark - Children
125-
126118
- (void)setChild:(id<ASLayoutable>)child
127119
{
128-
[self setChild:child forIndex:0];
120+
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
121+
if (child) {
122+
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
123+
if (finalLayoutable) {
124+
_children[0] = finalLayoutable;
125+
[self propagateUpLayoutable:finalLayoutable];
126+
}
127+
} else {
128+
_children.erase(0);
129+
}
129130
}
130131

131132
- (void)setChild:(id<ASLayoutable>)child forIndex:(NSUInteger)index
132133
{
133134
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
134135
if (child) {
135136
id<ASLayoutable> finalLayoutable = [self layoutableToAddFromLayoutable:child];
136-
if (finalLayoutable) {
137-
_childrenMap[index] = finalLayoutable;
138-
[self propagateUpLayoutable:finalLayoutable];
139-
}
137+
_children[index] = finalLayoutable;
140138
} else {
141-
_childrenMap.erase(index);
139+
_children.erase(index);
142140
}
143-
_mutations++;
144-
145-
// TODO: Should we propagate up the layoutable as it could happen that multiple children will propagated up their
141+
// TODO: Should we propagate up the layoutable at it could happen that multiple children will propagated up their
146142
// layout options and one child will overwrite values from another child
147143
// [self propagateUpLayoutable:finalLayoutable];
148144
}
@@ -151,71 +147,35 @@ - (void)setChildren:(NSArray<id<ASLayoutable>> *)children
151147
{
152148
ASDisplayNodeAssert(self.isMutable, @"Cannot set properties when layout spec is not mutable");
153149

154-
_childrenMap.clear();
150+
_children.clear();
155151
NSUInteger i = 0;
156152
for (id<ASLayoutable> child in children) {
157-
_childrenMap[i] = [self layoutableToAddFromLayoutable:child];
153+
_children[i] = [self layoutableToAddFromLayoutable:child];
158154
i += 1;
159-
160-
_mutations++;
161155
}
162156
}
163157

164158
- (id<ASLayoutable>)childForIndex:(NSUInteger)index
165159
{
166-
if (index < _childrenMap.size()) {
167-
return _childrenMap[index];
160+
if (index < _children.size()) {
161+
return _children[index];
168162
}
169163
return nil;
170164
}
171165

172166
- (id<ASLayoutable>)child
173167
{
174-
return _childrenMap[0];
168+
return _children[0];
175169
}
176170

177171
- (NSArray *)children
178172
{
179-
// If used inside ASDK, the childrenMap property should be preferred over the children array to prevent
180-
// unecessary boxing
181173
std::vector<ASLayout *> children;
182-
for (auto const &entry : _childrenMap) {
183-
children.push_back(entry.second);
174+
for (ASChildMap::iterator it = _children.begin(); it != _children.end(); ++it ) {
175+
children.push_back(it->second);
184176
}
185-
186-
return [NSArray arrayWithObjects:&children[0] count:children.size()];
187-
}
188-
189-
#pragma mark - NSFastEnumeration
190-
191-
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
192-
objects:(id __unsafe_unretained [])stackbuf
193-
count:(NSUInteger)stackbufLength
194-
{
195-
NSUInteger count = 0;
196-
unsigned long countOfItemsAlreadyEnumerated = state->state;
197177

198-
if (countOfItemsAlreadyEnumerated == 0) {
199-
state->mutationsPtr = &_mutations;
200-
}
201-
202-
if (countOfItemsAlreadyEnumerated < _childrenMap.size()) {
203-
state->itemsPtr = stackbuf;
204-
205-
while((countOfItemsAlreadyEnumerated < _childrenMap.size()) && (count < stackbufLength)) {
206-
// Hold on for the object while enumerating
207-
__autoreleasing id child = _childrenMap[countOfItemsAlreadyEnumerated];
208-
stackbuf[count] = child;
209-
countOfItemsAlreadyEnumerated++;
210-
count++;
211-
}
212-
} else {
213-
count = 0;
214-
}
215-
216-
state->state = countOfItemsAlreadyEnumerated;
217-
218-
return count;
178+
return [NSArray arrayWithObjects:&children[0] count:children.size()];
219179
}
220180

221181
#pragma mark - ASEnvironment
@@ -273,15 +233,6 @@ - (ASTraitCollection *)asyncTraitCollection
273233

274234
@end
275235

276-
@implementation ASLayoutSpec (Private)
277-
278-
- (ASChildrenMap)childrenMap
279-
{
280-
return _childrenMap;
281-
}
282-
283-
@end
284-
285236
@implementation ASLayoutSpec (Debugging)
286237

287238
#pragma mark - ASLayoutableAsciiArtProtocol

AsyncDisplayKit/Layout/ASStackLayoutSpec.mm

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#import "ASInternalHelpers.h"
1515

16-
#import "ASLayoutSpec+Private.h"
1716
#import "ASLayoutSpecUtilities.h"
1817
#import "ASStackBaselinePositionedLayout.h"
1918
#import "ASThread.h"
@@ -59,7 +58,7 @@ - (instancetype)initWithDirection:(ASStackLayoutDirection)direction spacing:(CGF
5958
_alignItems = alignItems;
6059
_justifyContent = justifyContent;
6160

62-
self.children = children;
61+
[self setChildren:children];
6362
return self;
6463
}
6564

@@ -121,9 +120,7 @@ - (void)setBaselineRelativeArrangement:(BOOL)baselineRelativeArrangement
121120

122121
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
123122
{
124-
auto const &children = self.childrenMap;
125-
126-
if (children.size() == 0) {
123+
if (self.children.count == 0) {
127124
return [ASLayout layoutWithLayoutableObject:self
128125
constrainedSizeRange:constrainedSize
129126
size:constrainedSize.min];
@@ -132,9 +129,9 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
132129
ASStackLayoutSpecStyle style = {.direction = _direction, .spacing = _spacing, .justifyContent = _justifyContent, .alignItems = _alignItems, .baselineRelativeArrangement = _baselineRelativeArrangement};
133130
BOOL needsBaselinePass = _baselineRelativeArrangement || _alignItems == ASStackLayoutAlignItemsBaselineFirst || _alignItems == ASStackLayoutAlignItemsBaselineLast;
134131

135-
std::vector<id<ASLayoutable>> stackChildren;
136-
for (auto const &entry : children) {
137-
stackChildren.push_back(entry.second);
132+
std::vector<id<ASLayoutable>> stackChildren = std::vector<id<ASLayoutable>>();
133+
for (id<ASLayoutable> child in self.children) {
134+
stackChildren.push_back(child);
138135
}
139136

140137
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(stackChildren, style, constrainedSize);
@@ -146,18 +143,14 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
146143
// regardless of whether or not this stack aligns to baseline, we should let ASStackBaselinePositionedLayout::compute find the max ascender
147144
// and min descender in case this spec is a child in another spec that wants to align to a baseline.
148145
const auto baselinePositionedLayout = ASStackBaselinePositionedLayout::compute(positionedLayout, style, constrainedSize);
149-
{
146+
if (self.direction == ASStackLayoutDirectionVertical) {
147+
ASDN::MutexLocker l(__instanceLock__);
148+
self.ascender = [[self.children firstObject] ascender];
149+
self.descender = [[self.children lastObject] descender];
150+
} else {
150151
ASDN::MutexLocker l(__instanceLock__);
151-
if (self.direction == ASStackLayoutDirectionVertical) {
152-
if (stackChildren.size() > 0) {
153-
self.ascender = stackChildren.front().ascender;
154-
self.descender = stackChildren.back().descender;
155-
}
156-
157-
} else {
158-
self.ascender = baselinePositionedLayout.ascender;
159-
self.descender = baselinePositionedLayout.descender;
160-
}
152+
self.ascender = baselinePositionedLayout.ascender;
153+
self.descender = baselinePositionedLayout.descender;
161154
}
162155

163156
if (needsBaselinePass) {

AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#import "ASStaticLayoutSpec.h"
1212

13-
#import "ASLayoutSpec+Private.h"
1413
#import "ASLayoutSpecUtilities.h"
1514
#import "ASLayout.h"
1615

@@ -39,8 +38,10 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
3938
{
4039
CGSize maxConstrainedSize = CGSizeMake(constrainedSize.max.width, constrainedSize.max.height);
4140

42-
NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:self.childrenMap.size()];
43-
for (id<ASLayoutable> child in self) {
41+
NSArray *children = self.children;
42+
NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:children.count];
43+
44+
for (id<ASLayoutable> child in children) {
4445
CGPoint layoutPosition = child.layoutPosition;
4546
CGSize autoMaxSize = CGSizeMake(maxConstrainedSize.width - layoutPosition.x,
4647
maxConstrainedSize.height - layoutPosition.y);

AsyncDisplayKit/Private/ASEnvironmentInternal.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void ASEnvironmentPerformBlockOnObjectAndChildren(id<ASEnvironment> object, void
4444

4545
block(object);
4646

47-
for (id<ASEnvironment> child in object) {
47+
for (id<ASEnvironment> child in [object children]) {
4848
queue.push(child);
4949
}
5050
}

0 commit comments

Comments
 (0)