diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 5734672d13fa33..0ac217c10166dc 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -82,7 +82,7 @@ - (NSString *)accessibilityLabel - (void)setPlaceholder:(NSString *)placeholder { _placeholder = placeholder; - _placeholderView.text = _placeholder; + _placeholderView.attributedText = [[NSAttributedString alloc] initWithString:_placeholder ?: @"" attributes:[self placeholderEffectiveTextAttributes]]; } - (void)setPlaceholderColor:(UIColor *)placeholderColor @@ -98,7 +98,8 @@ - (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes } self.typingAttributes = reactTextAttributes.effectiveTextAttributes; _reactTextAttributes = reactTextAttributes; - _placeholderView.font = self.font ?: defaultPlaceholderFont(); + // Update placeholder text attributes + [self setPlaceholder:_placeholder]; } - (RCTTextAttributes *)reactTextAttributes @@ -249,6 +250,17 @@ - (void)invalidatePlaceholderVisibility _placeholderView.hidden = !isVisible; } +- (NSDictionary *)placeholderEffectiveTextAttributes +{ + NSDictionary *effectiveTextAttributes = @{ + NSFontAttributeName: _reactTextAttributes.effectiveFont ?: defaultPlaceholderFont(), + NSForegroundColorAttributeName: self.placeholderColor ?: defaultPlaceholderColor(), + NSKernAttributeName:isnan(_reactTextAttributes.letterSpacing) ? @0 : @(_reactTextAttributes.letterSpacing) + }; + + return effectiveTextAttributes; +} + #pragma mark - Utility Methods - (void)copyTextAttributesFrom:(NSAttributedString *)sourceString diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index e092caa5d3a957..b4df1a9d7a9494 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -70,6 +70,7 @@ - (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes } self.defaultTextAttributes = reactTextAttributes.effectiveTextAttributes; _reactTextAttributes = reactTextAttributes; + [self _updatePlaceholder]; } - (RCTTextAttributes *)reactTextAttributes @@ -87,6 +88,10 @@ - (void)_updatePlaceholder 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];