Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Buttons] Move MDCButton's defaultContentInset configuration to later…
… in init (#8069) After digging in a bit, I've found that this is an issue with UIButton in iOS 13 (as of Xcode 11 beta 4). To reproduce: 1) Create a `UIButton`. 2) Create a `UIImage` and flip it using `imageWithHorizontallyFlippedOrientation`. 3) *Before setting the button's image*, give the button non-zero contentEdgeInsets (I used `{20, 10, 20, 10}`). 4) Set the image on the button. You should be able to see that the image is not visible, and that the button's internal UIImageView's bounds.origin is `{ -(i.left + i.right), -(i.top + i.bottom) }` (where `i` is the button's contentEdgeInsets). In iOS 12, the button's imageView's bounds.origin is `{0, 0}`. Closes #7983
- Loading branch information
1 parent
e58c550
commit 4fcf3cd
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
components/Buttons/tests/snapshot/ButtonsFlippedImageRenderingSnapshotTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2019-present the Material Components for iOS authors. All Rights Reserved. | ||
// | ||
// 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 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "MaterialSnapshot.h" | ||
|
||
#import <CoreGraphics/CoreGraphics.h> | ||
#import <UIKit/UIKit.h> | ||
|
||
#import "MaterialButtons.h" | ||
|
||
/** Snapshot tests for Buttons in different UIControlStates */ | ||
@interface ButtonsFlippedImageRenderingSnapshotTests : MDCSnapshotTestCase | ||
@property(nonatomic, strong) MDCButton *button; | ||
@end | ||
|
||
@implementation ButtonsFlippedImageRenderingSnapshotTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
self.button = [[MDCButton alloc] init]; | ||
} | ||
|
||
- (void)tearDown { | ||
self.button = nil; | ||
[super tearDown]; | ||
} | ||
|
||
- (void)generateSnapshotAndVerifyForView:(UIView *)view { | ||
[view sizeToFit]; | ||
UIView *snapshotView = [view mdc_addToBackgroundView]; | ||
[self snapshotVerifyView:snapshotView]; | ||
} | ||
|
||
// This test exists to exercise a bug in iOS 13 (Xcode 11 betas 1-4) where setting contentEdgeInsets | ||
// before a horizontally flipped UIImage causes the image to render outside of the UIImageView's | ||
// frame. | ||
- (void)testHorizontallyFlippedImageWithContentInsets { | ||
// Given | ||
if (@available(iOS 10.0, *)) { | ||
// When | ||
self.button.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20); | ||
UIImage *testImage = | ||
[[UIImage mdc_testImageOfSize:CGSizeMake(24, 24)] imageWithHorizontallyFlippedOrientation]; | ||
[self.button setImage:testImage forState:UIControlStateNormal]; | ||
} else { | ||
// Fallback on earlier versions | ||
} | ||
|
||
// Then | ||
[self.button sizeToFit]; | ||
[self snapshotVerifyViewForIOS13:self.button]; | ||
} | ||
|
||
@end |
Binary file added
BIN
+1.45 KB
...enderingSnapshotTests/testHorizontallyFlippedImageWithContentInsets_11_2@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1016 Bytes
...enderingSnapshotTests/testHorizontallyFlippedImageWithContentInsets_13_0@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.