Explicitly set default background color in RCTTextView

Summary:
RCTShadowText currently explicitly defaults to black text color:

https://github.com/facebook/react-native/blob/d46ac11/Libraries/Text/RCTShadowText.m#L204

However, the UITextView used by RCTTextInput doesn't explicitly default to black text color.

This causes issues when RCTTextInput is in rich text editing mode (i.e. when the <TextInput> element uses child <Text> nodes to provide extra styling info) and the client doesn't provide us with any explicit color info. In this case, the following series of badness occurs:

1. -[UITextView attributedText] will return an attributed string without the NSColor property set.
2. -[RCTShadowText attributedString] will return an attributed string with NSColor equal to blackColor.
3. The `[_textView.attributedText isEqualToAttributedString:_pendingAttributedText]` check in -performPendingTextUpdate will fail and causes -[UITextView setText:] to be called.
4. -setText: clears the marked text range in the text view, which breaks multi-character autocomplete (e.g. QWERTY input methods for CJK languages).

The easiest fix for now is to just make sure RCTUITextView and RCTShadowText default to the same text color.

Reviewed By: nicklockwood

Differential Revision: D3368726

fbshipit-source-id: a92cb188c60bac80d963af6b1f2a09f27ae084f5
This commit is contained in:
Ben Nham 2016-06-06 12:54:37 -07:00 committed by Facebook Github Bot 7
parent bc7ec03670
commit 1fce89176b
1 changed files with 1 additions and 0 deletions

View File

@ -86,6 +86,7 @@
_textView = [[RCTUITextView alloc] initWithFrame:CGRectZero];
_textView.backgroundColor = [UIColor clearColor];
_textView.textColor = [UIColor blackColor];
_textView.scrollsToTop = NO;
_textView.scrollEnabled = NO;
_textView.delegate = self;