Fix textAttributes not applied when typing text (#23585)
Summary: Currently, if we has `defaultValue`, textAttributes like `letterSpacing` can works, but if textinput has not default text, when we typing the text, some attributes not applied. [iOS] [Fixed] - Fix textAttributes not applied when typing text Pull Request resolved: https://github.com/facebook/react-native/pull/23585 Differential Revision: D14206568 Pulled By: cpojer fbshipit-source-id: 7db276d811684bf6e01f8d30287cca80095db87c
@@ -252,6 +252,9 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib
|
||||
|
||||
- (BOOL)isEqual:(RCTTextAttributes *)textAttributes
|
||||
{
|
||||
if (!textAttributes) {
|
||||
return NO;
|
||||
}
|
||||
if (self == textAttributes) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import <React/UIView+React.h>
|
||||
|
||||
#import "RCTBackedTextInputDelegateAdapter.h"
|
||||
#import "RCTTextAttributes.h"
|
||||
|
||||
@implementation RCTUITextView
|
||||
{
|
||||
@@ -19,6 +20,8 @@
|
||||
RCTBackedTextViewDelegateAdapter *_textInputDelegateAdapter;
|
||||
}
|
||||
|
||||
@synthesize reactTextAttributes = _reactTextAttributes;
|
||||
|
||||
static UIFont *defaultPlaceholderFont()
|
||||
{
|
||||
return [UIFont systemFontOfSize:17];
|
||||
@@ -88,6 +91,20 @@ static UIColor *defaultPlaceholderColor()
|
||||
_placeholderView.textColor = _placeholderColor ?: defaultPlaceholderColor();
|
||||
}
|
||||
|
||||
- (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes
|
||||
{
|
||||
if ([reactTextAttributes isEqual:_reactTextAttributes]) {
|
||||
return;
|
||||
}
|
||||
self.typingAttributes = reactTextAttributes.effectiveTextAttributes;
|
||||
_reactTextAttributes = reactTextAttributes;
|
||||
}
|
||||
|
||||
- (RCTTextAttributes *)reactTextAttributes
|
||||
{
|
||||
return _reactTextAttributes;
|
||||
}
|
||||
|
||||
- (void)textDidChange
|
||||
{
|
||||
_textWasPasted = NO;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@protocol RCTBackedTextInputDelegate;
|
||||
@class RCTTextAttributes;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -24,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, strong, nullable) UIView *inputAccessoryView;
|
||||
@property (nonatomic, weak, nullable) id<RCTBackedTextInputDelegate> textInputDelegate;
|
||||
@property (nonatomic, readonly) CGSize contentSize;
|
||||
@property (nonatomic, strong, nullable) RCTTextAttributes *reactTextAttributes;
|
||||
|
||||
// This protocol disallows direct access to `selectedTextRange` property because
|
||||
// unwise usage of it can break the `delegate` behavior. So, we always have to
|
||||
|
||||
@@ -68,13 +68,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
||||
- (void)enforceTextAttributesIfNeeded
|
||||
{
|
||||
id<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
|
||||
if (backedTextInputView.attributedText.string.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
backedTextInputView.font = _textAttributes.effectiveFont;
|
||||
backedTextInputView.textColor = _textAttributes.effectiveForegroundColor;
|
||||
backedTextInputView.textAlignment = _textAttributes.alignment;
|
||||
backedTextInputView.reactTextAttributes = _textAttributes;
|
||||
}
|
||||
|
||||
- (void)setReactPaddingInsets:(UIEdgeInsets)reactPaddingInsets
|
||||
|
||||
@@ -11,11 +11,14 @@
|
||||
#import <React/UIView+React.h>
|
||||
|
||||
#import "RCTBackedTextInputDelegateAdapter.h"
|
||||
#import "RCTTextAttributes.h"
|
||||
|
||||
@implementation RCTUITextField {
|
||||
RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter;
|
||||
}
|
||||
|
||||
@synthesize reactTextAttributes = _reactTextAttributes;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
@@ -60,6 +63,20 @@
|
||||
[self _updatePlaceholder];
|
||||
}
|
||||
|
||||
- (void)setReactTextAttributes:(RCTTextAttributes *)reactTextAttributes
|
||||
{
|
||||
if ([reactTextAttributes isEqual:_reactTextAttributes]) {
|
||||
return;
|
||||
}
|
||||
self.defaultTextAttributes = reactTextAttributes.effectiveTextAttributes;
|
||||
_reactTextAttributes = reactTextAttributes;
|
||||
}
|
||||
|
||||
- (RCTTextAttributes *)reactTextAttributes
|
||||
{
|
||||
return _reactTextAttributes;
|
||||
}
|
||||
|
||||
- (void)_updatePlaceholder
|
||||
{
|
||||
if (self.placeholder == nil) {
|
||||
|
||||
|
Before Width: | Height: | Size: 249 KiB After Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 179 KiB After Width: | Height: | Size: 178 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 145 KiB |
|
Before Width: | Height: | Size: 308 KiB After Width: | Height: | Size: 308 KiB |
|
Before Width: | Height: | Size: 235 KiB After Width: | Height: | Size: 234 KiB |