From 1e18d907bfb8cc5f4f2e1a1ede0dd98aec40ab11 Mon Sep 17 00:00:00 2001 From: Gabriel Peal Date: Tue, 21 Nov 2017 10:31:44 -0800 Subject: [PATCH] Prevent a crash when no cursor drawable is set Summary: React Native 0.43 added additional functionality to setSelectionColor that also tints the cursor drawable of the View. However, some views may not have a cursor drawable set in which case, the code will crash when attempting to load a drawable with resource id 0. We encountered this in our RN 0.45 upgrade in the Airbnb app. lelandrichardson Closes https://github.com/facebook/react-native/pull/14789 Differential Revision: D6386076 Pulled By: shergin fbshipit-source-id: faa5a1edb3be8d08988f46205c0f22d17b63b5bc --- .../react/views/textinput/ReactTextInputManager.java | 5 +++++ 1 file changed, 5 insertions(+) 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 70d9a461b3de5e..b4908385af81eb 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 @@ -332,6 +332,11 @@ private void setCursorColor(ReactEditText view, @Nullable Integer color) { cursorDrawableResField.setAccessible(true); int drawableResId = cursorDrawableResField.getInt(view); + // The view has no cursor drawable. + if (drawableResId == 0) { + return; + } + Drawable drawable = ContextCompat.getDrawable(view.getContext(), drawableResId); if (color != null) { drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);