From ae57b25134c4db8be8539a0f0e6e52d46c850339 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 16 Feb 2017 04:29:53 -0800 Subject: [PATCH] Change cursor color when using selectionColor on Android Summary: This matches the behavior on iOS, there was no way before to change the cursor color per input, it was only possible to change it globally via the theme. Ideally cursor color and selection color would be 2 different props but I think this is better than what we have (and matches iOS). Sadly there is no api to change it pragmatically (only possible via xml) so this uses reflection and can easily break so it is wrapped in a try catch to avoid crashes. I think it is better to just silently fail in this case. Definetly not super happy about the solution but I think it's worth adding since it is possible to do it natively using xml so it would suck not to be able to do it in RN. **Test plan** Tested that the cursor has the same color as before the change when not setting the prop and that it gets the selectionColor color when set. Closes https://github.com/facebook/react-native/pull/12280 Differential Revision: D4571858 Pulled By: astreet fbshipit-source-id: 7dca2db33a0a4eecb6115b45155549b1265ffbed --- Libraries/Components/TextInput/TextInput.js | 2 +- .../com/facebook/react/views/textinput/BUCK | 2 +- .../textinput/ReactTextInputManager.java | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index ffc25757a9f..7bccf38b9a5 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -409,7 +409,7 @@ const TextInput = React.createClass({ */ secureTextEntry: PropTypes.bool, /** - * The highlight (and cursor on iOS) color of the text input. + * The highlight and cursor color of the text input. */ selectionColor: ColorPropType, /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK index b14cc057f73..27e87e7fd0b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK @@ -5,6 +5,7 @@ android_library( srcs = glob(['*.java']), deps = [ YOGA_TARGET, + react_native_dep('third-party/android/support/v4:lib-support-v4'), react_native_dep('third-party/java/infer-annotations:infer-annotations'), react_native_dep('third-party/java/jsr-305:jsr-305'), react_native_target('java/com/facebook/react/bridge:bridge'), @@ -22,4 +23,3 @@ android_library( 'PUBLIC', ], ) - diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index b0ed4cf8352..e91f681af94 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -11,11 +11,14 @@ package com.facebook.react.views.textinput; import javax.annotation.Nullable; +import java.lang.reflect.Field; import java.util.LinkedList; import java.util.Map; +import android.graphics.drawable.Drawable; import android.graphics.PorterDuff; import android.graphics.Typeface; +import android.support.v4.content.ContextCompat; import android.text.Editable; import android.text.InputFilter; import android.text.InputType; @@ -310,6 +313,37 @@ public class ReactTextInputManager extends BaseViewManager