mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 17:34:07 +08:00
Fixed singleline text input placeholder size (#23745)
Summary: After #23738 , we can add more text attributes to placeholder, so now, let's update the calculation of placeholder size based on placeholder attributes. [iOS] [Fixed] - Fixed singleline text input placeholder size Pull Request resolved: https://github.com/facebook/react-native/pull/23745 Differential Revision: D14320630 Pulled By: cpojer fbshipit-source-id: 2d9e8b59ba70228202add762cfc9c6cbc77e5e95
This commit is contained in:
committed by
Facebook Github Bot
parent
fd954cda55
commit
ba6f818d7d
@@ -84,17 +84,8 @@
|
||||
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
|
||||
@@ -117,6 +108,23 @@
|
||||
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
|
||||
@@ -183,7 +191,7 @@
|
||||
{
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user