Skip to content

Commit

Permalink
Don't apply empty attributed string for TextInput (#25143)
Browse files Browse the repository at this point in the history
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: #25143

Differential Revision: D15661751

Pulled By: sammy-SC

fbshipit-source-id: 9770484a1b68a6409e63ea25ac9a6fd0d3589b14
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Jun 6, 2019
1 parent 63bc4b4 commit 9b61896
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Libraries/Text/TextInput/RCTBaseTextInputShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}];
}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/TextInput/RCTBaseTextInputView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9b61896

Please sign in to comment.