Skip to content

Commit

Permalink
[TextControls] Expose inter item spacing
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 344252502
  • Loading branch information
andrewoverton authored and material-automation committed Nov 25, 2020
1 parent 732e39b commit 16359d7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 5 deletions.
12 changes: 10 additions & 2 deletions components/TextControls/src/BaseTextAreas/MDCBaseTextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,27 @@ values are allowed.
/**
When this property is set, the text area will convert it to a @c CGFloat and use that as the
horizontal distance between the leading edge of the text area and the subview closest to it. When
this property is @c nil, the text area will use a default value that depends on the style. This
this property is @c nil, the text area will use a default value that is specific to its style. This
property is @c nil by default.
*/
@property(nullable, nonatomic, strong) NSNumber *leadingEdgePaddingOverride;

/**
When this property is set, the text area will convert it to a @c CGFloat and use that as the
horizontal distance between the trailing edge of the text area and the subview closest to it. When
this property is @c nil, the text area will use a default value that depends on the style. This
this property is @c nil, the text area will use a default value that is specific to its style. This
property is @c nil by default.
*/
@property(nullable, nonatomic, strong) NSNumber *trailingEdgePaddingOverride;

/**
When this property is set, the text area will convert it to a @c CGFloat and use that as the
horizontal distance between the text area's contained text view and its leading and trailing views.
When this property is @c nil, the text area will use a default value that is specific to its style.
This property is @c nil by default.
*/
@property(nullable, nonatomic, strong) NSNumber *horizontalInterItemSpacingOverride;

/**
This property allows the user to override the default height of the container. The container is the
region above the the assistive labels within the text area. If there is no assistive label text,
Expand Down
4 changes: 4 additions & 0 deletions components/TextControls/src/BaseTextAreas/MDCBaseTextArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ - (MDCBaseTextAreaLayout *)calculateLayoutWithSize:(CGSize)size {
horizontalPositioningReference.trailingEdgePadding =
(CGFloat)[self.trailingEdgePaddingOverride doubleValue];
}
if (self.horizontalInterItemSpacingOverride) {
horizontalPositioningReference.horizontalInterItemSpacing =
(CGFloat)[self.horizontalInterItemSpacingOverride doubleValue];
}
return horizontalPositioningReference;
}

Expand Down
14 changes: 11 additions & 3 deletions components/TextControls/src/BaseTextFields/MDCBaseTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
The @c label is a label that occupies the area the text usually occupies when there is no
text. It is distinct from the placeholder in that it can move above the text area or disappear to
text. It is distinct from the placeholder in that it can move above the text region or disappear to
reveal the placeholder when editing begins.
*/
@property(strong, nonatomic, readonly, nonnull) UILabel *label;
Expand Down Expand Up @@ -76,7 +76,7 @@
/**
Sets the floating label color for a given state.
Floating label color refers to the color of the label when it's in its "floating position," i.e.
when it's above the text area.
when it's above the text region.
@param floatingLabelColor The UIColor for the given state.
@param state The MDCTextControlState.
*/
Expand All @@ -87,7 +87,7 @@
/**
Returns the floating label color for a given state.
Floating label color refers to the color of the label when it's in its "floating position," i.e.
when it's above the text area.
when it's above the text field.
@param state The MDCTextControlState.
*/
- (nonnull UIColor *)floatingLabelColorForState:(MDCTextControlState)state;
Expand Down Expand Up @@ -171,6 +171,14 @@
*/
@property(nullable, nonatomic, strong) NSNumber *trailingEdgePaddingOverride;

/**
When this property is set, the text field will convert it to a @c CGFloat and use that as the
horizontal distance between things like the text field's text region, the leading/trailing views,
and the clear button. When this property is @c nil, the text field will use a default value that is
specific to its style. This property is @c nil by default.
*/
@property(nullable, nonatomic, strong) NSNumber *horizontalInterItemSpacingOverride;

