Skip to content

Commit 8465222

Browse files
Jeff Verkoeyenmaterial-automation
authored andcommitted
[Buttons] Attempt to reduce flakiness of the buttons screenshot tests.
PiperOrigin-RevId: 364466639
1 parent 386923b commit 8465222

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

components/Buttons/examples/supplemental/ButtonsTypicalUseSupplemental.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ - (void)layoutButtonsInRange:(NSRange)range around:(CGFloat)centerX {
122122
CGFloat labelOffset = (CGRectGetHeight(button.bounds) - CGRectGetHeight(label.bounds)) / 2;
123123
label.center = CGPointMake(centerX - (CGRectGetWidth(label.bounds) / 2) - kViewOffsetToCenter,
124124
heightSum + labelOffset + (CGRectGetHeight(label.bounds) / 2));
125+
126+
// Pin the label's frame to pixel boundaries to reduce snapshot flakiness due to inaccuracies in
127+
// floating point rounding behavior on the GPU when taking snapshots.
128+
CGRect labelFrame = label.frame;
129+
labelFrame.origin.x = floor(labelFrame.origin.x);
130+
labelFrame.origin.y = floor(labelFrame.origin.y);
131+
label.frame = labelFrame;
132+
125133
heightSum += CGRectGetHeight(button.bounds);
126134
if (i < self.buttons.count - 1) {
127135
heightSum += button.enabled ? 24 : 36;

0 commit comments

Comments
 (0)