mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-20 13:19:16 +00:00
Merge pull request #1767 from facebook/AHPercentToFraction
[ASRelativeDimensionType] Replace "percent" with "fraction" Where Appropriate
This commit is contained in:
commit
2040674aed
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
@ -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];
|
||||
|
||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
@ -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
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user