Skip to content

Commit

Permalink
[TextControls] Make text fields without floating labels shorter
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 320432378
  • Loading branch information
andrewoverton authored and material-automation committed Jul 9, 2020
1 parent a998a88 commit 9480bf4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ - (void)initializeScrollViewSubviewsArray {
outlinedTextFieldWithoutFloatingLabel,
[self createLabelWithText:@"MDCUnderlinedTextField:"],
[self createMaterialUnderlinedTextField],
[self createLabelWithText:@"MDCUnderlinedTextField:"],
[self createMaterialUnderlinedTextField],
[self createLabelWithText:@"MDCUnderlinedTextField without floating label:"],
underlinedTextFieldWithoutFloatingLabel,
[self createLabelWithText:@"MDCBaseTextField:"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (void)testClearButtonRectForBounds {
[textField layoutIfNeeded];

// Then
CGRect expectedClearButtonFrame = CGRectMake(99, 20, 19, 19);
CGRect expectedClearButtonFrame = CGRectMake(99, 11, 19, 19);
CGRect actualClearButtonFrame = [textField clearButtonRectForBounds:textFieldFrame];
XCTAssertTrue(CGRectEqualToRect(actualClearButtonFrame, expectedClearButtonFrame));
}
Expand Down Expand Up @@ -303,7 +303,7 @@ - (void)testSizeThatFits {

// Then
CGSize newSize = textField.frame.size;
CGSize correctSize = CGSizeMake(130, 59);
CGSize correctSize = CGSizeMake(130, 41);
XCTAssertTrue(CGSizeEqualToSize(newSize, correctSize));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize
}
}

CGFloat textRectMinYNormal = positioningReference.paddingBetweenContainerTopAndNormalLabel;
BOOL shouldLayoutForFloatingLabel = MDCTextControlShouldLayoutForFloatingLabelWithLabelPosition(
labelPosition, labelBehavior, label.text);
CGFloat textRectMinYNormal = 0;
if (shouldLayoutForFloatingLabel) {
textRectMinYNormal = positioningReference.paddingBetweenContainerTopAndNormalLabel;
} else {
textRectMinYNormal = positioningReference.paddingAroundTextWhenNoFloatingLabel;
}

CGFloat textRectWidth = textRectMaxX - textRectMinX;
CGFloat textRectHeight = [self textHeightWithFont:font];
CGRect textRectNormal =
Expand All @@ -196,7 +204,10 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize
CGRect textRectFloating =
CGRectMake(textRectMinX, textRectMinYFloatingLabel, textRectWidth, textRectHeight);

CGFloat containerMidY = (CGFloat)0.5 * positioningReference.containerHeightWithFloatingLabel;
CGFloat containerHeight = shouldLayoutForFloatingLabel
? positioningReference.containerHeightWithFloatingLabel
: positioningReference.containerHeightWithoutFloatingLabel;
CGFloat containerMidY = (CGFloat)0.5 * containerHeight;
BOOL isFloatingLabel = labelPosition == MDCTextControlLabelPositionFloating;
CGFloat textRectMidY =
isFloatingLabel ? CGRectGetMidY(textRectFloating) : CGRectGetMidY(textRectNormal);
Expand Down Expand Up @@ -242,9 +253,8 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize
paddingAboveAssistiveLabels:positioningReference.paddingAboveAssistiveLabels
paddingBelowAssistiveLabels:positioningReference.paddingBelowAssistiveLabels
isRTL:isRTL];
self.assistiveLabelViewFrame =
CGRectMake(0, positioningReference.containerHeightWithFloatingLabel, textFieldWidth,
self.assistiveLabelViewLayout.calculatedHeight);
self.assistiveLabelViewFrame = CGRectMake(0, containerHeight, textFieldWidth,
self.assistiveLabelViewLayout.calculatedHeight);
self.leftViewFrame = leftViewFrame;
self.rightViewFrame = rightViewFrame;
self.clearButtonFrame = clearButtonFrame;
Expand All @@ -254,7 +264,7 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize
self.labelFrameNormal = labelFrameNormal;
self.leftViewHidden = !displaysLeftView;
self.rightViewHidden = !displaysRightView;
self.containerHeight = positioningReference.containerHeightWithFloatingLabel;
self.containerHeight = containerHeight;
}

- (CGFloat)sideViewMidYWithSideViewAlignment:
Expand Down

0 comments on commit 9480bf4

Please sign in to comment.