Skip to content

Commit b231e15

Browse files
authored
Merge pull request Expensify#66952 from software-mansion-labs/war-in/dont-use-findNodeHandle-when-resetting-keyboard
Use `nativeId` to reset keyboard on Android - remove `findNodeHandle` usage
2 parents c2a15d5 + 9dc9b22 commit b231e15

5 files changed

Lines changed: 35 additions & 43 deletions

File tree

android/app/src/main/java/com/expensify/chat/RNTextInputResetModule.java

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.expensify.chat;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
import android.view.inputmethod.InputMethodManager;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
8+
import com.facebook.react.bridge.ReactMethod;
9+
import com.facebook.react.uimanager.util.ReactFindViewUtil;
10+
11+
class RNTextInputResetModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(
12+
reactContext
13+
) {
14+
override fun getName(): String = "RNTextInputReset"
15+
16+
// Props to https://github.com/MattFoley for this temporary hack
17+
// https://github.com/facebook/react-native/pull/12462#issuecomment-298812731
18+
@ReactMethod
19+
fun resetKeyboardInput(nativeId: String) {
20+
reactContext.runOnUiQueueThread {
21+
val imm = reactApplicationContext.baseContext.getSystemService(
22+
Context.INPUT_METHOD_SERVICE
23+
) as? InputMethodManager
24+
25+
val reactNativeView = currentActivity?.findViewById<View>(android.R.id.content)
26+
val viewToReset = reactNativeView?.let { ReactFindViewUtil.findView(it, nativeId) }
27+
imm?.restartInput(viewToReset)
28+
}
29+
}
30+
}

cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@
730730
"pnrs",
731731
"POLICYCHANGELOG_ADD_EMPLOYEE",
732732
"xcshareddata",
733-
"xcuserdata"
733+
"xcuserdata",
734+
"inputmethod"
734735
],
735736
"ignorePaths": [
736737
"src/languages/de.ts",

src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ function ComposerWithSuggestions(
305305
if (!RNTextInputReset) {
306306
return;
307307
}
308-
RNTextInputReset.resetKeyboardInput(findNodeHandle(textInputRef.current));
309-
}, [textInputRef]);
308+
RNTextInputReset.resetKeyboardInput(CONST.COMPOSER.NATIVE_ID);
309+
}, []);
310310

311311
const debouncedSaveReportComment = useMemo(
312312
() =>

src/types/modules/react-native.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type AppStateTrackerModule = {
1515
};
1616

1717
type RNTextInputResetModule = {
18-
resetKeyboardInput: (nodeHandle: number | null) => void;
18+
resetKeyboardInput: (nativeId: string) => void;
1919
};
2020

2121
type RNNavBarManagerModule = {

0 commit comments

Comments
 (0)