From 25ce6226832561da2a5f6385cdd5e2e30e2da383 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Thu, 5 Dec 2019 13:16:09 -0800 Subject: [PATCH] Fix TextInput example with `text` attribute and child Text node: `text` background shouldn't be same as TextInput background Summary: Currently the TextInput background is same as the background of the `text` value's attributes, because of the way we're parsing props and using the TextInput's props both for the background of the TextInput, and for the AttributedString/background color of the `text` prop node's attributes. If the background color has opacity, the `text` prop node will not have the correct background because it will be applied twice. Fix it. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D18760384 fbshipit-source-id: 0cdcc8dd8839dd47e8fe0f593b4696bc16a62333 --- .../textinput/androidtextinput/AndroidTextInputShadowNode.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp index 35f9e47f07c..1446c2d3909 100644 --- a/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp +++ b/ReactCommon/fabric/components/textinput/androidtextinput/AndroidTextInputShadowNode.cpp @@ -45,6 +45,10 @@ AttributedString AndroidTextInputShadowNode::getAttributedString( auto fragment = AttributedString::Fragment{}; fragment.string = getProps()->text; fragment.textAttributes = textAttributes; + // If the TextInput opacity is 0 < n < 1, the opacity of the TextInput and + // text value's background will stack. This is a hack/workaround to prevent + // that effect. + fragment.textAttributes.backgroundColor = clearColor(); fragment.parentShadowView = ShadowView(*this); attributedString.prependFragment(fragment);