10
2

More than 5 years have passed since last update.

AndroidのTextInputでunderlineColorAndroidを指定するとクラッシュする問題【React Native】

Last updated at Posted at 2018-10-15

React NativeのTextInputには、Androidで下線部の色を指定するunderlineColorAndroidというpropsがありますが、これを指定すると以下のようなエラーを吐いてアプリがクラッシュする場合があります(エラーが起きない時もあります。)

Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)' on a null object reference

FlatList, ScrollViewと同時に使用した際に発生するようです。

エラーが起きている箇所は ReactTextInputManager.javaで、underlineColorAndroidのpropsを渡すと、ReactTextInputManager.setUnderlineColorが呼ばれ、Drawable.mutate()のバグでクラッシュします。

根本的な解決策はなく、underlineColorAndroidの使用を避けるほか無いようです。

TextInputの下線を消す際に利用すると思うのですが、下線を消したい場合はunderlineColorAndroidの代わりに、android/app/src/main/res/values/styles.xmlを以下のように書き換えることで変更可能です。

styles.xml
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowExitAnimation">@android:anim/fade_out</item>
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:editTextBackground">@android:color/transparent</item>
    </style>
</resources>

10
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
2