/**
This property allows the user to override the default height of the container. The container is the
region above the the assistive labels within the text field. If there is no assistive label text,
Expand Down
4 changes: 4 additions & 0 deletions components/TextControls/src/BaseTextFields/MDCBaseTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ - (MDCBaseTextFieldLayout *)calculateLayoutWithTextFieldSize:(CGSize)textFieldSi
horizontalPositioningReference.trailingEdgePadding =
(CGFloat)[self.trailingEdgePaddingOverride doubleValue];
}
if (self.horizontalInterItemSpacingOverride) {
horizontalPositioningReference.horizontalInterItemSpacing =
(CGFloat)[self.horizontalInterItemSpacingOverride doubleValue];
}
return horizontalPositioningReference;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ - (void)testTextAreaWithPreferredContainerHeightOf300 {
[self validateTextArea:textArea];
}

- (void)testTextAreaWithLeadingViewTrailingViewAndCustomPaddings {
// Given
MDCBaseTextArea *textArea = self.textArea;

// When
textArea.label.text = @"Label text";
textArea.leadingView = [self createSideView];
textArea.leadingViewMode = UITextFieldViewModeAlways;
textArea.leadingView = [self createSideView];
textArea.leadingViewMode = UITextFieldViewModeAlways;
textArea.leadingEdgePaddingOverride = @(30.0f);
textArea.trailingEdgePaddingOverride = @(30.0f);
textArea.horizontalInterItemSpacingOverride = @(30.0f);

// Then
[self validateTextArea:textArea];
}

#pragma mark Helpers

- (UIView *)createSideView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,16 @@ - (void)testTextFieldWithHebrewTextAndTrailingViewInRTL {
[self validateTextField:textField];
}

- (void)testTextFieldWithLeadingViewTrailingViewAndCustomPaddings {
// Given
MDCBaseTextField *textField = self.textField;

// When
[MDCBaseTextFieldTestsSnapshotTestHelpers
configureTextFieldWithLeadingViewTrailingViewAndCustomPaddings:textField];

// Then
[self validateTextField:textField];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,16 @@ - (void)testTextFieldWithHebrewTextAndTrailingViewInRTL {
[self validateTextField:textField];
}

- (void)testTextFieldWithLeadingViewTrailingViewAndCustomPaddings {
// Given
MDCFilledTextField *textField = self.textField;

// When
[MDCBaseTextFieldTestsSnapshotTestHelpers
configureTextFieldWithLeadingViewTrailingViewAndCustomPaddings:textField];

// Then
[self validateTextField:textField];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,16 @@ - (void)testTextFieldWithHebrewTextAndTrailingViewInRTL {
[self validateTextField:textField];
}

- (void)testTextFieldWithLeadingViewTrailingViewAndCustomPaddings {
// Given
MDCOutlinedTextField *textField = self.textField;

// When
[MDCBaseTextFieldTestsSnapshotTestHelpers
configureTextFieldWithLeadingViewTrailingViewAndCustomPaddings:textField];

// Then
[self validateTextField:textField];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
(MDCBaseTextField *)textField;
+ (void)configureTextFieldWithHebrewTextAndTrailingViewInRTL:(MDCBaseTextField *)textField;
+ (void)configureTextFieldWithHebrewTextAndLeadingViewInRTL:(MDCBaseTextField *)textField;
+ (void)configureTextFieldWithLeadingViewTrailingViewAndCustomPaddings:
(MDCBaseTextField *)textField;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ + (void)configureTextFieldWithHebrewTextAndLeadingViewInRTL:(MDCBaseTextField *)
textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
}

+ (void)configureTextFieldWithLeadingViewTrailingViewAndCustomPaddings:
(MDCBaseTextField *)textField {
textField.text = @"Some text";
textField.leadingView = [self createRedSideView];
textField.leadingViewMode = UITextFieldViewModeAlways;
textField.leadingView = [self createBlueSideView];
textField.leadingViewMode = UITextFieldViewModeAlways;
textField.leadingEdgePaddingOverride = @(30.0f);
textField.trailingEdgePaddingOverride = @(30.0f);
textField.horizontalInterItemSpacingOverride = @(30.0f);
}

#pragma mark Helpers

+ (UIView *)createBlueSideView {
Expand Down

0 comments on commit 16359d7

Please sign in to comment.