Skip to content
Browse files

Explicitly set default background color in RCTTextView

RCTShadowText currently explicitly defaults to black text color:

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
  • Loading branch information...
bnham authored and Facebook Github Bot 7 committed Jun 6, 2016
1 parent bc7ec03 commit 1fce89176b2b87ea1914f94cf036b06a3176c4c1
Showing with 1 addition and 0 deletions.
  1. +1 −0 Libraries/Text/RCTTextView.m
@@ -86,6 +86,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher

_textView = [[RCTUITextView alloc] initWithFrame:CGRectZero];
_textView.backgroundColor = [UIColor clearColor];
_textView.textColor = [UIColor blackColor];
_textView.scrollsToTop = NO;
_textView.scrollEnabled = NO;
_textView.delegate = self;

0 comments on commit 1fce891

Please sign in to comment.
You can’t perform that action at this time.