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

Commit f912657

Browse files
appleguyAdlai Holler
authored andcommitted
[Yoga] Initial commit for supporting Yoga-powered layout calculation. (#2982)
* [Yoga + AsyncDisplayKit] Initial commit for supporting Yoga-powered layout calculation. Because this results in ASLayout objects, it preserve support for automaticallyManagesSubnodes as well as the animated transition system. More work remains to vet performance of the new mode, and it will remain in +Beta for the forseeable future. I'm not sure that this should ever be used as the primary ASDK layout system, but it should remain an option for some apps to experiment with if they require an implementation that more strictly mirrors W3C standard Flexbox. * [Yoga] Improve usage of ASHierarchyState to ensure simultaneous yoga layouts can't happen. * [Yoga] Strictly minimize the impact of the Yoga integration on existing code. Created new file ASDisplayNode+Yoga.mm, reduced size and number of integration points in core code. * [Yoga] Figured out how to further reduce ASDisplayNode.mm impact by allocating _yogaNode in property accessor, and changing all accesses to use the property.
1 parent 5c8818d commit f912657

14 files changed

Lines changed: 585 additions & 34 deletions

AsyncDisplayKit.podspec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,25 @@ Pod::Spec.new do |spec|
4444
end
4545

4646
spec.subspec 'PINRemoteImage' do |pin|
47+
# Note: The core.prefix_header_file includes setup of PIN_REMOTE_IMAGE, so the line below could be removed.
4748
pin.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) PIN_REMOTE_IMAGE=1' }
4849
pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.7'
4950
pin.dependency 'PINRemoteImage/PINCache'
5051
pin.dependency 'AsyncDisplayKit/Core'
5152
end
5253

5354
spec.subspec 'IGListKit' do |igl|
55+
# Note: The core.prefix_header_file includes setup of IG_LIST_KIT, so the line below could be removed.
5456
igl.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) IG_LIST_KIT=1' }
5557
igl.dependency 'IGListKit', '2.1.0'
5658
igl.dependency 'AsyncDisplayKit/Core'
5759
end
5860

61+
spec.subspec 'Yoga' do |yoga|
62+
yoga.dependency 'Yoga', '1.0.2'
63+
yoga.dependency 'AsyncDisplayKit/Core'
64+
end
65+
5966
# Include optional PINRemoteImage module
6067
spec.default_subspec = 'PINRemoteImage'
6168

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
8BBBAB8D1CEBAF1E00107FC6 /* ASDefaultPlaybackButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */; };
178178
8BDA5FC71CDBDF91007D13B2 /* ASVideoPlayerNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDA5FC31CDBDDE1007D13B2 /* ASVideoPlayerNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
179179
8BDA5FC81CDBDF95007D13B2 /* ASVideoPlayerNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8BDA5FC41CDBDDE1007D13B2 /* ASVideoPlayerNode.mm */; };
180+
90FC784F1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm in Sources */ = {isa = PBXBuildFile; fileRef = 90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */; };
180181
92DD2FE61BF4D05E0074C9DD /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92DD2FE51BF4D05E0074C9DD /* MapKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
181182
92DD2FE71BF4D0850074C9DD /* ASMapNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */; };
182183
92DD2FE81BF4D0A80074C9DD /* ASMapNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 92DD2FE11BF4B97E0074C9DD /* ASMapNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -613,6 +614,7 @@
613614
8B0768B21CE752EC002E1453 /* ASDefaultPlaybackButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASDefaultPlaybackButton.m; sourceTree = "<group>"; };
614615
8BDA5FC31CDBDDE1007D13B2 /* ASVideoPlayerNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASVideoPlayerNode.h; sourceTree = "<group>"; };
615616
8BDA5FC41CDBDDE1007D13B2 /* ASVideoPlayerNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASVideoPlayerNode.mm; sourceTree = "<group>"; };
617+
90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "ASDisplayNode+Yoga.mm"; sourceTree = "<group>"; };
616618
92DD2FE11BF4B97E0074C9DD /* ASMapNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASMapNode.h; sourceTree = "<group>"; };
617619
92DD2FE21BF4B97E0074C9DD /* ASMapNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASMapNode.mm; sourceTree = "<group>"; };
618620
92DD2FE51BF4D05E0074C9DD /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
@@ -893,6 +895,7 @@
893895
058D09D8195D050800B7D73C /* ASDisplayNode.h */,
894896
058D09D9195D050800B7D73C /* ASDisplayNode.mm */,
895897
68B027791C1A79CC0041016B /* ASDisplayNode+Beta.h */,
898+
90FC784E1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm */,
896899
683489271D70DE3400327501 /* ASDisplayNode+Deprecated.h */,
897900
058D09DA195D050800B7D73C /* ASDisplayNode+Subclasses.h */,
898901
058D09DB195D050800B7D73C /* ASDisplayNodeExtras.h */,
@@ -1902,6 +1905,7 @@
19021905
34EFC76F1B701CF700AD841F /* ASRatioLayoutSpec.mm in Sources */,
19031906
254C6B8B1BF94F8A003EC431 /* ASTextKitShadower.mm in Sources */,
19041907
254C6B851BF94F8A003EC431 /* ASTextKitAttributes.mm in Sources */,
1908+
90FC784F1E4BFE1B00383C5A /* ASDisplayNode+Yoga.mm in Sources */,
19051909
509E68601B3AED8E009B9150 /* ASScrollDirection.m in Sources */,
19061910
B35062091B010EFD0018CF92 /* ASScrollNode.mm in Sources */,
19071911
8BDA5FC81CDBDF95007D13B2 /* ASVideoPlayerNode.mm in Sources */,

