diff --git a/Libraries/Text/RCTTextAttributes.m b/Libraries/Text/RCTTextAttributes.m index f1bf6beab67..7da187fc341 100644 --- a/Libraries/Text/RCTTextAttributes.m +++ b/Libraries/Text/RCTTextAttributes.m @@ -252,6 +252,9 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib - (BOOL)isEqual:(RCTTextAttributes *)textAttributes { + if (!textAttributes) { + return NO; + } if (self == textAttributes) { return YES; } diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index c50638fc54a..39412eff904 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -11,6 +11,7 @@ #import #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; diff --git a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h index 9992986a46b..f2fb4f3c5e1 100644 --- a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +++ b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h @@ -8,6 +8,7 @@ #import @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 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 diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 2ad41b2c974..0a8ea15b7c0 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -68,13 +68,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) - (void)enforceTextAttributesIfNeeded { id 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 diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 03a9198e184..e092caa5d3a 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -11,11 +11,14 @@ #import #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) { diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS12@2x.png index 06297ec33c5..1232aed8ba7 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS12@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSliderExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSliderExample_1-iOS12@2x.png index 3476ceda8b6..6f22306ea6f 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSliderExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSliderExample_1-iOS12@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSwitchExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSwitchExample_1-iOS12@2x.png index aa1292f087c..d844d114823 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSwitchExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testSwitchExample_1-iOS12@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png index 9854157e297..4ad304715ba 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testTextExample_1-iOS12@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS12@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS12@2x.png index a79c579819b..c0f4ac370ed 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS12@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testViewExample_1-iOS12@2x.png differ