[YogaKit] add unit tests.
- pixel-align for view’s frame; - add unit tests for YogaKit.
This commit is contained in:
@@ -43,7 +43,7 @@ static void YogaSwizzleInstanceMethod(Class cls, SEL originalSelector, SEL swizz
|
||||
@implementation UIView (YogaKitAutoApplyLayout)
|
||||
|
||||
+ (void)load {
|
||||
static dispatch_once_t onceToken = 0;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
YogaSwizzleInstanceMethod(self, @selector(initWithFrame:), @selector(_yoga_initWithFrame:));
|
||||
YogaSwizzleInstanceMethod(self, @selector(setFrame:), @selector(_yoga_setFrame:));
|
||||
|
@@ -468,7 +468,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) {
|
||||
scale = [UIScreen mainScreen].scale;
|
||||
});
|
||||
|
||||
return roundf(value * scale) / scale;
|
||||
return ceil(value * scale) / scale; // Pixel-align
|
||||
}
|
||||
|
||||
static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
|
||||
@@ -513,15 +513,13 @@ static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
|
||||
CGRect frame = (CGRect){
|
||||
.origin =
|
||||
{
|
||||
.x = YGRoundPixelValue(topLeft.x + origin.x),
|
||||
.y = YGRoundPixelValue(topLeft.y + origin.y),
|
||||
.x = topLeft.x + origin.x,
|
||||
.y = topLeft.y + origin.y,
|
||||
},
|
||||
.size =
|
||||
{
|
||||
.width = MAX(YGRoundPixelValue(bottomRight.x) -
|
||||
YGRoundPixelValue(topLeft.x), 0),
|
||||
.height = MAX(YGRoundPixelValue(bottomRight.y) -
|
||||
YGRoundPixelValue(topLeft.y), 0),
|
||||
.width = MAX(YGRoundPixelValue(bottomRight.x - topLeft.x), 0),
|
||||
.height = MAX(YGRoundPixelValue(bottomRight.y - topLeft.y), 0),
|
||||
},
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user