Skip to content

Commit

Permalink
Fix TextInput never unset MovementMethod
Browse files Browse the repository at this point in the history
Summary:
Since we never unset `MovementMethod` when we unmount `EditText`:

https://www.internalfb.com/code/fbsource/[c3c455bf992e271a11603f404e7de719868be3da]/fbandroid/libraries/components/litho-widget/src/main/java/com/facebook/litho/widget/TextInputSpec.java?lines=942-949

We could potentially face a situation where the `TextView.layout` has been released when we're dealing with logic inside the callback `MovementMethod`, for example:

https://www.internalfb.com/code/fbsource/[c0dfc5d86d8051e0861c1abc35cb0e9647c6fd00]/fbandroid/java/com/facebook/widget/text/BetterLinkMovementMethod.kt?lines=30-68

It might lead to a crash like this: https://fburl.com/logview/9cgol7zq

Reviewed By: jettbow

Differential Revision: D67088678

fbshipit-source-id: 633af90a840ba08ac4b79acce8368ce0a3ebac8b
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Dec 12, 2024
1 parent c3628fb commit 54f930e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ internal constructor(
*/
@JvmField var enableA11Y: Boolean = false

/** This flag is used clear MovementMethod on TextInput to avoid a potential crash. */
@JvmField var clearMovementMethod: Boolean = true

/**
* This method is only used so that Java clients can have a builder like approach to override a
* configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ static void onUnmount(
editText.setKeyListener(null); // Clear any KeyListener
editText.setInputType(inputType); // Set the input type back to default.
}
if (ComponentsConfiguration.clearMovementMethod) {
editText.setMovementMethod(null);
}
editText.setTextState(null);
editText.removeOnWindowFocusChangeListener();
editText.setPrivateImeOptions(null);
Expand Down

0 comments on commit 54f930e

Please sign in to comment.