From eb9f86cfdbce41204009bb7922b82a1bc77c5ecf Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 17 Jun 2016 10:34:45 -0700 Subject: [PATCH 1/4] Replace "percent" with "fraction" where appropriate --- AsyncDisplayKit/ASImageNode.h | 2 +- AsyncDisplayKit/Layout/ASDimension.h | 4 ++-- AsyncDisplayKit/Layout/ASDimension.mm | 10 +++++----- AsyncDisplayKit/Layout/ASInsetLayoutSpec.h | 2 +- AsyncDisplayKit/Layout/ASLayoutable.h | 2 +- AsyncDisplayKit/Layout/ASStaticLayoutable.h | 2 +- AsyncDisplayKit/Private/ASImageNode+CGExtras.h | 2 +- AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/AsyncDisplayKit/ASImageNode.h b/AsyncDisplayKit/ASImageNode.h index c733a66459..35cbb068d6 100644 --- a/AsyncDisplayKit/ASImageNode.h +++ b/AsyncDisplayKit/ASImageNode.h @@ -83,7 +83,7 @@ typedef UIImage * _Nullable (^asimagenode_modification_block_t)(UIImage *image); * * @discussion This value defines a rectangle that is to be featured by the * receiver. The rectangle is specified as a "unit rectangle," using - * percentages of the source image's width and height, e.g. CGRectMake(0.5, 0, + * fractions of the source image's width and height, e.g. CGRectMake(0.5, 0, * 0.5, 1.0) will feature the full right half a photo. If the cropRect is * empty, the content mode of the receiver will be used to determine its * dimensions, and only the cropRect's origin will be used for positioning. The diff --git a/AsyncDisplayKit/Layout/ASDimension.h b/AsyncDisplayKit/Layout/ASDimension.h index 822a1c1963..79e7e2f64b 100644 --- a/AsyncDisplayKit/Layout/ASDimension.h +++ b/AsyncDisplayKit/Layout/ASDimension.h @@ -17,7 +17,7 @@ typedef NS_ENUM(NSInteger, ASRelativeDimensionType) { /** Just a number. It will always resolve to exactly this amount. This is the default type. */ ASRelativeDimensionTypePoints, /** Multiplied to a provided parent amount to resolve a final amount. */ - ASRelativeDimensionTypePercent, + ASRelativeDimensionTypeFraction, }; typedef struct { @@ -44,7 +44,7 @@ extern ASRelativeDimension ASRelativeDimensionMake(ASRelativeDimensionType type, extern ASRelativeDimension ASRelativeDimensionMakeWithPoints(CGFloat points); -extern ASRelativeDimension ASRelativeDimensionMakeWithPercent(CGFloat percent); +extern ASRelativeDimension ASRelativeDimensionMakeWithFraction(CGFloat fraction); extern ASRelativeDimension ASRelativeDimensionCopy(ASRelativeDimension aDimension); diff --git a/AsyncDisplayKit/Layout/ASDimension.mm b/AsyncDisplayKit/Layout/ASDimension.mm index d7309d7370..5859830c56 100644 --- a/AsyncDisplayKit/Layout/ASDimension.mm +++ b/AsyncDisplayKit/Layout/ASDimension.mm @@ -32,10 +32,10 @@ ASRelativeDimension ASRelativeDimensionMakeWithPoints(CGFloat points) return ASRelativeDimensionMake(ASRelativeDimensionTypePoints, points); } -ASRelativeDimension ASRelativeDimensionMakeWithPercent(CGFloat percent) +ASRelativeDimension ASRelativeDimensionMakeWithFraction(CGFloat fraction) { - // ASDisplayNodeCAssert( 0 <= percent && percent <= 1.0, @"ASRelativeDimension percent value (%f) must be between 0 and 1.", percent); - return ASRelativeDimensionMake(ASRelativeDimensionTypePercent, percent); + // ASDisplayNodeCAssert( 0 <= fraction && fraction <= 1.0, @"ASRelativeDimension fraction value (%f) must be between 0 and 1.", fraction); + return ASRelativeDimensionMake(ASRelativeDimensionTypeFraction, fraction); } ASRelativeDimension ASRelativeDimensionCopy(ASRelativeDimension aDimension) @@ -53,7 +53,7 @@ NSString *NSStringFromASRelativeDimension(ASRelativeDimension dimension) switch (dimension.type) { case ASRelativeDimensionTypePoints: return [NSString stringWithFormat:@"%.0fpt", dimension.value]; - case ASRelativeDimensionTypePercent: + case ASRelativeDimensionTypeFraction: return [NSString stringWithFormat:@"%.0f%%", dimension.value * 100.0]; } } @@ -63,7 +63,7 @@ CGFloat ASRelativeDimensionResolve(ASRelativeDimension dimension, CGFloat parent switch (dimension.type) { case ASRelativeDimensionTypePoints: return dimension.value; - case ASRelativeDimensionTypePercent: + case ASRelativeDimensionTypeFraction: return dimension.value * parent; } } diff --git a/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h b/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h index 9584094226..b41e66fb5f 100644 --- a/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h +++ b/AsyncDisplayKit/Layout/ASInsetLayoutSpec.h @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN /** A layout spec that wraps another layoutable child, applying insets around it. - If the child has a size specified as a percentage, the percentage is resolved against this spec's parent + If the child has a size specified as a fraction, the fraction is resolved against this spec's parent size **after** applying insets. @example ASOuterLayoutSpec contains an ASInsetLayoutSpec with an ASInnerLayoutSpec. Suppose that: diff --git a/AsyncDisplayKit/Layout/ASLayoutable.h b/AsyncDisplayKit/Layout/ASLayoutable.h index 0f68d5e2dd..ad1d1f8b92 100644 --- a/AsyncDisplayKit/Layout/ASLayoutable.h +++ b/AsyncDisplayKit/Layout/ASLayoutable.h @@ -117,7 +117,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - ASStaticLayoutable /** - If specified, the child's size is restricted according to this size. Percentages are resolved relative to the static layout spec. + If specified, the child's size is restricted according to this size. Fractions are resolved relative to the static layout spec. */ @property (nonatomic, assign) ASRelativeSizeRange sizeRange; diff --git a/AsyncDisplayKit/Layout/ASStaticLayoutable.h b/AsyncDisplayKit/Layout/ASStaticLayoutable.h index 825b6ac40e..d1c3f74806 100644 --- a/AsyncDisplayKit/Layout/ASStaticLayoutable.h +++ b/AsyncDisplayKit/Layout/ASStaticLayoutable.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol ASStaticLayoutable /** - If specified, the child's size is restricted according to this size. Percentages are resolved relative to the static layout spec. + If specified, the child's size is restricted according to this size. Fractions are resolved relative to the static layout spec. */ @property (nonatomic, assign) ASRelativeSizeRange sizeRange; diff --git a/AsyncDisplayKit/Private/ASImageNode+CGExtras.h b/AsyncDisplayKit/Private/ASImageNode+CGExtras.h index 74471ad62d..52b2109c50 100644 --- a/AsyncDisplayKit/Private/ASImageNode+CGExtras.h +++ b/AsyncDisplayKit/Private/ASImageNode+CGExtras.h @@ -20,7 +20,7 @@ ASDISPLAYNODE_EXTERN_C_BEGIN @param sourceImageSize The size of the encoded image. @param boundsSize The bounds in which the image will be displayed. @param contentMode The mode that defines how image will be scaled and cropped to fit. Supported values are UIViewContentModeScaleToAspectFill and UIViewContentModeScaleToAspectFit. - @param cropRect A rectangle that is to be featured by the cropped image. The rectangle is specified as a "unit rectangle," using percentages of the source image's width and height, e.g. CGRectMake(0.5, 0, 0.5, 1.0) will feature the full right half a photo. If the cropRect is empty, the contentMode will be used to determine the drawRect's size, and only the cropRect's origin will be used for positioning. + @param cropRect A rectangle that is to be featured by the cropped image. The rectangle is specified as a "unit rectangle," using fractions of the source image's width and height, e.g. CGRectMake(0.5, 0, 0.5, 1.0) will feature the full right half a photo. If the cropRect is empty, the contentMode will be used to determine the drawRect's size, and only the cropRect's origin will be used for positioning. @param forceUpscaling A boolean that indicates you would *not* like the backing size to be downscaled if the image is smaller than the destination size. Setting this to YES will result in higher memory usage when images are smaller than their destination. @discussion If the image is smaller than the size and UIViewContentModeScaleToAspectFill is specified, we suggest the input size so it will be efficiently upscaled on the GPU by the displaying layer at composite time. */ diff --git a/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm b/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm index bf40f61133..3b30272d45 100644 --- a/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm +++ b/AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm @@ -330,7 +330,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex) subnode2.staticSize = {50, 50}; ASRatioLayoutSpec *child1 = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:1.5 child:subnode1]; - child1.flexBasis = ASRelativeDimensionMakeWithPercent(1); + child1.flexBasis = ASRelativeDimensionMakeWithFraction(1); child1.flexGrow = YES; child1.flexShrink = YES; @@ -508,7 +508,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex) [self testStackLayoutSpecWithStyle:style sizeRange:kOverflowSize subnodes:subnodes identifier:@"overflow"]; } -- (void)testPercentageFlexBasisResolvesAgainstParentSize +- (void)testFractionalFlexBasisResolvesAgainstParentSize { ASStackLayoutSpecStyle style = {.direction = ASStackLayoutDirectionHorizontal}; @@ -520,7 +520,7 @@ static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize, BOOL flex) // This should override the intrinsic size of 50pts and instead compute to 50% = 100pts. // The result should be that the red box is twice as wide as the blue and gree boxes after flexing. - ((ASStaticSizeDisplayNode *)subnodes[0]).flexBasis = ASRelativeDimensionMakeWithPercent(0.5); + ((ASStaticSizeDisplayNode *)subnodes[0]).flexBasis = ASRelativeDimensionMakeWithFraction(0.5); static ASSizeRange kSize = {{200, 0}, {200, INFINITY}}; [self testStackLayoutSpecWithStyle:style sizeRange:kSize subnodes:subnodes identifier:nil]; From 7abceba4a01254d56aee226fe6988a3eec7e0b1c Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 17 Jun 2016 11:41:26 -0700 Subject: [PATCH 2/4] Rename snapshot test reference images --- ...tionalFlexBasisResolvesAgainstParentSize@2x.png} | Bin ...tionalFlexBasisResolvesAgainstParentSize@3x.png} | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/{testPercentageFlexBasisResolvesAgainstParentSize@2x.png => testFractionalFlexBasisResolvesAgainstParentSize@2x.png} (100%) rename AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/{testPercentageFlexBasisResolvesAgainstParentSize@3x.png => testFractionalFlexBasisResolvesAgainstParentSize@3x.png} (100%) diff --git a/AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testPercentageFlexBasisResolvesAgainstParentSize@2x.png b/AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testFractionalFlexBasisResolvesAgainstParentSize@2x.png similarity index 100% rename from AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testPercentageFlexBasisResolvesAgainstParentSize@2x.png rename to AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testFractionalFlexBasisResolvesAgainstParentSize@2x.png diff --git a/AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testPercentageFlexBasisResolvesAgainstParentSize@3x.png b/AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testFractionalFlexBasisResolvesAgainstParentSize@3x.png similarity index 100% rename from AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testPercentageFlexBasisResolvesAgainstParentSize@3x.png rename to AsyncDisplayKitTests/ReferenceImages_64/ASStackLayoutSpecSnapshotTests/testFractionalFlexBasisResolvesAgainstParentSize@3x.png From f07d5c4e9922db40835997275577cf129ecdde5a Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 17 Jun 2016 13:52:09 -0700 Subject: [PATCH 3/4] [Examples] Percent -> Fraction --- .../Sample/OverviewComponentsViewController.m | 4 ++-- examples/CatDealsCollectionView/Sample/ItemNode.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m index 54bd530b1a..2734bb5265 100644 --- a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m +++ b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m @@ -425,8 +425,8 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr verticalStackLayoutSpec.spacing = 5.0; // Spacing between children // Layout the stack layout with 100% width and 100% height of the parent node - ASRelativeSizeRange sizeRange = ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimensionMakeWithPercent(1), - ASRelativeDimensionMakeWithPercent(1)); + ASRelativeSizeRange sizeRange = ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimensionMakeWithFraction(1), + ASRelativeDimensionMakeWithFraction(1)); verticalStackLayoutSpec.sizeRange = sizeRange; // Wrap the static stack layout in a static spec so it will grow to the whole parent node size diff --git a/examples/CatDealsCollectionView/Sample/ItemNode.m b/examples/CatDealsCollectionView/Sample/ItemNode.m index e383abf16f..34da74cfbc 100644 --- a/examples/CatDealsCollectionView/Sample/ItemNode.m +++ b/examples/CatDealsCollectionView/Sample/ItemNode.m @@ -107,7 +107,7 @@ const CGFloat kSoldOutGBHeight = 50.0; self.soldOutLabelFlat.layerBacked = YES; self.soldOutLabelBackground = [[ASDisplayNode alloc] init]; - self.soldOutLabelBackground.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight))); + self.soldOutLabelBackground.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight))); self.soldOutLabelBackground.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9]; self.soldOutLabelBackground.flexGrow = YES; self.soldOutLabelBackground.layerBacked = YES; @@ -289,7 +289,7 @@ const CGFloat kSoldOutGBHeight = 50.0; ASRatioLayoutSpec *imagePlace = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:imageRatio child:self.dealImageView]; self.badge.layoutPosition = CGPointMake(0, constrainedSize.max.height - kFixedLabelsAreaHeight - kBadgeHeight); - self.badge.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(0), ASRelativeDimensionMakeWithPoints(kBadgeHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kBadgeHeight))); + self.badge.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(0), ASRelativeDimensionMakeWithPoints(kBadgeHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(1), ASRelativeDimensionMakeWithPoints(kBadgeHeight))); ASStaticLayoutSpec *badgePosition = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.badge]]; ASOverlayLayoutSpec *badgeOverImage = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imagePlace overlay:badgePosition]; From 3f77a3d46c01e24d90c1d1a9dd3d119ffe2d0065 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 11 Aug 2016 10:37:48 -0700 Subject: [PATCH 4/4] More Percent -> Fraction --- AsyncDisplayKit/Layout/ASDimension.mm | 4 ++-- AsyncDisplayKit/Layout/ASRelativeSize.h | 8 ++++---- AsyncDisplayKit/Layout/ASRelativeSize.mm | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/AsyncDisplayKit/Layout/ASDimension.mm b/AsyncDisplayKit/Layout/ASDimension.mm index 5859830c56..a60b6b4ba9 100644 --- a/AsyncDisplayKit/Layout/ASDimension.mm +++ b/AsyncDisplayKit/Layout/ASDimension.mm @@ -19,9 +19,9 @@ ASRelativeDimension ASRelativeDimensionMake(ASRelativeDimensionType type, CGFloa { if (type == ASRelativeDimensionTypePoints) { ASDisplayNodeCAssertPositiveReal(@"Points", value); - } else if (type == ASRelativeDimensionTypePercent) { + } else if (type == ASRelativeDimensionTypeFraction) { // TODO: Enable this assertion for 2.0. Check that there is no use case for using a larger value, e.g. to layout for a clipsToBounds = NO element. - // ASDisplayNodeCAssert( 0 <= value && value <= 1.0, @"ASRelativeDimension percent value (%f) must be between 0 and 1.", value); + // ASDisplayNodeCAssert( 0 <= value && value <= 1.0, @"ASRelativeDimension fraction value (%f) must be between 0 and 1.", value); } ASRelativeDimension dimension; dimension.type = type; dimension.value = value; return dimension; } diff --git a/AsyncDisplayKit/Layout/ASRelativeSize.h b/AsyncDisplayKit/Layout/ASRelativeSize.h index 12f4845531..4f355044e9 100644 --- a/AsyncDisplayKit/Layout/ASRelativeSize.h +++ b/AsyncDisplayKit/Layout/ASRelativeSize.h @@ -39,11 +39,11 @@ NS_ASSUME_NONNULL_BEGIN extern ASRelativeSize ASRelativeSizeMake(ASRelativeDimension width, ASRelativeDimension height); -/** Convenience constructor to provide size in Points. */ +/** Convenience constructor to provide size in points. */ extern ASRelativeSize ASRelativeSizeMakeWithCGSize(CGSize size); -/** Convenience constructor to provide size in Percentage. */ -extern ASRelativeSize ASRelativeSizeMakeWithPercent(CGFloat percent); +/** Convenience constructor to provide size as a fraction. */ +extern ASRelativeSize ASRelativeSizeMakeWithFraction(CGFloat fraction); /** Resolve this relative size relative to a parent size. */ extern CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize); @@ -61,7 +61,7 @@ extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelati extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactCGSize(CGSize exact); -extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactPercent(CGFloat percent); +extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactFraction(CGFloat fraction); extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimension exactWidth, ASRelativeDimension exactHeight); diff --git a/AsyncDisplayKit/Layout/ASRelativeSize.mm b/AsyncDisplayKit/Layout/ASRelativeSize.mm index 575c1f197e..3fc7abd92d 100644 --- a/AsyncDisplayKit/Layout/ASRelativeSize.mm +++ b/AsyncDisplayKit/Layout/ASRelativeSize.mm @@ -25,10 +25,10 @@ ASRelativeSize ASRelativeSizeMakeWithCGSize(CGSize size) ASRelativeDimensionMakeWithPoints(size.height)); } -ASRelativeSize ASRelativeSizeMakeWithPercent(CGFloat percent) +ASRelativeSize ASRelativeSizeMakeWithFraction(CGFloat fraction) { - return ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(percent), - ASRelativeDimensionMakeWithPercent(percent)); + return ASRelativeSizeMake(ASRelativeDimensionMakeWithFraction(fraction), + ASRelativeDimensionMakeWithFraction(fraction)); } CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize) @@ -67,9 +67,9 @@ ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactCGSize(CGSize exact) return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMakeWithCGSize(exact)); } -ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactPercent(CGFloat percent) +ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactFraction(CGFloat fraction) { - return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMakeWithPercent(percent)); + return ASRelativeSizeRangeMakeWithExactRelativeSize(ASRelativeSizeMakeWithFraction(fraction)); } ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeDimensions(ASRelativeDimension exactWidth,