Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TextInput npe in #29452 on react native side #37302

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ android {
preBuild.dependsOn(preparePrefab)

sourceSets.main {
res.srcDirs = ["src/main/res/devsupport", "src/main/res/shell", "src/main/res/views/modal", "src/main/res/views/uimanager"]
res.srcDirs = ["src/main/res/devsupport", "src/main/res/shell", "src/main/res/views/modal", "src/main/res/views/uimanager", "src/main/res/views/textinput"]
jcdhlzq marked this conversation as resolved.
Show resolved Hide resolved
java {
srcDirs = ["src/main/java", "src/main/libraries/soloader/java", "src/main/jni/first-party/fb/jni/java"]
exclude("com/facebook/react/processing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.view.ViewCompat;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.R;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -263,6 +265,12 @@ public void setPadding(int spacingType, float padding) {
* {@code EditText} this class uses to determine the expected size of the view.
*/
protected EditText createInternalEditText() {
return new EditText(getThemedContext());
// By setting a style which has a background drawable, this EditText will have a different
// background drawable instance from that on the UI Thread, which maybe has a default background
// drawable instance.
// Otherwise, DrawableContainer is not a thread safe class, and it caused the npe in #29452.
ContextThemeWrapper context = new ContextThemeWrapper(getThemedContext(),
R.style.Theme_ReactNative_TextInput_DefaultBackground);
return new EditText(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.ReactNative.TextInput.DefaultBackground" parent="android:Widget.EditText">

<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
jcdhlzq marked this conversation as resolved.
Show resolved Hide resolved

</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
</style>

</resources>