From 3db4a5b7cd500a7f442fabd2b7fb909b8a76965e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Gonza=CC=81lez?= Date: Wed, 31 May 2017 09:32:02 +0200 Subject: [PATCH 1/2] Fixed incorrect bounds of snapshot when UIAppearance properties cause the view to resize --- .../Categories/UIImage+Snapshot.m | 11 +++++----- .../FBSnapshotTestCaseDemoTests.m | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/FBSnapshotTestCase/Categories/UIImage+Snapshot.m b/FBSnapshotTestCase/Categories/UIImage+Snapshot.m index 968091b..2f3a4c3 100644 --- a/FBSnapshotTestCase/Categories/UIImage+Snapshot.m +++ b/FBSnapshotTestCase/Categories/UIImage+Snapshot.m @@ -40,10 +40,6 @@ + (UIImage *)fb_imageForViewLayer:(UIView *)view + (UIImage *)fb_imageForView:(UIView *)view { - CGRect bounds = view.bounds; - NSAssert1(CGRectGetWidth(bounds), @"Zero width for view %@", view); - NSAssert1(CGRectGetHeight(bounds), @"Zero height for view %@", view); - // If the input view is already a UIWindow, then just use that. Otherwise wrap in a window. UIWindow *window = [view isKindOfClass:[UIWindow class]] ? (UIWindow *)view : view.window; BOOL removeFromSuperview = NO; @@ -55,9 +51,14 @@ + (UIImage *)fb_imageForView:(UIView *)view [window addSubview:view]; removeFromSuperview = YES; } + + [view layoutIfNeeded]; + CGRect bounds = view.bounds; + NSAssert1(CGRectGetWidth(bounds), @"Zero width for view %@", view); + NSAssert1(CGRectGetHeight(bounds), @"Zero height for view %@", view); + UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0); - [view layoutIfNeeded]; [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES]; UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); diff --git a/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDemoTests.m b/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDemoTests.m index 720866c..65994fc 100644 --- a/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDemoTests.m +++ b/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDemoTests.m @@ -63,6 +63,28 @@ - (void)testViewSnapshotWithUIAppearance FBSnapshotVerifyView(control, nil); } +- (void)testViewSnapshotWithUIAppearanceResizing +{ + // If this works properly you should be able to read the whole "Click me!" title in the snapshot + [[UIButton appearance] setContentEdgeInsets:UIEdgeInsetsMake(15, 15, 15, 15)]; + + UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; + [button setTitle:@"Click me!" forState:UIControlStateNormal]; + + button.translatesAutoresizingMaskIntoConstraints = NO; + [button addConstraint:[NSLayoutConstraint constraintWithItem:button + attribute:NSLayoutAttributeWidth + relatedBy:NSLayoutRelationGreaterThanOrEqual + toItem:nil + attribute:NSLayoutAttributeNotAnAttribute + multiplier:0 + constant:65]]; + [button sizeToFit]; + + self.usesDrawViewHierarchyInRect = YES; + FBSnapshotVerifyView(button, nil); +} + - (void)testViewSnapshotWithDifferentBackgroundColorPerArchitecture { UIColor *color = FBSnapshotTestCaseIs64Bit() ? [UIColor magentaColor] : [UIColor cyanColor]; From 5b2b9d6b3cb70865cb0e7c6fafc5099815e944fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Gonza=CC=81lez?= Date: Wed, 31 May 2017 16:21:58 +0200 Subject: [PATCH 2/2] Added reference images --- ...stViewSnapshotWithUIAppearanceResizing@2x.png | Bin 0 -> 2709 bytes ...stViewSnapshotWithUIAppearanceResizing@2x.png | Bin 0 -> 2709 bytes ...stViewSnapshotWithUIAppearanceResizing@3x.png | Bin 0 -> 4498 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages_32/FBSnapshotTestCaseDemoTests/testViewSnapshotWithUIAppearanceResizing@2x.png create mode 100644 FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages_64/FBSnapshotTestCaseDemoTests/testViewSnapshotWithUIAppearanceResizing@2x.png create mode 100644 FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages_64/FBSnapshotTestCaseDemoTests/testViewSnapshotWithUIAppearanceResizing@3x.png diff --git a/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages_32/FBSnapshotTestCaseDemoTests/testViewSnapshotWithUIAppearanceResizing@2x.png b/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages_32/FBSnapshotTestCaseDemoTests/testViewSnapshotWithUIAppearanceResizing@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..cab71c0cc7ef5b4352e01c81464e5489dc316d5b GIT binary patch literal 2709 zcmd6n_dgqm8^=>6rHUH0N6)SrRVCFLt;UR1Eoa1NQ`BsX5QnIBxNn+)U~L6CrdLxJyG`S>B0xMa*F@}#8rOyjJ1>U#_3Tu0POJalw7C&QP)nb z{(qj%JeP-e8z2AxH`5w?_aX8OvjCDVXD;^Z@Sd3?gP%uO_%6?-OXeb3sy-JKlXz!Z z;dI5M>x)+-+JiDLB9ziw$Lz!v!Jg`cS^Ns%us+OvsW`KXNzzG0Ps{tVmHkkhagxV8 z?lve|`(M2X4u9IW>RSlnSFD5c&t!zXsqn=!|5YWjf4Y`94n60u>eR8yJ3J>g)wKRC zkc?jqL46K^0`m+K1+}AeS!KcD@;Xg%Da-DAl0=hlSp;NZo7EFJdx33Z6Vmq;XbL2` z^T362L?rJ%mQkRKfHH;LDCiw+A#ghf1i!*wdUTI^{ofwsvek3MLP+)Q1;-HUFH6l zLozrK^EnW`)*tb1{mOA0FS1sfHXY?B0*c(3(g|_!4h=J@ zzmloJwphjiea_rK#6xk<(}W+ zFe8V96b92{=%yrEE4aO?T+YRKq0;LYrxp0)X+xqu1S6YC*de4S4vfYr&Gm5OuS=5i zkn-3kC%Zhb&E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