mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-04 03:40:45 +00:00
* [Yoga Beta] Improvements to the experimental support for Yoga layout. Yoga remains an unsupported / speculative feature, but these improvements are important for the functionality of clients that are experimenting with it. For example, without these changes, ASButtonNode is not able to lay out correctly. These changes allow certain subtrees that use layout specs to coexist properly in a Yoga heirarchy. The most significant change here is moving ASEdgeInsets into the #if YOGA gating. Although this is technically an API change, this type was added with no known use cases and is really only useful for flexbox layout specification. So, before usages of it are created, it makes sense to constrain the Texture API surface until that time. * [RTL] Bridge the UISemanticContentAttribute property for more convenient RTL support. Although apps could handle this before by setting the view's property in didLoad, it's useful to bridge this property for setting during off-main initialization. This change also makes RTL fully functional / automatic for Yoga layout users. * Remove RTL property addition and depend on PR #60 landing first. * Fix warnings * Add line to changelog
119 lines
3.5 KiB
Plaintext
119 lines
3.5 KiB
Plaintext
//
|
|
// ASDimension.mm
|
|
// Texture
|
|
//
|
|
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional
|
|
// grant of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present,
|
|
// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
|
|
#import <AsyncDisplayKit/ASDimension.h>
|
|
|
|
#import <UIKit/UIGeometry.h>
|
|
|
|
#import <AsyncDisplayKit/CoreGraphics+ASConvenience.h>
|
|
|
|
#import <AsyncDisplayKit/ASAssert.h>
|
|
|
|
#pragma mark - ASDimension
|
|
|
|
ASDimension const ASDimensionAuto = {ASDimensionUnitAuto, 0};
|
|
|
|
ASOVERLOADABLE ASDimension ASDimensionMake(NSString *dimension)
|
|
{
|
|
if (dimension.length > 0) {
|
|
|
|
// Handle points
|
|
if ([dimension hasSuffix:@"pt"]) {
|
|
return ASDimensionMake(ASDimensionUnitPoints, ASCGFloatFromString(dimension));
|
|
}
|
|
|
|
// Handle auto
|
|
if ([dimension isEqualToString:@"auto"]) {
|
|
return ASDimensionAuto;
|
|
}
|
|
|
|
// Handle percent
|
|
if ([dimension hasSuffix:@"%"]) {
|
|
return ASDimensionMake(ASDimensionUnitFraction, (ASCGFloatFromString(dimension) / 100.0));
|
|
}
|
|
}
|
|
|
|
ASDisplayNodeCAssert(NO, @"Parsing dimension failed for: %@", dimension);
|
|
return ASDimensionAuto;
|
|
}
|
|
|
|
NSString *NSStringFromASDimension(ASDimension dimension)
|
|
{
|
|
switch (dimension.unit) {
|
|
case ASDimensionUnitPoints:
|
|
return [NSString stringWithFormat:@"%.0fpt", dimension.value];
|
|
case ASDimensionUnitFraction:
|
|
return [NSString stringWithFormat:@"%.0f%%", dimension.value * 100.0];
|
|
case ASDimensionUnitAuto:
|
|
return @"Auto";
|
|
}
|
|
}
|
|
|
|
#pragma mark - ASLayoutSize
|
|
|
|
ASLayoutSize const ASLayoutSizeAuto = {ASDimensionAuto, ASDimensionAuto};
|
|
|
|
#pragma mark - ASSizeRange
|
|
|
|
ASSizeRange const ASSizeRangeZero = {};
|
|
|
|
ASSizeRange const ASSizeRangeUnconstrained = { {0, 0}, { INFINITY, INFINITY }};
|
|
|
|
struct _Range {
|
|
CGFloat min;
|
|
CGFloat max;
|
|
|
|
/**
|
|
Intersects another dimension range. If the other range does not overlap, this size range "wins" by returning a
|
|
single point within its own range that is closest to the non-overlapping range.
|
|
*/
|
|
_Range intersect(const _Range &other) const
|
|
{
|
|
CGFloat newMin = MAX(min, other.min);
|
|
CGFloat newMax = MIN(max, other.max);
|
|
if (newMin <= newMax) {
|
|
return {newMin, newMax};
|
|
} else {
|
|
// No intersection. If we're before the other range, return our max; otherwise our min.
|
|
if (min < other.min) {
|
|
return {max, max};
|
|
} else {
|
|
return {min, min};
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
ASSizeRange ASSizeRangeIntersect(ASSizeRange sizeRange, ASSizeRange otherSizeRange)
|
|
{
|
|
auto w = _Range({sizeRange.min.width, sizeRange.max.width}).intersect({otherSizeRange.min.width, otherSizeRange.max.width});
|
|
auto h = _Range({sizeRange.min.height, sizeRange.max.height}).intersect({otherSizeRange.min.height, otherSizeRange.max.height});
|
|
return {{w.min, h.min}, {w.max, h.max}};
|
|
}
|
|
|
|
NSString *NSStringFromASSizeRange(ASSizeRange sizeRange)
|
|
{
|
|
return [NSString stringWithFormat:@"<ASSizeRange: min=%@, max=%@>",
|
|
NSStringFromCGSize(sizeRange.min),
|
|
NSStringFromCGSize(sizeRange.max)];
|
|
}
|
|
|
|
#if YOGA
|
|
#pragma mark - Yoga - ASEdgeInsets
|
|
ASEdgeInsets const ASEdgeInsetsZero = {};
|
|
#endif
|