From 5498816b25ae661eafedc7ce5b7077997f0800f4 Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Fri, 12 May 2023 19:19:47 +0530 Subject: [PATCH 1/6] Remove additional letters --- .../com/expensify/chat/MainApplication.java | 1 + .../chat/RNTextInputResetModule.java | 46 +++++++++++++++++++ .../chat/RNTextInputResetPackage.java | 28 +++++++++++ src/pages/home/report/ReportActionCompose.js | 6 ++- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java create mode 100644 android/app/src/main/java/com/expensify/chat/RNTextInputResetPackage.java diff --git a/android/app/src/main/java/com/expensify/chat/MainApplication.java b/android/app/src/main/java/com/expensify/chat/MainApplication.java index b24e8eb49eb1..a4f2bc97416d 100644 --- a/android/app/src/main/java/com/expensify/chat/MainApplication.java +++ b/android/app/src/main/java/com/expensify/chat/MainApplication.java @@ -37,6 +37,7 @@ protected List getPackages() { // packages.add(new MyReactNativePackage()); packages.add(new BootSplashPackage()); packages.add(new ExpensifyAppPackage()); + packages.add(new RNTextInputResetPackage()); return packages; } diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java new file mode 100644 index 000000000000..57c67f1bc5f0 --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java @@ -0,0 +1,46 @@ +package com.expensify.chat; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.Callback; +import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.UIBlock; +import com.facebook.react.uimanager.NativeViewHierarchyManager; +import android.content.Context; +import android.view.View; +import android.widget.TextView; +import android.view.inputmethod.InputMethodManager; +import android.util.Log; + +public class RNTextInputResetModule extends ReactContextBaseJavaModule { + + private final ReactApplicationContext reactContext; + + public RNTextInputResetModule(ReactApplicationContext reactContext) { + super(reactContext); + this.reactContext = reactContext; + } + + @Override + public String getName() { + return "RNTextInputReset"; + } + + // Props to https://github.com/MattFoley for this temporary hack + // https://github.com/facebook/react-native/pull/12462#issuecomment-298812731 + @ReactMethod + public void resetKeyboardInput(final int reactTagToReset) { + UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class); + uiManager.addUIBlock(new UIBlock() { + @Override + public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { + InputMethodManager imm = (InputMethodManager) getReactApplicationContext().getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + View viewToReset = nativeViewHierarchyManager.resolveView(reactTagToReset); + imm.restartInput(viewToReset); + } + } + }); + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetPackage.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetPackage.java new file mode 100644 index 000000000000..8e5d9994fd4b --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetPackage.java @@ -0,0 +1,28 @@ +package com.expensify.chat; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.bridge.JavaScriptModule; + +public class RNTextInputResetPackage implements ReactPackage { + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Arrays.asList(new RNTextInputResetModule(reactContext)); + } + + // Deprecated from RN 0.47 + public List> createJSModules() { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +} diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 1309d518b539..1820b7be4820 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import {View, TouchableOpacity, InteractionManager, LayoutAnimation} from 'react-native'; +import {View, TouchableOpacity, InteractionManager, LayoutAnimation, NativeModules, findNodeHandle} from 'react-native'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; @@ -139,6 +139,7 @@ const defaultProps = { ...withCurrentUserPersonalDetailsDefaultProps, }; +const { RNTextInputReset } = NativeModules; /** * Return the max available index for arrow manager. * @param {Number} numRows @@ -591,6 +592,9 @@ class ReportActionCompose extends React.Component { const commentAfterColonWithEmojiNameRemoved = this.state.value.slice(this.state.selection.end).replace(CONST.REGEX.EMOJI_REPLACER, CONST.SPACE); this.updateComment(`${commentBeforeColon}${emojiCode} ${commentAfterColonWithEmojiNameRemoved}`, true); + if (RNTextInputReset) { + RNTextInputReset.resetKeyboardInput(findNodeHandle(this.textInput)); + } this.setState((prevState) => ({ selection: { start: prevState.colonIndex + emojiCode.length + CONST.SPACE_LENGTH, From e8cfc3a88127a3c77e4f9c9bd6e6d7f06d9d5731 Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Sun, 14 May 2023 17:37:02 +0530 Subject: [PATCH 2/6] Remove additional letters --- src/pages/home/report/ReportActionCompose.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 1820b7be4820..b8e0a157a505 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -139,7 +139,7 @@ const defaultProps = { ...withCurrentUserPersonalDetailsDefaultProps, }; -const { RNTextInputReset } = NativeModules; +const {RNTextInputReset} = NativeModules; /** * Return the max available index for arrow manager. * @param {Number} numRows @@ -592,6 +592,7 @@ class ReportActionCompose extends React.Component { const commentAfterColonWithEmojiNameRemoved = this.state.value.slice(this.state.selection.end).replace(CONST.REGEX.EMOJI_REPLACER, CONST.SPACE); this.updateComment(`${commentBeforeColon}${emojiCode} ${commentAfterColonWithEmojiNameRemoved}`, true); + // Clear the contents of a TextInput in some android keyboards if (RNTextInputReset) { RNTextInputReset.resetKeyboardInput(findNodeHandle(this.textInput)); } From 19f06b24c909d342b55a41909a6d645281a21352 Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Mon, 15 May 2023 09:32:46 +0530 Subject: [PATCH 3/6] Remove additional letters --- src/pages/home/report/ReportActionCompose.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index b8e0a157a505..04aa5fab1237 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -592,7 +592,9 @@ class ReportActionCompose extends React.Component { const commentAfterColonWithEmojiNameRemoved = this.state.value.slice(this.state.selection.end).replace(CONST.REGEX.EMOJI_REPLACER, CONST.SPACE); this.updateComment(`${commentBeforeColon}${emojiCode} ${commentAfterColonWithEmojiNameRemoved}`, true); - // Clear the contents of a TextInput in some android keyboards + // In some Android phones keyboard, the text to search for the emoji is not cleared + // will be added after the user starts typing again on the keyboard. This package is + // a workaround to reset the keyboard natively. if (RNTextInputReset) { RNTextInputReset.resetKeyboardInput(findNodeHandle(this.textInput)); } From 927c1a80a7924d6c5cd7a4b2f7fc0e518041ff1a Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Tue, 16 May 2023 09:25:56 +0530 Subject: [PATCH 4/6] Remove additional letters --- .../main/java/com/expensify/chat/RNTextInputResetModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java index 57c67f1bc5f0..37ec8f5c58f2 100644 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java @@ -43,4 +43,4 @@ public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { } }); } -} \ No newline at end of file +} From 87db39a7ea6f7ff9ed50c6cb39631f510120cf23 Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Tue, 16 May 2023 11:51:37 +0530 Subject: [PATCH 5/6] Remove additional letters --- .../main/java/com/expensify/chat/RNTextInputResetModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java index 37ec8f5c58f2..57c67f1bc5f0 100644 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java @@ -43,4 +43,4 @@ public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { } }); } -} +} \ No newline at end of file From f15a4b1ae583804dca1b3132702f61d705af0215 Mon Sep 17 00:00:00 2001 From: Kaushik Kapadiya Date: Tue, 16 May 2023 12:14:08 +0530 Subject: [PATCH 6/6] Remove additional letters --- .../main/java/com/expensify/chat/RNTextInputResetModule.java | 2 +- src/pages/home/report/ReportActionCompose.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java index 57c67f1bc5f0..37ec8f5c58f2 100644 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java @@ -43,4 +43,4 @@ public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) { } }); } -} \ No newline at end of file +} diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 04aa5fab1237..e77507b8bdfa 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -593,7 +593,7 @@ class ReportActionCompose extends React.Component { this.updateComment(`${commentBeforeColon}${emojiCode} ${commentAfterColonWithEmojiNameRemoved}`, true); // In some Android phones keyboard, the text to search for the emoji is not cleared - // will be added after the user starts typing again on the keyboard. This package is + // will be added after the user starts typing again on the keyboard. This package is // a workaround to reset the keyboard natively. if (RNTextInputReset) { RNTextInputReset.resetKeyboardInput(findNodeHandle(this.textInput));