From 2290db15984861aee6c85ac4aa9922ab024493b3 Mon Sep 17 00:00:00 2001 From: Brayden Williams <1311325+redstar504@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:40:18 -0800 Subject: [PATCH 1/4] Match other platforms behavior for overflowed TextInput on Android --- .../views/textinput/ReactTextInputManager.java | 6 +++++- .../examples/TextInput/TextInputSharedExamples.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 e67955e27fd6f8..847c8e4550dc1f 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 @@ -1069,7 +1069,11 @@ public WritableMap getStateUpdate() { } @Override - public void afterTextChanged(Editable s) {} + public void afterTextChanged(Editable s) { + if (!mEditText.hasFocus()) { + mEditText.post(() -> mEditText.scrollTo(0,0)); + } + } } @Override diff --git a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js index 353379409ffe6a..488fefba4551a6 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js @@ -1106,6 +1106,20 @@ module.exports = ([ ); }, }, + { + title: 'Overflowed text behavior on render', + name: 'overflowedOnRender', + render: function(): React.Node { + return ( + + + + ); + } + }, { title: 'Uncontrolled component with layout changes', name: 'uncontrolledComponent', From 0f4493685c87e1c98c9dfdc3513b46a726e77c9c Mon Sep 17 00:00:00 2001 From: Brayden Williams <1311325+redstar504@users.noreply.github.com> Date: Thu, 9 Mar 2023 15:51:49 -0800 Subject: [PATCH 2/4] Fix dangling comma, use defaultValue for editable example field --- .../examples/TextInput/TextInputSharedExamples.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js index 488fefba4551a6..4ee80daacd814a 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js @@ -1108,17 +1108,14 @@ module.exports = ([ }, { title: 'Overflowed text behavior on render', - name: 'overflowedOnRender', - render: function(): React.Node { + render: function (): React.Node { return ( - - - + ); - } + }, }, { title: 'Uncontrolled component with layout changes', From 38d0cd88cb04a72784bf83304671d9bbca378cf8 Mon Sep 17 00:00:00 2001 From: Brayden Williams <1311325+redstar504@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:02:27 -0800 Subject: [PATCH 3/4] Replace lambda with anonymous inner class --- .../react/views/textinput/ReactTextInputManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 847c8e4550dc1f..4aa84ea04a4698 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 @@ -1070,9 +1070,12 @@ public WritableMap getStateUpdate() { @Override public void afterTextChanged(Editable s) { - if (!mEditText.hasFocus()) { - mEditText.post(() -> mEditText.scrollTo(0,0)); - } + mEditText.post(new Runnable() { + @Override + public void run() { + mEditText.scrollTo(0, 0); + } + }); } } From 9501f14448d69c5630b0c8852177c9e00601dd31 Mon Sep 17 00:00:00 2001 From: Brayden Williams <1311325+redstar504@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:10:56 -0800 Subject: [PATCH 4/4] Re-add focus condition --- .../views/textinput/ReactTextInputManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 4aa84ea04a4698..99a666d0623362 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 @@ -1070,12 +1070,14 @@ public WritableMap getStateUpdate() { @Override public void afterTextChanged(Editable s) { - mEditText.post(new Runnable() { - @Override - public void run() { - mEditText.scrollTo(0, 0); - } - }); + if (!mEditText.hasFocus()) { + mEditText.post(new Runnable() { + @Override + public void run() { + mEditText.scrollTo(0, 0); + } + }); + } } }