From 86089751896266195734d290330bf0c26f7cc057 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 6 Jun 2019 09:13:52 -0700 Subject: [PATCH] Don't apply empty attributed string for TextInput (#25143) Summary: Issue reported by Titozzz , `TextInput` would shrink when we have attributes like `lineHeight`. Demonstration can see GIF like below: https://giphy.com/gifs/KGNs1qIMHF3DIk1EPK I think the reason is we apply an empty attributed string to `UITextField`, now if the length is 0, we just nil the `attributedText` instead. ## Changelog [iOS] [Fixed] - Don't apply empty attributed string for TextInput Pull Request resolved: https://github.com/facebook/react-native/pull/25143 Differential Revision: D15661751 Pulled By: sammy-SC fbshipit-source-id: 9770484a1b68a6409e63ea25ac9a6fd0d3589b14 --- Libraries/Text/TextInput/RCTBaseTextInputShadowView.m | 7 ++++++- Libraries/Text/TextInput/RCTBaseTextInputView.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m b/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m index c79d65e136f88f..c6cc08bb8bf0f3 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m @@ -174,7 +174,12 @@ - (void)uiManagerWillPerformMounting baseTextInputView.reactPaddingInsets = paddingInsets; if (isAttributedTextChanged) { - baseTextInputView.attributedText = attributedText; + // Don't set `attributedText` if length equal to zero, otherwise it would shrink when attributes contain like `lineHeight`. + if (attributedText.length != 0) { + baseTextInputView.attributedText = attributedText; + } else { + baseTextInputView.attributedText = nil; + } } }]; } diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.h b/Libraries/Text/TextInput/RCTBaseTextInputView.h index 5b62f90251492e..ead709672f8f9a 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.h +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.h @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL secureTextEntry; @property (nonatomic, copy) RCTTextSelection *selection; @property (nonatomic, strong, nullable) NSNumber *maxLength; -@property (nonatomic, copy) NSAttributedString *attributedText; +@property (nonatomic, copy, nullable) NSAttributedString *attributedText; @property (nonatomic, copy) NSString *inputAccessoryViewID; @property (nonatomic, assign) UIKeyboardType keyboardType;