From 17be5effdcf78755ac9bebb00f18ceecbbefe641 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Mon, 22 May 2023 16:49:06 +0800 Subject: [PATCH 1/9] Fix TextInput vertical alignment issue when using lineHeight prop on iOS (Paper - old arch) --- .../Libraries/Text/RCTTextAttributes.m | 14 ++++++++--- .../Text/TextInput/Multiline/RCTUITextView.h | 3 +++ .../Text/TextInput/Multiline/RCTUITextView.m | 8 +++++++ .../RCTBackedTextInputViewProtocol.h | 3 +++ .../TextInput/RCTBaseTextInputShadowView.m | 18 +++++++++++++++ .../Text/TextInput/RCTBaseTextInputView.h | 2 ++ .../Text/TextInput/RCTBaseTextInputView.m | 23 ++++++++++++++++--- .../TextInput/Singleline/RCTUITextField.h | 2 ++ .../TextInput/Singleline/RCTUITextField.m | 18 ++++++++++++++- 9 files changed, 84 insertions(+), 7 deletions(-) diff --git a/packages/react-native/Libraries/Text/RCTTextAttributes.m b/packages/react-native/Libraries/Text/RCTTextAttributes.m index c8323388ce684b..c2ca6407a9778f 100644 --- a/packages/react-native/Libraries/Text/RCTTextAttributes.m +++ b/packages/react-native/Libraries/Text/RCTTextAttributes.m @@ -130,9 +130,12 @@ - (NSParagraphStyle *)effectiveParagraphStyle if (!isnan(_lineHeight)) { CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier; - paragraphStyle.minimumLineHeight = lineHeight; - paragraphStyle.maximumLineHeight = lineHeight; - isParagraphStyleUsed = YES; + // text with lineHeight lower then font.lineHeight does not correctly vertically align + if (lineHeight > self.effectiveFont.lineHeight) { + paragraphStyle.minimumLineHeight = lineHeight; + paragraphStyle.maximumLineHeight = lineHeight; + isParagraphStyleUsed = YES; + } } if (isParagraphStyleUsed) { @@ -172,6 +175,11 @@ - (NSParagraphStyle *)effectiveParagraphStyle NSParagraphStyle *paragraphStyle = [self effectiveParagraphStyle]; if (paragraphStyle) { attributes[NSParagraphStyleAttributeName] = paragraphStyle; + // The baseline aligns the text vertically in the line height + if (!isnan(paragraphStyle.maximumLineHeight) && paragraphStyle.maximumLineHeight >= font.lineHeight) { + CGFloat baseLineOffset = (paragraphStyle.maximumLineHeight - font.lineHeight) / 2.0; + attributes[NSBaselineOffsetAttributeName] = @(baseLineOffset); + } } // Decoration diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h index 1215ff0843402f..fa19bf1cfaafac 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h @@ -26,6 +26,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) BOOL textWasPasted; @property (nonatomic, copy, nullable) NSString *placeholder; @property (nonatomic, strong, nullable) UIColor *placeholderColor; +@property (nonatomic, assign) CGRect fragmentViewContainerBounds; +@property (nonatomic, assign) UIEdgeInsets textBorderInsets; +@property (nonatomic, assign) UIControlContentVerticalAlignment contentVerticalAlignment; @property (nonatomic, assign) CGFloat preferredMaxLayoutWidth; diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 5d5d3085879ba2..ef505dd9b3b417 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -169,6 +169,14 @@ - (void)paste:(id)sender [super paste:sender]; } +- (void)setTextBorderInsetsAndFrame:(CGRect)bounds textBorderInsets:(UIEdgeInsets)textBorderInsets +{ + _textBorderInsets = textBorderInsets; + // We apply `borderInsets` as `RCTUITextView` layout offset. + self.frame = UIEdgeInsetsInsetRect(bounds, textBorderInsets); + [self setNeedsLayout]; +} + // Turn off scroll animation to fix flaky scrolling. // This is only necessary for iOS <= 13. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED < 140000 diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h index 686af9e3a363e2..ba3d79d6ae73e6 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +++ b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) CGFloat zoomScale; @property (nonatomic, assign, readonly) CGPoint contentOffset; @property (nonatomic, assign, readonly) UIEdgeInsets contentInset; +@property (nonatomic, assign) CGRect fragmentViewContainerBounds; +@property (nonatomic, assign) UIControlContentVerticalAlignment contentVerticalAlignment; // This protocol disallows direct access to `selectedTextRange` property because // unwise usage of it can break the `delegate` behavior. So, we always have to @@ -42,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN // If the change was a result of user actions (like typing or touches), we MUST notify the delegate. - (void)setSelectedTextRange:(nullable UITextRange *)selectedTextRange NS_UNAVAILABLE; - (void)setSelectedTextRange:(nullable UITextRange *)selectedTextRange notifyDelegate:(BOOL)notifyDelegate; +- (void)setTextBorderInsetsAndFrame:(CGRect)bounds textBorderInsets:(UIEdgeInsets)textBorderInsets; // This protocol disallows direct access to `text` property because // unwise usage of it can break the `attributeText` behavior. diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m index 9d777436763f24..7db8fc96a024a6 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m @@ -177,6 +177,24 @@ - (void)uiManagerWillPerformMounting baseTextInputView.textAttributes = textAttributes; baseTextInputView.reactBorderInsets = borderInsets; + + // Fixes iOS issue caused by adding paragraphStyle.maximumLineHeight to an iOS UITextField. + // The CALayer _UITextLayoutFragmentView does not align correctly (see issue #28012). + if (!isnan(textAttributes.lineHeight) && !isnan(textAttributes.effectiveFont.lineHeight)) { + CGFloat effectiveLineHeight = textAttributes.lineHeight * textAttributes.effectiveFontSizeMultiplier; + CGFloat fontLineHeight = textAttributes.effectiveFont.lineHeight; + if (effectiveLineHeight >= fontLineHeight * 2.0) { + CGFloat height = self.layoutMetrics.frame.size.height; + CGFloat width = self.layoutMetrics.frame.size.width; + // sets the same origin.y coordinates for _UITextLayoutFragmentView and UITextField frame + baseTextInputView.contentVerticalAlignment = UIControlContentVerticalAlignmentTop; + // vertically center aligns the _UITextLayoutFragmentView in the parent UITextField + CGFloat padding = (height - effectiveLineHeight) / 2.0; + baseTextInputView.fragmentViewContainerBounds = CGRectMake(0, padding, width, effectiveLineHeight); + } + } else { + baseTextInputView.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + } baseTextInputView.reactPaddingInsets = paddingInsets; if (newAttributedText) { diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h index 209947de9b4aaa..7258c36e1d8b8f 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h @@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, nullable) RCTTextAttributes *textAttributes; @property (nonatomic, assign) UIEdgeInsets reactPaddingInsets; @property (nonatomic, assign) UIEdgeInsets reactBorderInsets; +@property (nonatomic, assign) CGRect fragmentViewContainerBounds; +@property (nonatomic, assign) UIControlContentVerticalAlignment contentVerticalAlignment; @property (nonatomic, copy, nullable) RCTDirectEventBlock onContentSizeChange; @property (nonatomic, copy, nullable) RCTDirectEventBlock onSelectionChange; diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m index ec473bcef5df4f..05fab973828669 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -76,6 +76,22 @@ - (void)enforceTextAttributesIfNeeded backedTextInputView.defaultTextAttributes = textAttributes; } +// Fixes iOS alignment issue caused by adding paragraphStyle.maximumLineHeight to an iOS UITextField +// vertically aligns _UITextLayoutFragmentView with the parent view UITextField +- (void)setContentVerticalAlignment:(UIControlContentVerticalAlignment)contentVerticalAlignment +{ + _contentVerticalAlignment = contentVerticalAlignment; + self.backedTextInputView.contentVerticalAlignment = contentVerticalAlignment; +} + +// Custom bounds used to control vertical position of CALayer _UITextLayoutFragmentView +// _UITextLayoutFragmentView is the CALayer of UITextField +- (void)setFragmentViewContainerBounds:(CGRect)fragmentViewContainerBounds +{ + _fragmentViewContainerBounds = fragmentViewContainerBounds; + self.backedTextInputView.fragmentViewContainerBounds = fragmentViewContainerBounds; +} + - (void)setReactPaddingInsets:(UIEdgeInsets)reactPaddingInsets { _reactPaddingInsets = reactPaddingInsets; @@ -87,9 +103,8 @@ - (void)setReactPaddingInsets:(UIEdgeInsets)reactPaddingInsets - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets { _reactBorderInsets = reactBorderInsets; - // We apply `borderInsets` as `backedTextInputView` layout offset. - self.backedTextInputView.frame = UIEdgeInsetsInsetRect(self.bounds, reactBorderInsets); - [self setNeedsLayout]; + // Borders are added using insets (UITextField textRectForBound, UITextView setFrame) + [self.backedTextInputView setTextBorderInsetsAndFrame:self.bounds textBorderInsets:reactBorderInsets]; } - (NSAttributedString *)attributedText @@ -515,6 +530,8 @@ - (void)textInputDidChangeSelection } RCTTextSelection *selection = self.selection; + UITextRange *selectedTextRange = self.backedTextInputView.selectedTextRange; + CGPoint selectionOrigin = [self.backedTextInputView caretRectForPosition:selectedTextRange.start].origin; _onSelectionChange(@{ @"selection" : @{ diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h index b26b41f8693d7b..e850331c5f26fc 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h @@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) BOOL textWasPasted; @property (nonatomic, strong, nullable) UIColor *placeholderColor; @property (nonatomic, assign) UIEdgeInsets textContainerInset; +@property (nonatomic, assign) CGRect fragmentViewContainerBounds; +@property (nonatomic, assign) UIEdgeInsets textBorderInsets; @property (nonatomic, assign, getter=isEditable) BOOL editable; @property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled; @property (nonatomic, strong, nullable) NSString *inputAccessoryViewID; diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 3d116019b89cde..f97325a20a107d 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -55,6 +55,12 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset [self setNeedsLayout]; } +- (void)setTextBorderInsetsAndFrame:(CGRect)bounds textBorderInsets:(UIEdgeInsets)textBorderInsets +{ + _textBorderInsets = textBorderInsets; + [self setNeedsLayout]; +} + - (void)setPlaceholder:(NSString *)placeholder { [super setPlaceholder:placeholder]; @@ -157,7 +163,17 @@ - (CGRect)caretRectForPosition:(UITextPosition *)position - (CGRect)textRectForBounds:(CGRect)bounds { - return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], _textContainerInset); + // Text is vertically aligned to the center + CGFloat leftPadding = _textContainerInset.left + _textBorderInsets.left; + CGFloat rightPadding = _textContainerInset.right + _textBorderInsets.right; + UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); + if (self.fragmentViewContainerBounds.size.height > 0) { + // apply custom bounds to fix iOS UITextField issue with lineHeight + // sets the correct y coordinates for _UITextLayoutFragmentView + return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds], borderAndPaddingInsets); + } else { + return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], borderAndPaddingInsets); + } } - (CGRect)editingRectForBounds:(CGRect)bounds From dfc2b2086fbfe44e31077d8aef3c640d4251d145 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Tue, 23 May 2023 10:09:39 +0800 Subject: [PATCH 2/9] fix indentation --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index f97325a20a107d..640aa23d9b1a48 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -172,7 +172,7 @@ - (CGRect)textRectForBounds:(CGRect)bounds // sets the correct y coordinates for _UITextLayoutFragmentView return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds], borderAndPaddingInsets); } else { - return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], borderAndPaddingInsets); + return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], borderAndPaddingInsets); } } From 7dbfde41615cb44b7b22d4e77d057f4dd91db35d Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Tue, 23 May 2023 10:39:23 +0800 Subject: [PATCH 3/9] revert fix from PR #54 --- .../Libraries/Text/TextInput/RCTBaseTextInputView.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m index 05fab973828669..8b1956f3742724 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -530,8 +530,6 @@ - (void)textInputDidChangeSelection } RCTTextSelection *selection = self.selection; - UITextRange *selectedTextRange = self.backedTextInputView.selectedTextRange; - CGPoint selectionOrigin = [self.backedTextInputView caretRectForPosition:selectedTextRange.start].origin; _onSelectionChange(@{ @"selection" : @{ From 12b51ddb8b995e4a08278d5094c6d2c838c09f04 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Thu, 25 May 2023 11:09:07 +0800 Subject: [PATCH 4/9] update code comments https://github.com/Expensify/react-native/pull/57/files#r1204428114 --- .../react-native/Libraries/Text/RCTTextAttributes.m | 6 ++++-- .../Text/TextInput/Multiline/RCTUITextView.m | 3 ++- .../Text/TextInput/RCTBaseTextInputShadowView.m | 11 +++++++---- .../Libraries/Text/TextInput/RCTBaseTextInputView.m | 9 +++++---- .../Text/TextInput/Singleline/RCTUITextField.m | 6 +++--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/react-native/Libraries/Text/RCTTextAttributes.m b/packages/react-native/Libraries/Text/RCTTextAttributes.m index c2ca6407a9778f..cd0098b28bdbb0 100644 --- a/packages/react-native/Libraries/Text/RCTTextAttributes.m +++ b/packages/react-native/Libraries/Text/RCTTextAttributes.m @@ -130,7 +130,8 @@ - (NSParagraphStyle *)effectiveParagraphStyle if (!isnan(_lineHeight)) { CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier; - // text with lineHeight lower then font.lineHeight does not correctly vertically align + + // Text with lineHeight lower than font.lineHeight does not correctly vertically align. if (lineHeight > self.effectiveFont.lineHeight) { paragraphStyle.minimumLineHeight = lineHeight; paragraphStyle.maximumLineHeight = lineHeight; @@ -175,7 +176,8 @@ - (NSParagraphStyle *)effectiveParagraphStyle NSParagraphStyle *paragraphStyle = [self effectiveParagraphStyle]; if (paragraphStyle) { attributes[NSParagraphStyleAttributeName] = paragraphStyle; - // The baseline aligns the text vertically in the line height + + // The baseline aligns the text vertically in the line height (_UITextLayoutFragmentView). if (!isnan(paragraphStyle.maximumLineHeight) && paragraphStyle.maximumLineHeight >= font.lineHeight) { CGFloat baseLineOffset = (paragraphStyle.maximumLineHeight - font.lineHeight) / 2.0; attributes[NSBaselineOffsetAttributeName] = @(baseLineOffset); diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m index ef505dd9b3b417..b0015bc4b57864 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -172,7 +172,8 @@ - (void)paste:(id)sender - (void)setTextBorderInsetsAndFrame:(CGRect)bounds textBorderInsets:(UIEdgeInsets)textBorderInsets { _textBorderInsets = textBorderInsets; - // We apply `borderInsets` as `RCTUITextView` layout offset. + + // We apply `borderInsets` as the `RCTUITextView` layout offset. self.frame = UIEdgeInsetsInsetRect(bounds, textBorderInsets); [self setNeedsLayout]; } diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m index 7db8fc96a024a6..f959919f793cae 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m @@ -178,17 +178,20 @@ - (void)uiManagerWillPerformMounting baseTextInputView.textAttributes = textAttributes; baseTextInputView.reactBorderInsets = borderInsets; - // Fixes iOS issue caused by adding paragraphStyle.maximumLineHeight to an iOS UITextField. - // The CALayer _UITextLayoutFragmentView does not align correctly (see issue #28012). + // The CALayer _UITextLayoutFragmentView does not align correctly + // when adding paragraphStyle.maximumLineHeight to an iOS UITextField (issue #28012). if (!isnan(textAttributes.lineHeight) && !isnan(textAttributes.effectiveFont.lineHeight)) { CGFloat effectiveLineHeight = textAttributes.lineHeight * textAttributes.effectiveFontSizeMultiplier; CGFloat fontLineHeight = textAttributes.effectiveFont.lineHeight; if (effectiveLineHeight >= fontLineHeight * 2.0) { CGFloat height = self.layoutMetrics.frame.size.height; CGFloat width = self.layoutMetrics.frame.size.width; - // sets the same origin.y coordinates for _UITextLayoutFragmentView and UITextField frame + + // Setting contentVerticalAlignment to UIControlContentVerticalAlignmentTop aligns + // _UITextLayoutFragmentView and UITextField on the same ordinate (y coordinate). baseTextInputView.contentVerticalAlignment = UIControlContentVerticalAlignmentTop; - // vertically center aligns the _UITextLayoutFragmentView in the parent UITextField + + // Align vertically _UITextLayoutFragmentView in the center of the UITextField (TextInput). CGFloat padding = (height - effectiveLineHeight) / 2.0; baseTextInputView.fragmentViewContainerBounds = CGRectMake(0, padding, width, effectiveLineHeight); } diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m index 8b1956f3742724..4dbb31067367a8 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -77,15 +77,15 @@ - (void)enforceTextAttributesIfNeeded } // Fixes iOS alignment issue caused by adding paragraphStyle.maximumLineHeight to an iOS UITextField -// vertically aligns _UITextLayoutFragmentView with the parent view UITextField +// and vertically aligns _UITextLayoutFragmentView with the parent view UITextField. - (void)setContentVerticalAlignment:(UIControlContentVerticalAlignment)contentVerticalAlignment { _contentVerticalAlignment = contentVerticalAlignment; self.backedTextInputView.contentVerticalAlignment = contentVerticalAlignment; } -// Custom bounds used to control vertical position of CALayer _UITextLayoutFragmentView -// _UITextLayoutFragmentView is the CALayer of UITextField +// Custom bounds used to control vertical position of CALayer _UITextLayoutFragmentView. +// _UITextLayoutFragmentView is the CALayer of UITextField. - (void)setFragmentViewContainerBounds:(CGRect)fragmentViewContainerBounds { _fragmentViewContainerBounds = fragmentViewContainerBounds; @@ -103,7 +103,8 @@ - (void)setReactPaddingInsets:(UIEdgeInsets)reactPaddingInsets - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets { _reactBorderInsets = reactBorderInsets; - // Borders are added using insets (UITextField textRectForBound, UITextView setFrame) + + // Borders are added using insets (UITextField textRectForBound, UITextView setFrame). [self.backedTextInputView setTextBorderInsetsAndFrame:self.bounds textBorderInsets:reactBorderInsets]; } diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 640aa23d9b1a48..95971c93926366 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -163,13 +163,13 @@ - (CGRect)caretRectForPosition:(UITextPosition *)position - (CGRect)textRectForBounds:(CGRect)bounds { - // Text is vertically aligned to the center + // Text is vertically aligned to the center. CGFloat leftPadding = _textContainerInset.left + _textBorderInsets.left; CGFloat rightPadding = _textContainerInset.right + _textBorderInsets.right; UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); if (self.fragmentViewContainerBounds.size.height > 0) { - // apply custom bounds to fix iOS UITextField issue with lineHeight - // sets the correct y coordinates for _UITextLayoutFragmentView + // Apply custom bounds to fix iOS UITextField issue with lineHeight. + // Sets the correct y coordinates for _UITextLayoutFragmentView. return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds], borderAndPaddingInsets); } else { return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], borderAndPaddingInsets); From 613bf0a29dc3c68525fa8f1c193aa2e4e7350720 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Tue, 30 May 2023 10:48:10 +0800 Subject: [PATCH 5/9] changes requested in code review https://github.com/Expensify/react-native/pull/57#discussion_r1209482669 --- .../Text/TextInput/Singleline/RCTUITextField.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 95971c93926366..74b56fb289efc6 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -167,13 +167,9 @@ - (CGRect)textRectForBounds:(CGRect)bounds CGFloat leftPadding = _textContainerInset.left + _textBorderInsets.left; CGFloat rightPadding = _textContainerInset.right + _textBorderInsets.right; UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); - if (self.fragmentViewContainerBounds.size.height > 0) { - // Apply custom bounds to fix iOS UITextField issue with lineHeight. - // Sets the correct y coordinates for _UITextLayoutFragmentView. - return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds], borderAndPaddingInsets); - } else { - return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], borderAndPaddingInsets); - } + // The fragmentViewContainerBounds set the correct y coordinates for + // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. + return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds], borderAndPaddingInsets); } - (CGRect)editingRectForBounds:(CGRect)bounds From a5ac3c31c59e22c99991b4fb132d6a87cb3d56bc Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Tue, 30 May 2023 11:23:42 +0800 Subject: [PATCH 6/9] minor improvement --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 74b56fb289efc6..e08c5c94c3703a 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -169,7 +169,8 @@ - (CGRect)textRectForBounds:(CGRect)bounds UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); // The fragmentViewContainerBounds set the correct y coordinates for // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. - return UIEdgeInsetsInsetRect([super textRectForBounds:self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds], borderAndPaddingInsets); + CGRect updatedBounds = self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds; + return UIEdgeInsetsInsetRect([super textRectForBounds:updatedBounds], borderAndPaddingInsets); } - (CGRect)editingRectForBounds:(CGRect)bounds From 3d12d11080170c91407676576eac59b90afaf082 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Thu, 1 Jun 2023 13:52:32 +0800 Subject: [PATCH 7/9] adding a line break before comment --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.m | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index e08c5c94c3703a..8f28d376c28278 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -167,6 +167,7 @@ - (CGRect)textRectForBounds:(CGRect)bounds CGFloat leftPadding = _textContainerInset.left + _textBorderInsets.left; CGFloat rightPadding = _textContainerInset.right + _textBorderInsets.right; UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); + // The fragmentViewContainerBounds set the correct y coordinates for // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. CGRect updatedBounds = self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds; From 0dae434c15a064038bfb8903b1f4888a2d7388ff Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Thu, 1 Jun 2023 14:13:29 +0800 Subject: [PATCH 8/9] rerun ci --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 8f28d376c28278..79b653868aa5c0 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -169,7 +169,7 @@ - (CGRect)textRectForBounds:(CGRect)bounds UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); // The fragmentViewContainerBounds set the correct y coordinates for - // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. + // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. Rerun CI CGRect updatedBounds = self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds; return UIEdgeInsetsInsetRect([super textRectForBounds:updatedBounds], borderAndPaddingInsets); } From a1433f343e3c94fc465676d6c66f81e37ff1ec5e Mon Sep 17 00:00:00 2001 From: Fabrizio Bertoglio Date: Thu, 1 Jun 2023 14:29:18 +0800 Subject: [PATCH 9/9] remove comment rerun ci --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 79b653868aa5c0..8f28d376c28278 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -169,7 +169,7 @@ - (CGRect)textRectForBounds:(CGRect)bounds UIEdgeInsets borderAndPaddingInsets = UIEdgeInsetsMake(_textContainerInset.top, leftPadding, _textContainerInset.bottom, rightPadding); // The fragmentViewContainerBounds set the correct y coordinates for - // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. Rerun CI + // _UITextLayoutFragmentView to fix an iOS UITextField issue with lineHeight. CGRect updatedBounds = self.fragmentViewContainerBounds.size.height > 0 ? self.fragmentViewContainerBounds : bounds; return UIEdgeInsetsInsetRect([super textRectForBounds:updatedBounds], borderAndPaddingInsets); }