Skip to content

Commit 52aee50

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
underlineColor transparent not working on API 21 (#30897)
Summary: This issue fixes facebook/react-native#29379 `underlineColorAndroid'='transparent'` does not work on Android API 21. Setting `style: { bottomBorderColor: 'transparent'}` fixes the issue. The following steps fix underlineColorAndroid on Android API 21: - Store the bottomBorderColor in a local variable - Then set the bottomBorderColor to the same color of underlineColorAndroid - Set underlineColorAndroid - Then Set the bottomBorderColor to the previous color previously stored in the local variable This change requires `ReactViewBackgroundDrawable` method `getBorderColor` to be public and accessible from `ReactTextInputManager` to retrieve the border color. https://github.com/facebook/react-native/blob/6061b7928320c64a94716ce3d6646667ebf3f6b5/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java#L1231-L1236 Related Discussions facebook/react-native#18938 facebook/react-native#18988 facebook/react-native#29412 (comment) More Information at #4 (comment) ## Changelog [Android] [Fixed] - Fix underlineColorAndroid transparent not working on API 21 Pull Request resolved: facebook/react-native#30897 Test Plan: This changes fix the Java API which can not be tested as explained in commit facebook/react-native@709a441 The java TextInputTest was excluded from the test suite in commit facebook/react-native@709a441 as they need the Yoga libraries to run **<details><summary>CLICK TO OPEN TESTS RESULTS - API 21</summary>** <p> Does not show underline by default (`transparent`) ```javascript <TextInput /> ``` <image src="https://user-images.githubusercontent.com/24992535/107060953-dee34d00-67d7-11eb-8f01-360dbb1420b8.png" width="150" /> ```javascript <TextInput underlineColorAndroid="red" /> ``` <image src="https://user-images.githubusercontent.com/24992535/107061134-194cea00-67d8-11eb-9da1-9780b1aa8294.png" width="150" /> ```javascript <TextInput underlineColorAndroid="green" style={ { borderBottomColor: 'red', borderBottomWidth: 2, borderTopColor: 'black', borderTopWidth: 4 } } /> ``` <image src="https://user-images.githubusercontent.com/24992535/107062411-9167df80-67d9-11eb-810c-749992d8d2d3.png" width="150" /> ```javascript <TextInput style={ { borderBottomColor: 'red', borderBottomWidth: 2, borderTopColor: 'black', borderTopWidth: 4 } } /> ``` <image src="https://user-images.githubusercontent.com/24992535/107062735-e6a3f100-67d9-11eb-93c3-02cd768f8421.png" width="150" /> ```javascript <TextInput underlineColorAndroid="blue" style={ { borderBottomColor: 'red', borderBottomWidth: 2, borderTopColor: 'black', borderTopWidth: 4, borderLeftColor: 'pink', borderLeftWidth: 7, borderRightColor: 'yellow', borderRightWidth: 7, } } /> ``` <image src="https://user-images.githubusercontent.com/24992535/107063263-75b10900-67da-11eb-97ab-316736d525a2.png" width="150" /> ```javascript <TextInput underlineColorAndroid="transparent" style={ { borderBottomColor: 'red', borderBottomWidth: 2, borderTopColor: 'black', borderTopWidth: 4, borderLeftColor: 'pink', borderLeftWidth: 7, borderRightColor: 'yellow', borderRightWidth: 7, } } /> ``` <image src="https://user-images.githubusercontent.com/24992535/107063332-8792ac00-67da-11eb-82fc-99793bf4d49d.png" width="150" /> </p> </details> Reviewed By: cortinico Differential Revision: D33906415 Pulled By: lunaleaps fbshipit-source-id: bd7efe4aac40ad701aec83f051ac40dcd4a99cda
1 parent 1804951 commit 52aee50

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,10 @@ public void setBorderColor(int position, float color, float alpha) {
914914
mReactBackgroundManager.setBorderColor(position, color, alpha);
915915
}
916916

917+
public int getBorderColor(int position) {
918+
return mReactBackgroundManager.getBorderColor(position);
919+
}
920+
917921
public void setBorderRadius(float borderRadius) {
918922
mReactBackgroundManager.setBorderRadius(borderRadius);
919923
}

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,16 @@ public void setUnderlineColor(ReactEditText view, @Nullable Integer underlineCol
637637
if (underlineColor == null) {
638638
drawableToMutate.clearColorFilter();
639639
} else {
640-
drawableToMutate.setColorFilter(underlineColor, PorterDuff.Mode.SRC_IN);
640+
// fixes underlineColor transparent not working on API 21
641+
// re-sets the TextInput underlineColor https://bit.ly/3M4alr6
642+
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
643+
int bottomBorderColor = view.getBorderColor(Spacing.BOTTOM);
644+
setBorderColor(view, Spacing.START, underlineColor);
645+
drawableToMutate.setColorFilter(underlineColor, PorterDuff.Mode.SRC_IN);
646+
setBorderColor(view, Spacing.START, bottomBorderColor);
647+
} else {
648+
drawableToMutate.setColorFilter(underlineColor, PorterDuff.Mode.SRC_IN);
649+
}
641650
}
642651
}
643652

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ private boolean isBorderColorDefined(int position) {
12591259
return !YogaConstants.isUndefined(rgb) && !YogaConstants.isUndefined(alpha);
12601260
}
12611261

1262-
private int getBorderColor(int position) {
1262+
public int getBorderColor(int position) {
12631263
float rgb = mBorderRGB != null ? mBorderRGB.get(position) : DEFAULT_BORDER_RGB;
12641264
float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : DEFAULT_BORDER_ALPHA;
12651265

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public void setBorderColor(int position, float color, float alpha) {
5858
getOrCreateReactViewBackground().setBorderColor(position, color, alpha);
5959
}
6060

61+
public int getBorderColor(int position) {
62+
return getOrCreateReactViewBackground().getBorderColor(position);
63+
}
64+
6165
public void setBorderRadius(float borderRadius) {
6266
getOrCreateReactViewBackground().setRadius(borderRadius);
6367
}

0 commit comments

Comments
 (0)