From f6d13e36bf12030bf21dca2e8b884fa7160d4fe7 Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 23 Jul 2025 14:45:00 +0200 Subject: [PATCH 1/5] use nativeId to find view --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 4 ++-- src/types/modules/react-native.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 1601c0627a2a..5934ae4c60f6 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: (nodeHandle: string) => void; }; type RNNavBarManagerModule = { From 3903dfe7f9744af4fa12d52f0bc2e2e14706debd Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 23 Jul 2025 14:50:43 +0200 Subject: [PATCH 2/5] adjust standalone native module --- .../chat/RNTextInputResetModule.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 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 fd8f278e3e21..27a7fb2664cd 100644 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java @@ -3,6 +3,8 @@ 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; + import android.content.Context; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -24,15 +26,15 @@ public String getName() { // 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); - } + public void resetKeyboardInput(final String nativeId) { + reactContext.runOnUiQueueThread(() -> { + InputMethodManager imm = (InputMethodManager) getReactApplicationContext().getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); + + View reactNativeView = getCurrentActivity().findViewById(android.R.id.content); + View viewToReset = ReactFindViewUtil.findView(reactNativeView, nativeId); + + if (imm != null && viewToReset != null) { + imm.restartInput(viewToReset); } }); } From e82548b95470e751453d407123f131a7806afead Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 23 Jul 2025 15:37:07 +0200 Subject: [PATCH 3/5] migrate module to kotlin --- .../chat/RNTextInputResetModule.java | 41 ------------------- .../expensify/chat/RNTextInputResetModule.kt | 29 +++++++++++++ src/types/modules/react-native.d.ts | 2 +- 3 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java create mode 100644 android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt 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 27a7fb2664cd..000000000000 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java +++ /dev/null @@ -1,41 +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 com.facebook.react.uimanager.util.ReactFindViewUtil; - -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 String nativeId) { - reactContext.runOnUiQueueThread(() -> { - InputMethodManager imm = (InputMethodManager) getReactApplicationContext().getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); - - View reactNativeView = getCurrentActivity().findViewById(android.R.id.content); - View viewToReset = ReactFindViewUtil.findView(reactNativeView, nativeId); - - if (imm != null && viewToReset != null) { - 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..cc7baa785406 --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt @@ -0,0 +1,29 @@ +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.uimanager.util.ReactFindViewUtil; + +import android.content.Context; +import android.os.Build +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import androidx.annotation.RequiresApi + +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/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts index 5934ae4c60f6..bd0e9fa0e42f 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: string) => void; + resetKeyboardInput: (nativeId: string) => void; }; type RNNavBarManagerModule = { From 67e3e6db5b6fdf1b57cd5db34c8d4a0b93112f3d Mon Sep 17 00:00:00 2001 From: war-in Date: Wed, 23 Jul 2025 17:24:49 +0200 Subject: [PATCH 4/5] fix spellcheck --- cspell.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index 94144d242d8a..62133eae6f69 100644 --- a/cspell.json +++ b/cspell.json @@ -696,7 +696,8 @@ "pnrs", "POLICYCHANGELOG_ADD_EMPLOYEE", "xcshareddata", - "xcuserdata" + "xcuserdata", + "inputmethod" ], "ignorePaths": [ "src/languages/de.ts", From 9dc9b2207bcbfbc00c0df296d3856ecc434b005a Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 28 Jul 2025 11:11:28 +0200 Subject: [PATCH 5/5] fix kotlin lint --- .../expensify/chat/RNTextInputResetModule.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt index cc7baa785406..f34d39c60eca 100644 --- a/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt +++ b/android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.kt @@ -1,17 +1,16 @@ 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; -import android.content.Context; -import android.os.Build -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import androidx.annotation.RequiresApi - -class RNTextInputResetModule(private val reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext) { +class RNTextInputResetModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule( + reactContext +) { override fun getName(): String = "RNTextInputReset" // Props to https://github.com/MattFoley for this temporary hack @@ -19,7 +18,9 @@ class RNTextInputResetModule(private val reactContext: ReactApplicationContext): @ReactMethod fun resetKeyboardInput(nativeId: String) { reactContext.runOnUiQueueThread { - val imm = reactApplicationContext.baseContext.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager + 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) }