Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixed singleline text input placeholder size #23745

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.m
Expand Up @@ -84,17 +84,8 @@ - (void)_updatePlaceholder
return;
}

NSMutableDictionary *attributes = [NSMutableDictionary new];
if (_placeholderColor) {
[attributes setObject:_placeholderColor forKey:NSForegroundColorAttributeName];
}
// Kerning
if (!isnan(_reactTextAttributes.letterSpacing)) {
attributes[NSKernAttributeName] = @(_reactTextAttributes.letterSpacing);
}

self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder
attributes:attributes];
attributes:[self placeholderEffectiveTextAttributes]];
}

- (BOOL)isEditable
Expand All @@ -117,6 +108,23 @@ - (BOOL)scrollEnabled
return NO;
}

#pragma mark - Placeholder

- (NSDictionary<NSAttributedStringKey, id> *)placeholderEffectiveTextAttributes
{
NSMutableDictionary<NSAttributedStringKey, id> *effectiveTextAttributes = [NSMutableDictionary dictionary];

if (_placeholderColor) {
effectiveTextAttributes[NSForegroundColorAttributeName] = _placeholderColor;
}
// Kerning
if (!isnan(_reactTextAttributes.letterSpacing)) {
effectiveTextAttributes[NSKernAttributeName] = @(_reactTextAttributes.letterSpacing);
}

return [effectiveTextAttributes copy];
}

#pragma mark - Context Menu

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
Expand Down Expand Up @@ -183,7 +191,7 @@ - (CGSize)intrinsicContentSize
{
// Note: `placeholder` defines intrinsic size for `<TextInput>`.
NSString *text = self.placeholder ?: @"";
CGSize size = [text sizeWithAttributes:@{NSFontAttributeName: self.font}];
CGSize size = [text sizeWithAttributes:[self placeholderEffectiveTextAttributes]];
size = CGSizeMake(RCTCeilPixelValue(size.width), RCTCeilPixelValue(size.height));
size.width += _textContainerInset.left + _textContainerInset.right;
size.height += _textContainerInset.top + _textContainerInset.bottom;
Expand Down