diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java deleted file mode 100644 index fd8f278e3e21..000000000000 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.expensify.chat; - -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -import android.content.Context; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -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) { - reactContext.runOnUiQueueThread(new Runnable() { - @Override - public void run() { - InputMethodManager imm = (InputMethodManager) getReactApplicationContext().getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - View viewToReset = reactContext.getFabricUIManager().resolveView(reactTagToReset); - imm.restartInput(viewToReset); - } - } - }); - } -} diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt new file mode 100644 index 000000000000..f34d39c60eca --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt @@ -0,0 +1,30 @@ +package com.expensify.chat; + +import android.content.Context; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.uimanager.util.ReactFindViewUtil; + +class RNTextInputResetModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule( + reactContext +) { + override fun getName(): String = "RNTextInputReset" + + // Props to https://github.com/MattFoley for this temporary hack + // https://github.com/facebook/react-native/pull/12462#issuecomment-298812731 + @ReactMethod + fun resetKeyboardInput(nativeId: String) { + reactContext.runOnUiQueueThread { + val imm = reactApplicationContext.baseContext.getSystemService( + Context.INPUT_METHOD_SERVICE + ) as? InputMethodManager + + val reactNativeView = currentActivity?.findViewById(android.R.id.content) + val viewToReset = reactNativeView?.let { ReactFindViewUtil.findView(it, nativeId) } + imm?.restartInput(viewToReset) + } + } +} diff --git a/cspell.json b/cspell.json index f23df674bbe5..3e76450f7fb2 100644 --- a/cspell.json +++ b/cspell.json @@ -730,7 +730,8 @@ "pnrs", "POLICYCHANGELOG_ADD_EMPLOYEE", "xcshareddata", - "xcuserdata" + "xcuserdata", + "inputmethod" ], "ignorePaths": [ "src/languages/de.ts", diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 081e610b7907..ea17a85766d9 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -305,8 +305,8 @@ function ComposerWithSuggestions( if (!RNTextInputReset) { return; } - RNTextInputReset.resetKeyboardInput(findNodeHandle(textInputRef.current)); - }, [textInputRef]); + RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID); + }, []); const debouncedSaveReportComment = useMemo( () => diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index 9b27b712f034..ea7b4f709730 100644 --- a/src/types/modules/react-native.d.ts +++ b/src/types/modules/react-native.d.ts @@ -15,7 +15,7 @@ type AppStateTrackerModule = { }; type RNTextInputResetModule = { - resetKeyboardInput: (nodeHandle: number | null) => void; + resetKeyboardInput: (nativeId: string) => void; }; type RNNavBarManagerModule = {