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

Commit 8e6f842

Browse files
Hannah Troisimaicki
authored andcommitted
[ASLayoutElementStyle] implement -description with sizing info (#2495)
* Layout style object debugging * Remove cocoapods crap
1 parent 6297fa5 commit 8e6f842

7 files changed

Lines changed: 104 additions & 30 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 24 additions & 20 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.

AsyncDisplayKit/Layout/ASDimension.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASLayoutSize ASLayoutSizeMake(ASDimen
208208
/*
209209
* Returns a string representation of a relative size.
210210
*/
211-
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT NSString *NSStringFromASLayoutSize(ASLayoutSize size);
211+
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT NSString *NSStringFromASLayoutSize(ASLayoutSize size)
212+
{
213+
return [NSString stringWithFormat:@"{%@, %@}",
214+
NSStringFromASDimension(size.width),
215+
NSStringFromASDimension(size.height)];
216+
}
212217

213218
#pragma mark - ASSizeRange
214219

AsyncDisplayKit/Layout/ASDimension.mm

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ ASDISPLAYNODE_INLINE CGSize ASLayoutSizeResolveSize(ASLayoutSize layoutSize, CGS
8181
ASDimensionResolve(layoutSize.height, parentSize.height, autoSize.height));
8282
}
8383

84-
// ** Returns a string formatted to contain the data from an ASLayoutSize. */
85-
ASDISPLAYNODE_INLINE NSString *NSStringFromASLayoutSize(ASLayoutSize size)
86-
{
87-
return [NSString stringWithFormat:@"{%@, %@}",
88-
NSStringFromASDimension(size.width),
89-
NSStringFromASDimension(size.height)];
90-
}
91-
9284

9385
#pragma mark - ASLayoutElementSize
9486

AsyncDisplayKit/Layout/ASLayoutElement.mm

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,77 @@ - (CGPoint)layoutPosition
437437
return _layoutPosition.load();
438438
}
439439

440+
#pragma mark - Debugging
441+
442+
- (NSString *)description
443+
{
444+
return ASObjectDescriptionMake(self, [self propertiesForDescription]);
445+
}
446+
447+
- (NSMutableArray<NSDictionary *> *)propertiesForDescription
448+
{
449+
NSMutableArray<NSDictionary *> *result = [NSMutableArray array];
450+
451+
if ((self.minLayoutSize.width.unit != ASDimensionUnitAuto ||
452+
self.minLayoutSize.height.unit != ASDimensionUnitAuto)) {
453+
[result addObject:@{ @"minLayoutSize" : NSStringFromASLayoutSize(self.minLayoutSize) }];
454+
}
455+
456+
if ((self.preferredLayoutSize.width.unit != ASDimensionUnitAuto ||
457+
self.preferredLayoutSize.height.unit != ASDimensionUnitAuto)) {
458+
[result addObject:@{ @"preferredSize" : NSStringFromASLayoutSize(self.preferredLayoutSize) }];
459+
}
460+
461+
if ((self.maxLayoutSize.width.unit != ASDimensionUnitAuto ||
462+
self.maxLayoutSize.height.unit != ASDimensionUnitAuto)) {
463+
[result addObject:@{ @"maxLayoutSize" : NSStringFromASLayoutSize(self.maxLayoutSize) }];
464+
}
465+
466+
const ASEnvironmentLayoutOptionsState defaultState = ASEnvironmentLayoutOptionsStateMakeDefault();
467+
468+
if (self.alignSelf != defaultState.alignSelf) {
469+
[result addObject:@{ @"alignSelf" : [@[@"ASStackLayoutAlignSelfAuto",
470+
@"ASStackLayoutAlignSelfStart",
471+
@"ASStackLayoutAlignSelfEnd",
472+
@"ASStackLayoutAlignSelfCenter",
473+
@"ASStackLayoutAlignSelfStretch"] objectAtIndex:self.alignSelf] }];
474+
}
475+
476+
if (self.ascender != defaultState.ascender) {
477+
[result addObject:@{ @"ascender" : @(self.ascender) }];
478+
}
479+
480+
if (self.descender != defaultState.descender) {
481+
[result addObject:@{ @"descender" : @(self.descender) }];
482+
}
483+
484+
if (ASDimensionEqualToDimension(self.flexBasis, defaultState.flexBasis) == NO) {
485+
[result addObject:@{ @"flexBasis" : NSStringFromASDimension(self.flexBasis) }];
486+
}
487+
488+
if (self.flexGrow != defaultState.flexGrow) {
489+
[result addObject:@{ @"flexGrow" : @(self.flexGrow) }];
490+
}
491+
492+
if (self.flexShrink != defaultState.flexShrink) {
493+
[result addObject:@{ @"flexShrink" : @(self.flexShrink) }];
494+
}
495+
496+
if (self.spacingAfter != defaultState.spacingAfter) {
497+
[result addObject:@{ @"spacingAfter" : @(self.spacingAfter) }];
498+
}
499+
500+
if (self.spacingBefore != defaultState.spacingBefore) {
501+
[result addObject:@{ @"spacingBefore" : @(self.spacingBefore) }];
502+
}
503+
504+
if (CGPointEqualToPoint(self.layoutPosition, defaultState.layoutPosition) == NO) {
505+
[result addObject:@{ @"layoutPosition" : [NSValue valueWithCGPoint:self.layoutPosition] }];
506+
}
507+
508+
return result;
509+
}
510+
440511
#pragma mark Deprecated
441512

442513
#pragma clang diagnostic push

AsyncDisplayKit/Layout/ASLayoutElementStylePrivate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
#pragma once
1212

13-
@interface ASLayoutElementStyle ()
13+
#import "ASObjectDescriptionHelpers.h"
14+
15+
@interface ASLayoutElementStyle () <ASDescriptionProvider>
1416

1517
/**
1618
* @abstract The object that acts as the delegate of the style.

0 commit comments

Comments
 (0)