Add support for selectionColor on Android TextInput

Summary:
public
This adds support to set the highlight color on TextInput on Android.  See https://github.com/facebook/react-native/pull/5678 for the iOS implementation.

Note : We will merge these two properties with one name 'selectionColor' in a follow on diff, and may move it to a style.

Reviewed By: nicklockwood

Differential Revision: D2895253

fb-gh-sync-id: 6f2c08c812ff0028973185356a8af285f7dd7969
This commit is contained in:
Dave Miller
2016-02-03 05:48:31 -08:00
committed by facebook-github-bot-3
parent 2e8eb652e1
commit 0c91931adf
7 changed files with 39 additions and 21 deletions

View File

@@ -30,17 +30,7 @@ public final class DefaultStyleValuesUtil {
* @return The ColorStateList for the hint text as defined in the style
*/
public static ColorStateList getDefaultTextColorHint(Context context) {
Resources.Theme theme = context.getTheme();
TypedArray textAppearances = null;
try {
textAppearances = theme.obtainStyledAttributes(new int[]{android.R.attr.textColorHint});
ColorStateList textColorHint = textAppearances.getColorStateList(0);
return textColorHint;
} finally {
if (textAppearances != null) {
textAppearances.recycle();
}
}
return getDefaultTextAttribute(context, android.R.attr.textColorHint);
}
/**
@@ -50,10 +40,24 @@ public final class DefaultStyleValuesUtil {
* @return The ColorStateList for the text as defined in the style
*/
public static ColorStateList getDefaultTextColor(Context context) {
return getDefaultTextAttribute(context, android.R.attr.textColor);
}
/**
* Utility method that returns the default text highlight color as define by the theme
*
* @param context The Context
* @return The int for the highlight color as defined in the style
*/
public static int getDefaultTextColorHighlight(Context context) {
return getDefaultTextAttribute(context, android.R.attr.textColorHighlight).getDefaultColor();
}
private static ColorStateList getDefaultTextAttribute(Context context, int attribute) {
Resources.Theme theme = context.getTheme();
TypedArray textAppearances = null;
try {
textAppearances = theme.obtainStyledAttributes(new int[]{android.R.attr.textColor});
textAppearances = theme.obtainStyledAttributes(new int[]{attribute});
ColorStateList textColor = textAppearances.getColorStateList(0);
return textColor;
} finally {

View File

@@ -196,6 +196,15 @@ public class ReactTextInputManager extends
}
}
@ReactProp(name = "selectionColor", customType = "Color")
public void setSelectionColor(ReactEditText view, @Nullable Integer color) {
if (color == null) {
view.setHighlightColor(DefaultStyleValuesUtil.getDefaultTextColorHighlight(view.getContext()));
} else {
view.setHighlightColor(color);
}
}
@ReactProp(name = "underlineColorAndroid", customType = "Color")
public void setUnderlineColor(ReactEditText view, @Nullable Integer underlineColor) {
if (underlineColor == null) {