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 7d111f7ecd8..7e51725760b 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,6 +11,8 @@ import static com.facebook.react.uimanager.UIManagerHelper.getReactContext; import android.content.Context; import android.content.res.ColorStateList; +import android.graphics.BlendMode; +import android.graphics.BlendModeColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; @@ -433,8 +435,24 @@ public class ReactTextInputManager extends BaseViewManager= Build.VERSION_CODES.Q) { + Drawable cursorDrawable = view.getTextCursorDrawable(); + if (cursorDrawable != null) { + cursorDrawable.setColorFilter(new BlendModeColorFilter(color, BlendMode.SRC_IN)); + view.setTextCursorDrawable(cursorDrawable); + } + return; + } + + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) { + // Pre-Android 10, there was no supported API to change the cursor color programmatically. + // In Android 9.0, they changed the underlying implementation, + // but also "dark greylisted" the new field, rendering it unusable. + return; + } + + // The evil code that follows uses reflection to achieve this on Android 8.1 and below. // Based on // http://stackoverflow.com/questions/25996032/how-to-change-programatically-edittext-cursor-color-in-android. try {