[ASTextKitFontSizeAdjuster] Use the constrainedSize’s height to adjust font scaling (#2309)

* refactor shrinking logic

# Conflicts:
#	AsyncDisplayKit/TextKit/ASTextKitFontSizeAdjuster.mm

* fix ASTraitCollection sample

* updated comments.

* fix build errors

* adlai’s comments
This commit is contained in:
ricky
2016-10-04 10:01:50 -07:00
committed by Adlai Holler
parent d6e5e27c39
commit 872aad220f
4 changed files with 54 additions and 51 deletions

View File

@@ -77,7 +77,7 @@ static const CGFloat kInnerPadding = 10.0f;
// kitten image, with a solid background colour serving as placeholder
_imageNode = [[ASNetworkImageNode alloc] init];
_imageNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
_imageNode.size = ASRelativeSizeRangeMakeWithExactCGSize(_kittenSize);
_imageNode.style.size = (ASLayoutableSize){ .width = ASDimensionMake(_kittenSize.width), .height = ASDimensionMake(_kittenSize.height) };
[_imageNode addTarget:self action:@selector(imageTapped:) forControlEvents:ASControlNodeEventTouchUpInside];
CGFloat scale = [UIScreen mainScreen].scale;
@@ -91,8 +91,8 @@ static const CGFloat kInnerPadding = 10.0f;
_textNode = [[ASTextNode alloc] init];
_textNode.attributedText = [[NSAttributedString alloc] initWithString:[self kittyIpsum]
attributes:[self textStyle]];
_textNode.flexShrink = YES;
_textNode.flexGrow = YES;
_textNode.style.flexShrink = YES;
_textNode.style.flexGrow = YES;
[self addSubnode:_textNode];
return self;
@@ -141,10 +141,10 @@ static const CGFloat kInnerPadding = 10.0f;
[stackSpec setChildren:@[_imageNode, _textNode]];
if (self.asyncTraitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular) {
_imageNode.alignSelf = ASStackLayoutAlignSelfStart;
_imageNode.style.alignSelf = ASStackLayoutAlignSelfStart;
stackSpec.direction = ASStackLayoutDirectionHorizontal;
} else {
_imageNode.alignSelf = ASStackLayoutAlignSelfCenter;
_imageNode.style.alignSelf = ASStackLayoutAlignSelfCenter;
stackSpec.direction = ASStackLayoutDirectionVertical;
}