Skip to content

Commit

Permalink
Fix Drawable Runtime - More Info in Description
Browse files Browse the repository at this point in the history
The AppCompat Theme Theme.AppCompat.Light.NoActionBar provides a default
Drawable resource for AppCompatEditText. The resource is located in
@drawable/abc_edit_text_material.xml

https://chromium.googlesource.com/android_tools/+/7200281446186c7192cb02f54dc2b38e02d705e5/sdk/extras/android/support/v7/appcompat/res/drawable/abc_edit_text_material.xml

A Runtime Error is triggered in a scenario with the following conditions:

1) Rendering a large number of TextInputs in the screen with a key prop
2) Triggering re-render with setInterval

The scenario is also experienced with FlatList and ONLY using TextInput
component.

The following Runtime Error is triggered:

NullPointerException:tempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)

It is caused from the following line from abc_edit_text_material.xml

<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>

I posted a Minimal Reproducible Example at #17530 (comment)

This commit simply changes RNTester to use a custom drawable resource
for TextInput named @drawable/edit_text.
  • Loading branch information
fabOnReact committed Jul 21, 2020
1 parent 980900c commit 0858d41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RNTester/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:banner="@drawable/tv_banner"
android:icon="@drawable/launcher_icon"
android:label="@string/app_name"
android:theme="@style/Theme.ReactNative.AppCompat.Light" >
android:theme="@style/AppTheme">
<activity
android:name=".RNTesterActivity"
android:label="@string/app_name"
Expand Down
28 changes: 28 additions & 0 deletions RNTester/android/app/src/main/res/drawable/edit_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material"
android:insetRight="@dimen/abc_edit_text_inset_horizontal_material"
android:insetTop="@dimen/abc_edit_text_inset_top_material"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material">

<selector>
<item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/>
</selector>

</inset>

4 changes: 2 additions & 2 deletions RNTester/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<item name="android:editTextBackground">@drawable/edit_text</item>
</style>

</resources>

0 comments on commit 0858d41

Please sign in to comment.