mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Keep placeholder paragraph style same with text input (#23763)
Summary: Keep placeholder paragraph style same with text input. [iOS] [Fixed] - Keep placeholder paragraph style same with text input Pull Request resolved: https://github.com/facebook/react-native/pull/23763 Differential Revision: D14320996 Pulled By: cpojer fbshipit-source-id: 07c20722809395a74a48300fbb7cadebb8707b03
This commit is contained in:
committed by
Facebook Github Bot
parent
8491cc36dd
commit
debd4462e0
@@ -66,6 +66,11 @@ extern NSString *const RCTTextAttributesTagAttributeName;
|
||||
*/
|
||||
- (NSDictionary<NSAttributedStringKey, id> *)effectiveTextAttributes;
|
||||
|
||||
/**
|
||||
* Constructed paragraph style.
|
||||
*/
|
||||
- (NSParagraphStyle *_Nullable)effectiveParagraphStyle;
|
||||
|
||||
/**
|
||||
* Constructed font.
|
||||
*/
|
||||
|
||||
@@ -79,6 +79,44 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib
|
||||
_textTransform = textAttributes->_textTransform != RCTTextTransformUndefined ? textAttributes->_textTransform : _textTransform;
|
||||
}
|
||||
|
||||
- (NSParagraphStyle *)effectiveParagraphStyle
|
||||
{
|
||||
// Paragraph Style
|
||||
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
|
||||
BOOL isParagraphStyleUsed = NO;
|
||||
if (_alignment != NSTextAlignmentNatural) {
|
||||
NSTextAlignment alignment = _alignment;
|
||||
if (_layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
|
||||
if (alignment == NSTextAlignmentRight) {
|
||||
alignment = NSTextAlignmentLeft;
|
||||
} else if (alignment == NSTextAlignmentLeft) {
|
||||
alignment = NSTextAlignmentRight;
|
||||
}
|
||||
}
|
||||
|
||||
paragraphStyle.alignment = alignment;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (_baseWritingDirection != NSWritingDirectionNatural) {
|
||||
paragraphStyle.baseWritingDirection = _baseWritingDirection;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (!isnan(_lineHeight)) {
|
||||
CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
|
||||
paragraphStyle.minimumLineHeight = lineHeight;
|
||||
paragraphStyle.maximumLineHeight = lineHeight;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (isParagraphStyleUsed) {
|
||||
return [paragraphStyle copy];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSAttributedStringKey, id> *)effectiveTextAttributes
|
||||
{
|
||||
NSMutableDictionary<NSAttributedStringKey, id> *attributes =
|
||||
@@ -107,35 +145,8 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib
|
||||
}
|
||||
|
||||
// Paragraph Style
|
||||
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
|
||||
BOOL isParagraphStyleUsed = NO;
|
||||
if (_alignment != NSTextAlignmentNatural) {
|
||||
NSTextAlignment alignment = _alignment;
|
||||
if (_layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
|
||||
if (alignment == NSTextAlignmentRight) {
|
||||
alignment = NSTextAlignmentLeft;
|
||||
} else if (alignment == NSTextAlignmentLeft) {
|
||||
alignment = NSTextAlignmentRight;
|
||||
}
|
||||
}
|
||||
|
||||
paragraphStyle.alignment = alignment;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (_baseWritingDirection != NSWritingDirectionNatural) {
|
||||
paragraphStyle.baseWritingDirection = _baseWritingDirection;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (!isnan(_lineHeight)) {
|
||||
CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
|
||||
paragraphStyle.minimumLineHeight = lineHeight;
|
||||
paragraphStyle.maximumLineHeight = lineHeight;
|
||||
isParagraphStyleUsed = YES;
|
||||
}
|
||||
|
||||
if (isParagraphStyleUsed) {
|
||||
NSParagraphStyle *paragraphStyle = [self effectiveParagraphStyle];
|
||||
if (paragraphStyle) {
|
||||
attributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
||||
}
|
||||
|
||||
|
||||
@@ -257,11 +257,8 @@ static UIColor *defaultPlaceholderColor()
|
||||
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;
|
||||
NSParagraphStyle *paragraphStyle = [_reactTextAttributes effectiveParagraphStyle];
|
||||
if (paragraphStyle) {
|
||||
effectiveTextAttributes[NSParagraphStyleAttributeName] = paragraphStyle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user