36
36
static const CGFloat MDCChipFieldVerticalInset = 8 ;
37
37
static const CGFloat MDCChipFieldHorizontalMargin = 8 ;
38
38
static const CGFloat MDCChipFieldVerticalMargin = 8 ;
39
+ static const UIEdgeInsets MDCChipFieldTextFieldTextInsetsDefault = {16 , 4 , 16 , 0 };
39
40
static const UIKeyboardType MDCChipFieldDefaultKeyboardType = UIKeyboardTypeEmailAddress;
40
41
41
42
const CGFloat MDCChipFieldDefaultMinTextFieldWidth = 44 ;
@@ -53,20 +54,20 @@ @interface MDCChipFieldTextField : UITextField
53
54
54
55
@property (nonatomic , weak ) id <MDCChipFieldTextFieldDelegate> deletionDelegate;
55
56
57
+ @property (nonatomic ) UIEdgeInsets textFieldTextInsets;
58
+
56
59
@end
57
60
58
61
@implementation MDCChipFieldTextField
59
62
60
- const UIEdgeInsets MDCChipFieldTextFieldRTLEdgeInsets = {16 , 0 , 16 , 4 };
61
-
62
- const UIEdgeInsets MDCChipFieldTextFieldLTREdgeInsets = {16 , 4 , 16 , 0 };
63
-
64
63
- (BOOL )isRTL {
65
64
return self.effectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
66
65
}
67
66
68
67
- (UIEdgeInsets)textEdgeInsets {
69
- return [self isRTL ] ? MDCChipFieldTextFieldRTLEdgeInsets : MDCChipFieldTextFieldLTREdgeInsets;
68
+ return [self isRTL ] ? UIEdgeInsetsMake (_textFieldTextInsets.top , _textFieldTextInsets.right ,
69
+ _textFieldTextInsets.bottom , _textFieldTextInsets.left )
70
+ : _textFieldTextInsets;
70
71
}
71
72
72
73
- (CGRect )textRectForBounds : (CGRect )bounds {
@@ -149,6 +150,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
149
150
chipFieldTextField.autocorrectionType = UITextAutocorrectionTypeNo;
150
151
chipFieldTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
151
152
chipFieldTextField.keyboardType = MDCChipFieldDefaultKeyboardType;
153
+ chipFieldTextField.textFieldTextInsets = MDCChipFieldTextFieldTextInsetsDefault;
152
154
// Listen for notifications posted when the text field is the first responder.
153
155
[[NSNotificationCenter defaultCenter ] addObserver: self
154
156
selector: @selector (textFieldDidChange )
@@ -182,6 +184,8 @@ - (void)commonMDCChipFieldInit {
182
184
_contentEdgeInsets = MDCChipFieldDefaultContentEdgeInsets;
183
185
_showPlaceholderWithChips = YES ;
184
186
_chipHeight = 32 ;
187
+ _textFieldLeadingPaddingWhenChipIsAdded = 0 ;
188
+ _textFieldTextInsets = MDCChipFieldTextFieldTextInsetsDefault;
185
189
186
190
[self configureLocalizedAccessibilityActionName ];
187
191
}
@@ -289,6 +293,13 @@ - (void)setPlaceholderAttributes:(NSDictionary<NSAttributedStringKey, id> *)plac
289
293
[self updateTextFieldPlaceholderText ];
290
294
}
291
295
296
+ - (void )setTextFieldTextInsets : (UIEdgeInsets)textFieldTextInsets {
297
+ _textFieldTextInsets = textFieldTextInsets;
298
+ if ([_textField isKindOfClass: [MDCChipFieldTextField class ]]) {
299
+ ((MDCChipFieldTextField *)self.textField ).textFieldTextInsets = _textFieldTextInsets;
300
+ }
301
+ }
302
+
292
303
- (CGSize )sizeThatFits : (CGSize )size {
293
304
NSArray *chipFrames = [self chipFramesForSize: size];
294
305
CGRect lastChipFrame = [chipFrames.lastObject CGRectValue ];
@@ -720,7 +731,8 @@ - (CGRect)frameForTextFieldForLastChipFrame:(CGRect)lastChipFrame
720
731
chipFieldSize.width - self.contentEdgeInsets .left - self.contentEdgeInsets .right ;
721
732
} else {
722
733
// The text field fits on the line with chips
723
- originX += CGRectGetMaxX (lastChipFrame) + MDCChipFieldHorizontalMargin;
734
+ originX += CGRectGetMaxX (lastChipFrame) + MDCChipFieldHorizontalMargin +
735
+ _textFieldLeadingPaddingWhenChipIsAdded;
724
736
textFieldWidth = availableWidth;
725
737
}
726
738
0 commit comments