AsyncDisplayKit/ASDisplayNode+Beta.h

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

11+
#import <AsyncDisplayKit/ASAvailability.h>
1112
#import <AsyncDisplayKit/ASDisplayNode.h>
1213
#import <AsyncDisplayKit/ASLayoutRangeType.h>
1314
#import <AsyncDisplayKit/ASEventLog.h>
@@ -20,15 +21,15 @@ void ASPerformBlockOnBackgroundThread(void (^block)()); // DISPATCH_QUEUE_PRIORI
2021
ASDISPLAYNODE_EXTERN_C_END
2122

2223
#if ASEVENTLOG_ENABLE
23-
#define ASDisplayNodeLogEvent(node, ...) [node.eventLog logEventWithBacktrace:(AS_SAVE_EVENT_BACKTRACES ? [NSThread callStackSymbols] : nil) format:__VA_ARGS__]
24+
#define ASDisplayNodeLogEvent(node, ...) [node.eventLog logEventWithBacktrace:(AS_SAVE_EVENT_BACKTRACES ? [NSThread callStackSymbols] : nil) format:__VA_ARGS__]
2425
#else
25-
#define ASDisplayNodeLogEvent(node, ...)
26+
#define ASDisplayNodeLogEvent(node, ...)
2627
#endif
2728

2829
#if ASEVENTLOG_ENABLE
29-
#define ASDisplayNodeGetEventLog(node) node.eventLog
30+
#define ASDisplayNodeGetEventLog(node) node.eventLog
3031
#else
31-
#define ASDisplayNodeGetEventLog(node) nil
32+
#define ASDisplayNodeGetEventLog(node) nil
3233
#endif
3334

3435
/**
@@ -147,4 +148,38 @@ typedef struct {
147148

148149
@end
149150

151+
#pragma mark - Yoga Layout Support
152+
153+
#if YOGA
154+
155+
@interface ASDisplayNode (Yoga)
156+
157+
@property (nonatomic, strong) NSArray *yogaChildren;
158+
159+
- (void)addYogaChild:(ASDisplayNode *)child;
160+
- (void)removeYogaChild:(ASDisplayNode *)child;
161+
162+
// This method should not normally be called directly.
163+
- (ASLayout *)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize;
164+
165+
@end
166+
167+
@interface ASLayoutElementStyle (Yoga)
168+
169+
@property (nonatomic, assign, readwrite) ASStackLayoutDirection direction;
170+
@property (nonatomic, assign, readwrite) CGFloat spacing;
171+
@property (nonatomic, assign, readwrite) ASStackLayoutJustifyContent justifyContent;
172+
@property (nonatomic, assign, readwrite) ASStackLayoutAlignItems alignItems;
173+
@property (nonatomic, assign, readwrite) YGPositionType positionType;
174+
@property (nonatomic, assign, readwrite) ASEdgeInsets position;
175+
@property (nonatomic, assign, readwrite) ASEdgeInsets margin;
176+
@property (nonatomic, assign, readwrite) ASEdgeInsets padding;
177+
@property (nonatomic, assign, readwrite) ASEdgeInsets border;
178+
@property (nonatomic, assign, readwrite) CGFloat aspectRatio;
179+
@property (nonatomic, assign, readwrite) YGWrap flexWrap;
180+
181+
@end
182+
183+
#endif
184+
150185
NS_ASSUME_NONNULL_END

AsyncDisplayKit/ASDisplayNode+Subclasses.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ NS_ASSUME_NONNULL_BEGIN
232232
/** @name Observing node state changes */
233233

234234
/**
235-
* Declare <ASInterfaceState> methods as requiring super calls (this can't be required in the protocol).
236-
* For descriptions, see <ASInterfaceState> definition.
235+
* Declare <ASInterfaceStateDelegate> methods as requiring super calls (this can't be required in the protocol).
236+
* For descriptions, see <ASInterfaceStateDelegate> definition.
237237
*/
238238

239239
- (void)didEnterVisibleState ASDISPLAYNODE_REQUIRES_SUPER;

0 commit comments

Comments
 (0)