Add lineHeight support of placeholder for multiline text input (#23760)

Summary:
After some refactor of text input attributes, we can now add style attributes  the same as text input's attributes, from https://github.com/facebook/react-native/issues/19002#issuecomment-467171589, user wants placeholder to support line-height , I think we can add it now for multiline text input.

[iOS] [Added] - Added lineHeight support of placeholder for multiline text input
Pull Request resolved: https://github.com/facebook/react-native/pull/23760

Differential Revision: D14320600

Pulled By: cpojer

fbshipit-source-id: ededeaa11560af089ca15ffc188e2e70db2ad7d4
This commit is contained in:
zhongwuzw 2019-03-04 21:45:48 -08:00 коммит произвёл Facebook Github Bot
Родитель aa3b0d99f4
Коммит fd954cda55
1 изменённых файлов: 13 добавлений и 6 удалений

Просмотреть файл

@ -252,13 +252,20 @@ static UIColor *defaultPlaceholderColor()
- (NSDictionary<NSAttributedStringKey, id> *)placeholderEffectiveTextAttributes
{
NSDictionary<NSAttributedStringKey, id> *effectiveTextAttributes = @{
NSFontAttributeName: _reactTextAttributes.effectiveFont ?: defaultPlaceholderFont(),
NSForegroundColorAttributeName: self.placeholderColor ?: defaultPlaceholderColor(),
NSKernAttributeName:isnan(_reactTextAttributes.letterSpacing) ? @0 : @(_reactTextAttributes.letterSpacing)
};
NSMutableDictionary<NSAttributedStringKey, id> *effectiveTextAttributes = [NSMutableDictionary dictionaryWithDictionary:@{
NSFontAttributeName: _reactTextAttributes.effectiveFont ?: defaultPlaceholderFont(),
NSForegroundColorAttributeName: self.placeholderColor ?: defaultPlaceholderColor(),
NSKernAttributeName:isnan(_reactTextAttributes.letterSpacing) ? @0 : @(_reactTextAttributes.letterSpacing)
}];
if (!isnan(_reactTextAttributes.lineHeight)) {
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
CGFloat lineHeight = _reactTextAttributes.lineHeight * _reactTextAttributes.effectiveFontSizeMultiplier;
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;
effectiveTextAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
}
return effectiveTextAttributes;
return [effectiveTextAttributes copy];
}
#pragma mark - Utility Methods