From 1d7746f552d8cf043ab23d0f60dd041cb4478281 Mon Sep 17 00:00:00 2001 From: Andrew Overton Date: Tue, 4 Feb 2020 12:16:56 -0800 Subject: [PATCH] Reevaluate RTL logic because of internal snapshot testing infrastructure Some internal snapshot tests force RTL by setting the semantic content attribute. The "is RTL" logic in MDCBaseTextFields up to this point only looked at effective layout direction. This change makes it so that it checks if either RTL or LTR semantic content attributes are being forced before consulting effective layout direction. PiperOrigin-RevId: 293201200 --- .../src/BaseTextFields/MDCBaseTextField.m | 75 ++++++++----------- .../private/MDCBaseTextFieldLayout.h | 4 +- .../private/MDCBaseTextFieldLayout.m | 16 ++-- .../MDCBaseTextFieldLayoutTests.m | 4 +- .../BaseTextFields/MDCBaseTextFieldTests.m | 42 ++++++++--- .../Shared/MDCTextControlAssistiveLabelView.h | 4 +- .../Shared/MDCTextControlAssistiveLabelView.m | 24 +++--- .../MDCTextControlAssistiveLabelViewLayout.h | 8 +- .../MDCTextControlAssistiveLabelViewLayout.m | 26 +++---- 9 files changed, 108 insertions(+), 95 deletions(-) diff --git a/components/TextControls/src/BaseTextFields/MDCBaseTextField.m b/components/TextControls/src/BaseTextFields/MDCBaseTextField.m index 8257b457fb9..8e2d604e45b 100644 --- a/components/TextControls/src/BaseTextFields/MDCBaseTextField.m +++ b/components/TextControls/src/BaseTextFields/MDCBaseTextField.m @@ -28,7 +28,6 @@ @interface MDCBaseTextField () @property(strong, nonatomic) UILabel *label; @property(nonatomic, strong) MDCTextControlAssistiveLabelView *assistiveLabelView; @property(strong, nonatomic) MDCBaseTextFieldLayout *layout; -@property(nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection; @property(nonatomic, assign) MDCTextControlState textControlState; @property(nonatomic, assign) MDCTextControlLabelState labelState; @property(nonatomic, assign) CGRect labelFrame; @@ -85,7 +84,6 @@ - (void)dealloc { - (void)initializeProperties { self.animationDuration = kMDCTextControlDefaultAnimationDuration; self.labelBehavior = MDCTextControlLabelBehaviorFloats; - self.layoutDirection = self.mdf_effectiveUserInterfaceLayoutDirection; self.labelState = [self determineCurrentLabelState]; self.textControlState = [self determineCurrentTextControlState]; self.containerStyle = [[MDCTextControlStyleBase alloc] init]; @@ -106,8 +104,8 @@ - (void)setUpAssistiveLabels { self.assistiveLabelView = [[MDCTextControlAssistiveLabelView alloc] init]; CGFloat assistiveFontSize = MDCRound([UIFont systemFontSize] * (CGFloat)0.75); UIFont *assistiveFont = [UIFont systemFontOfSize:assistiveFontSize]; - self.assistiveLabelView.leftAssistiveLabel.font = assistiveFont; - self.assistiveLabelView.rightAssistiveLabel.font = assistiveFont; + self.assistiveLabelView.leadingAssistiveLabel.font = assistiveFont; + self.assistiveLabelView.trailingAssistiveLabel.font = assistiveFont; [self addSubview:self.assistiveLabelView]; } @@ -138,8 +136,12 @@ - (CGSize)intrinsicContentSize { - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { [super traitCollectionDidChange:previousTraitCollection]; + [self setNeedsLayout]; +} - self.layoutDirection = self.mdf_effectiveUserInterfaceLayoutDirection; +- (void)setSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute { + [super setSemanticContentAttribute:semanticContentAttribute]; + [self setNeedsLayout]; } #pragma mark Layout @@ -226,11 +228,11 @@ - (MDCBaseTextFieldLayout *)calculateLayoutWithTextFieldSize:(CGSize)textFieldSi rightViewMode:self.rightViewMode clearButtonSideLength:clearButtonSideLength clearButtonMode:self.clearButtonMode - leftAssistiveLabel:self.assistiveLabelView.leftAssistiveLabel - rightAssistiveLabel:self.assistiveLabelView.rightAssistiveLabel + leadingAssistiveLabel:self.assistiveLabelView.leadingAssistiveLabel + trailingAssistiveLabel:self.assistiveLabelView.trailingAssistiveLabel assistiveLabelDrawPriority:self.assistiveLabelDrawPriority customAssistiveLabelDrawPriority:clampedCustomAssistiveLabelDrawPriority - isRTL:self.isRTL + isRTL:self.shouldLayoutForRTL isEditing:self.isEditing]; } @@ -274,6 +276,17 @@ - (BOOL)calculatedHeightHasChangedSinceIntrinsicContentSizeWasLastComputed { return self.layout.calculatedHeight != self.mostRecentlyComputedIntrinsicContentSize.height; } +- (BOOL)shouldLayoutForRTL { + if (self.semanticContentAttribute == UISemanticContentAttributeForceRightToLeft) { + return YES; + } else if (self.semanticContentAttribute == UISemanticContentAttributeForceLeftToRight) { + return NO; + } else { + return self.mdf_effectiveUserInterfaceLayoutDirection == + UIUserInterfaceLayoutDirectionRightToLeft; + } +} + #pragma mark UITextField Accessor Overrides - (void)setEnabled:(BOOL)enabled { @@ -301,23 +314,15 @@ - (void)setRightView:(UIView *)rightView { #pragma mark Custom Accessors - (UILabel *)leadingAssistiveLabel { - if ([self isRTL]) { - return self.assistiveLabelView.rightAssistiveLabel; - } else { - return self.assistiveLabelView.leftAssistiveLabel; - } + return self.assistiveLabelView.leadingAssistiveLabel; } - (UILabel *)trailingAssistiveLabel { - if ([self isRTL]) { - return self.assistiveLabelView.leftAssistiveLabel; - } else { - return self.assistiveLabelView.rightAssistiveLabel; - } + return self.assistiveLabelView.trailingAssistiveLabel; } - (void)setTrailingView:(UIView *)trailingView { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { [self mdc_setLeftView:trailingView]; } else { [self mdc_setRightView:trailingView]; @@ -325,7 +330,7 @@ - (void)setTrailingView:(UIView *)trailingView { } - (UIView *)trailingView { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.leftView; } else { return self.rightView; @@ -333,7 +338,7 @@ - (UIView *)trailingView { } - (void)setLeadingView:(UIView *)leadingView { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { [self mdc_setRightView:leadingView]; } else { [self mdc_setLeftView:leadingView]; @@ -341,7 +346,7 @@ - (void)setLeadingView:(UIView *)leadingView { } - (UIView *)leadingView { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.rightView; } else { return self.leftView; @@ -357,7 +362,7 @@ - (void)mdc_setRightView:(UIView *)rightView { } - (void)setTrailingViewMode:(UITextFieldViewMode)trailingViewMode { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { [self mdc_setLeftViewMode:trailingViewMode]; } else { [self mdc_setRightViewMode:trailingViewMode]; @@ -365,7 +370,7 @@ - (void)setTrailingViewMode:(UITextFieldViewMode)trailingViewMode { } - (UITextFieldViewMode)trailingViewMode { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.leftViewMode; } else { return self.rightViewMode; @@ -373,7 +378,7 @@ - (UITextFieldViewMode)trailingViewMode { } - (void)setLeadingViewMode:(UITextFieldViewMode)leadingViewMode { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { [self mdc_setRightViewMode:leadingViewMode]; } else { [self mdc_setLeftViewMode:leadingViewMode]; @@ -381,7 +386,7 @@ - (void)setLeadingViewMode:(UITextFieldViewMode)leadingViewMode { } - (UITextFieldViewMode)leadingViewMode { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.rightViewMode; } else { return self.leftViewMode; @@ -396,14 +401,6 @@ - (void)mdc_setRightViewMode:(UITextFieldViewMode)rightViewMode { [super setRightViewMode:rightViewMode]; } -- (void)setLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection { - if (_layoutDirection == layoutDirection) { - return; - } - _layoutDirection = layoutDirection; - [self setNeedsLayout]; -} - #pragma mark MDCTextControl accessors - (void)setLabelBehavior:(MDCTextControlLabelBehavior)labelBehavior { @@ -452,7 +449,7 @@ - (CGRect)editingRectForBounds:(CGRect)bounds { // @c rightView, even though @c rightView is nil. The RTL-aware wrappers around these APIs that // MDCBaseTextField introduce handle this situation more accurately. - (CGRect)leftViewRectForBounds:(CGRect)bounds { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.layout.rightViewFrame; } else { return self.layout.leftViewFrame; @@ -460,7 +457,7 @@ - (CGRect)leftViewRectForBounds:(CGRect)bounds { } - (CGRect)rightViewRectForBounds:(CGRect)bounds { - if ([self isRTL]) { + if ([self shouldLayoutForRTL]) { return self.layout.leftViewFrame; } else { return self.layout.rightViewFrame; @@ -641,12 +638,6 @@ - (MDCTextControlLabelState)labelStateWithLabel:(UILabel *)label } } -#pragma mark Internationalization - -- (BOOL)isRTL { - return self.layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; -} - #pragma mark Coloring - (void)applyColorViewModel:(MDCTextControlColorViewModel *)colorViewModel diff --git a/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.h b/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.h index 37dad6f44d2..f9884d432ab 100644 --- a/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.h +++ b/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.h @@ -59,8 +59,8 @@ rightViewMode:(UITextFieldViewMode)rightViewMode clearButtonSideLength:(CGFloat)clearButtonSideLength clearButtonMode:(UITextFieldViewMode)clearButtonMode - leftAssistiveLabel:(nonnull UILabel *)leftAssistiveLabel - rightAssistiveLabel:(nonnull UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(nonnull UILabel *)leftAssistiveLabel + trailingAssistiveLabel:(nonnull UILabel *)rightAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority diff --git a/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.m b/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.m index 60b4acf6f5c..fa10d29ccab 100644 --- a/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.m +++ b/components/TextControls/src/BaseTextFields/private/MDCBaseTextFieldLayout.m @@ -38,8 +38,8 @@ - (instancetype)initWithTextFieldSize:(CGSize)textFieldSize rightViewMode:(UITextFieldViewMode)rightViewMode clearButtonSideLength:(CGFloat)clearButtonSideLength clearButtonMode:(UITextFieldViewMode)clearButtonMode - leftAssistiveLabel:(nonnull UILabel *)leftAssistiveLabel - rightAssistiveLabel:(nonnull UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(nonnull UILabel *)leadingAssistiveLabel + trailingAssistiveLabel:(nonnull UILabel *)trailingAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority @@ -59,8 +59,8 @@ - (instancetype)initWithTextFieldSize:(CGSize)textFieldSize rightViewMode:rightViewMode clearButtonSideLength:clearButtonSideLength clearButtonMode:clearButtonMode - leftAssistiveLabel:leftAssistiveLabel - rightAssistiveLabel:rightAssistiveLabel + leadingAssistiveLabel:leadingAssistiveLabel + trailingAssistiveLabel:trailingAssistiveLabel assistiveLabelDrawPriority:assistiveLabelDrawPriority customAssistiveLabelDrawPriority:customAssistiveLabelDrawPriority isRTL:isRTL @@ -85,8 +85,8 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize rightViewMode:(UITextFieldViewMode)rightViewMode clearButtonSideLength:(CGFloat)clearButtonSideLength clearButtonMode:(UITextFieldViewMode)clearButtonMode - leftAssistiveLabel:(nonnull UILabel *)leftAssistiveLabel - rightAssistiveLabel:(nonnull UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(nonnull UILabel *)leadingAssistiveLabel + trailingAssistiveLabel:(nonnull UILabel *)trailingAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority @@ -236,8 +236,8 @@ - (void)calculateLayoutWithTextFieldSize:(CGSize)textFieldSize self.assistiveLabelViewLayout = [[MDCTextControlAssistiveLabelViewLayout alloc] initWithWidth:textFieldWidth - leftAssistiveLabel:leftAssistiveLabel - rightAssistiveLabel:rightAssistiveLabel + leadingAssistiveLabel:leadingAssistiveLabel + trailingAssistiveLabel:trailingAssistiveLabel assistiveLabelDrawPriority:assistiveLabelDrawPriority customAssistiveLabelDrawPriority:customAssistiveLabelDrawPriority horizontalPadding:kHorizontalPadding diff --git a/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldLayoutTests.m b/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldLayoutTests.m index f3a4ebc3cec..405699c54cb 100644 --- a/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldLayoutTests.m +++ b/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldLayoutTests.m @@ -57,8 +57,8 @@ - (MDCBaseTextFieldLayout *)createLayoutWithSideViewsAndViewMode:(UITextFieldVie rightViewMode:viewMode clearButtonSideLength:19 clearButtonMode:viewMode - leftAssistiveLabel:assistiveLabelView.leftAssistiveLabel - rightAssistiveLabel:assistiveLabelView.rightAssistiveLabel + leadingAssistiveLabel:assistiveLabelView.leadingAssistiveLabel + trailingAssistiveLabel:assistiveLabelView.trailingAssistiveLabel assistiveLabelDrawPriority:MDCTextControlAssistiveLabelDrawPriorityTrailing customAssistiveLabelDrawPriority:0 isRTL:NO diff --git a/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldTests.m b/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldTests.m index 8096666cf3a..8b224115b87 100644 --- a/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldTests.m +++ b/components/TextControls/tests/unit/BaseTextFields/MDCBaseTextFieldTests.m @@ -18,7 +18,7 @@ #import "MaterialTextControlsPrivate+BaseStyle.h" @interface MDCBaseTextField (Private) -@property(nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection; +- (BOOL)shouldLayoutForRTL; - (CGRect)adjustTextAreaFrame:(CGRect)textRect withParentClassTextAreaFrame:(CGRect)parentClassTextAreaFrame; - (BOOL)shouldPlaceholderBeVisibleWithPlaceholder:(NSString *)placeholder @@ -44,7 +44,7 @@ - (UIView *)createSideView { - (void)testLeadingViewEqualsLeftViewInLTR { // Given MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; - textField.layoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; + textField.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; // When UIView *sideView = [self createSideView]; @@ -58,7 +58,7 @@ - (void)testLeadingViewEqualsLeftViewInLTR { - (void)testLeadingViewEqualsRightViewInRTL { // Given MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; - textField.layoutDirection = UIUserInterfaceLayoutDirectionRightToLeft; + textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; // When UIView *sideView = [self createSideView]; @@ -72,7 +72,7 @@ - (void)testLeadingViewEqualsRightViewInRTL { - (void)testTrailingViewEqualsRightViewInLTR { // Given MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; - textField.layoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; + textField.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; // When UIView *sideView = [self createSideView]; @@ -86,7 +86,7 @@ - (void)testTrailingViewEqualsRightViewInLTR { - (void)testTrailingViewEqualsLeftViewInRTL { // Given MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; - textField.layoutDirection = UIUserInterfaceLayoutDirectionRightToLeft; + textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; // When UIView *sideView = [self createSideView]; @@ -102,7 +102,7 @@ - (void)testLeadingViewModeEqualsLeftViewModeInLTR { MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; // When - textField.layoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; + textField.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; textField.leadingViewMode = UITextFieldViewModeAlways; // Then @@ -115,7 +115,7 @@ - (void)testLeadingViewModeEqualsRightViewModeInRTL { MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; // When - textField.layoutDirection = UIUserInterfaceLayoutDirectionRightToLeft; + textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; textField.leadingViewMode = UITextFieldViewModeAlways; // Then @@ -128,7 +128,7 @@ - (void)testTrailingViewModeEqualsRightViewModeInLTR { MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; // When - textField.layoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; + textField.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; textField.trailingViewMode = UITextFieldViewModeAlways; // Then @@ -141,7 +141,7 @@ - (void)testTrailingViewModeEqualsLeftViewModeInRTL { MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:CGRectMake(0, 0, 100, 60)]; // When - textField.layoutDirection = UIUserInterfaceLayoutDirectionRightToLeft; + textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; textField.trailingViewMode = UITextFieldViewModeAlways; // Then @@ -489,4 +489,28 @@ - (void)testIntrinsicContentInvalidationWhenCalculatedHeightChanges { intrinsicContentSizeBeforeCalculatedHeightChange.height); } +- (void)testShouldLayoutForRTLWhenForcingRTL { + // Given + CGRect textFieldFrame = CGRectMake(0, 0, 100, 100); + MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:textFieldFrame]; + + // When + textField.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; + + // Then + XCTAssertTrue(textField.shouldLayoutForRTL); +} + +- (void)testShouldLayoutForRTLWhenForcingLTR { + // Given + CGRect textFieldFrame = CGRectMake(0, 0, 100, 100); + MDCBaseTextField *textField = [[MDCBaseTextField alloc] initWithFrame:textFieldFrame]; + + // When + textField.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; + + // Then + XCTAssertFalse(textField.shouldLayoutForRTL); +} + @end diff --git a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.h b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.h index 65e86a8f688..f69450142d1 100644 --- a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.h +++ b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.h @@ -24,8 +24,8 @@ */ @interface MDCTextControlAssistiveLabelView : UIView -@property(nonatomic, strong, readonly, nonnull) UILabel *leftAssistiveLabel; -@property(nonatomic, strong, readonly, nonnull) UILabel *rightAssistiveLabel; +@property(nonatomic, strong, readonly, nonnull) UILabel *leadingAssistiveLabel; +@property(nonatomic, strong, readonly, nonnull) UILabel *trailingAssistiveLabel; @property(nonatomic, strong, nonnull) MDCTextControlAssistiveLabelViewLayout *layout; @end diff --git a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.m b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.m index 845acef8d11..80515a3b091 100644 --- a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.m +++ b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelView.m @@ -15,8 +15,8 @@ #import "MDCTextControlAssistiveLabelView.h" @interface MDCTextControlAssistiveLabelView () -@property(nonatomic, strong) UILabel *leftAssistiveLabel; -@property(nonatomic, strong) UILabel *rightAssistiveLabel; +@property(nonatomic, strong) UILabel *leadingAssistiveLabel; +@property(nonatomic, strong) UILabel *trailingAssistiveLabel; @end @implementation MDCTextControlAssistiveLabelView @@ -38,20 +38,20 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)commonMDCTextControlAssistiveLabelViewInit { - self.leftAssistiveLabel = [[UILabel alloc] init]; - self.leftAssistiveLabel.numberOfLines = 0; - [self addSubview:self.leftAssistiveLabel]; - self.rightAssistiveLabel = [[UILabel alloc] init]; - self.rightAssistiveLabel.numberOfLines = 0; - [self addSubview:self.rightAssistiveLabel]; + self.leadingAssistiveLabel = [[UILabel alloc] init]; + self.leadingAssistiveLabel.numberOfLines = 0; + [self addSubview:self.leadingAssistiveLabel]; + self.trailingAssistiveLabel = [[UILabel alloc] init]; + self.trailingAssistiveLabel.numberOfLines = 0; + [self addSubview:self.trailingAssistiveLabel]; } - (void)layoutSubviews { [super layoutSubviews]; - self.leftAssistiveLabel.frame = self.layout.leftAssistiveLabelFrame; - self.leftAssistiveLabel.hidden = self.layout == nil; - self.rightAssistiveLabel.frame = self.layout.rightAssistiveLabelFrame; - self.rightAssistiveLabel.hidden = self.layout == nil; + self.leadingAssistiveLabel.frame = self.layout.leadingAssistiveLabelFrame; + self.leadingAssistiveLabel.hidden = self.layout == nil; + self.trailingAssistiveLabel.frame = self.layout.trailingAssistiveLabelFrame; + self.trailingAssistiveLabel.hidden = self.layout == nil; } @end diff --git a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.h b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.h index 89fdaa8b306..494ee37ec35 100644 --- a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.h +++ b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.h @@ -26,13 +26,13 @@ */ @interface MDCTextControlAssistiveLabelViewLayout : NSObject -@property(nonatomic, assign, readonly) CGRect leftAssistiveLabelFrame; -@property(nonatomic, assign, readonly) CGRect rightAssistiveLabelFrame; +@property(nonatomic, assign, readonly) CGRect leadingAssistiveLabelFrame; +@property(nonatomic, assign, readonly) CGRect trailingAssistiveLabelFrame; @property(nonatomic, assign, readonly) CGFloat calculatedHeight; - (instancetype)initWithWidth:(CGFloat)superviewWidth - leftAssistiveLabel:(UILabel *)leftAssistiveLabel - rightAssistiveLabel:(UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(UILabel *)leadingAssistiveLabel + trailingAssistiveLabel:(UILabel *)trailingAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority diff --git a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.m b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.m index 0b88ccc40f5..9d5f2a45109 100644 --- a/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.m +++ b/components/private/TextControlsPrivate/src/Shared/MDCTextControlAssistiveLabelViewLayout.m @@ -16,8 +16,8 @@ @interface MDCTextControlAssistiveLabelViewLayout () -@property(nonatomic, assign) CGRect leftAssistiveLabelFrame; -@property(nonatomic, assign) CGRect rightAssistiveLabelFrame; +@property(nonatomic, assign) CGRect leadingAssistiveLabelFrame; +@property(nonatomic, assign) CGRect trailingAssistiveLabelFrame; @property(nonatomic, assign) CGFloat calculatedHeight; @end @@ -27,8 +27,8 @@ @implementation MDCTextControlAssistiveLabelViewLayout #pragma mark Object Lifecycle - (instancetype)initWithWidth:(CGFloat)superviewWidth - leftAssistiveLabel:(UILabel *)leftAssistiveLabel - rightAssistiveLabel:(UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(UILabel *)leadingAssistiveLabel + trailingAssistiveLabel:(UILabel *)trailingAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority @@ -39,8 +39,8 @@ - (instancetype)initWithWidth:(CGFloat)superviewWidth self = [super init]; if (self) { [self calculateLayoutWithSuperviewWidth:superviewWidth - leftAssistiveLabel:leftAssistiveLabel - rightAssistiveLabel:rightAssistiveLabel + leadingAssistiveLabel:leadingAssistiveLabel + trailingAssistiveLabel:trailingAssistiveLabel assistiveLabelDrawPriority:assistiveLabelDrawPriority customAssistiveLabelDrawPriority:customAssistiveLabelDrawPriority horizontalPadding:horizontalPadding @@ -55,8 +55,8 @@ - (instancetype)initWithWidth:(CGFloat)superviewWidth #pragma mark Layout Calculation - (void)calculateLayoutWithSuperviewWidth:(CGFloat)superviewWidth - leftAssistiveLabel:(UILabel *)leftAssistiveLabel - rightAssistiveLabel:(UILabel *)rightAssistiveLabel + leadingAssistiveLabel:(UILabel *)leadingAssistiveLabel + trailingAssistiveLabel:(UILabel *)trailingAssistiveLabel assistiveLabelDrawPriority: (MDCTextControlAssistiveLabelDrawPriority)assistiveLabelDrawPriority customAssistiveLabelDrawPriority:(CGFloat)customAssistiveLabelDrawPriority @@ -74,8 +74,6 @@ - (void)calculateLayoutWithSuperviewWidth:(CGFloat)superviewWidth CGFloat trailingAssistiveLabelWidth = 0; CGSize leadingAssistiveLabelSize = CGSizeZero; CGSize trailingAssistiveLabelSize = CGSizeZero; - UILabel *leadingAssistiveLabel = isRTL ? rightAssistiveLabel : leftAssistiveLabel; - UILabel *trailingAssistiveLabel = isRTL ? leftAssistiveLabel : rightAssistiveLabel; switch (assistiveLabelDrawPriority) { case MDCTextControlAssistiveLabelDrawPriorityCustom: leadingAssistiveLabelWidth = [self @@ -121,8 +119,8 @@ - (void)calculateLayoutWithSuperviewWidth:(CGFloat)superviewWidth BOOL leadingAssistiveLabelIsVisible = !CGSizeEqualToSize(leadingAssistiveLabelSize, CGSizeZero); BOOL trailingAssistiveLabelIsVisible = !CGSizeEqualToSize(trailingAssistiveLabelSize, CGSizeZero); if (!leadingAssistiveLabelIsVisible && !trailingAssistiveLabelIsVisible) { - self.leftAssistiveLabelFrame = CGRectZero; - self.rightAssistiveLabelFrame = CGRectZero; + self.leadingAssistiveLabelFrame = CGRectZero; + self.trailingAssistiveLabelFrame = CGRectZero; self.calculatedHeight = 0; return; } @@ -144,8 +142,8 @@ - (void)calculateLayoutWithSuperviewWidth:(CGFloat)superviewWidth CGFloat maxAssistiveLabelHeight = MAX(CGRectGetMaxY(leftAssistiveLabelFrame), CGRectGetMaxY(rightAssistiveLabelFrame)); - self.leftAssistiveLabelFrame = leftAssistiveLabelFrame; - self.rightAssistiveLabelFrame = rightAssistiveLabelFrame; + self.leadingAssistiveLabelFrame = isRTL ? rightAssistiveLabelFrame : leftAssistiveLabelFrame; + self.trailingAssistiveLabelFrame = isRTL ? leftAssistiveLabelFrame : rightAssistiveLabelFrame; self.calculatedHeight = maxAssistiveLabelHeight + paddingBelowAssistiveLabels; }