From a231d4b16c3684a330a56e0bf0baa64d22f569f3 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Mon, 2 Dec 2024 15:28:52 +0100 Subject: [PATCH 1/3] fix: keyboard hide when press 'Save' button --- ...1+fallback-to-activity-current-focus.patch | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch diff --git a/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch b/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch new file mode 100644 index 000000000000..12161534dbfa --- /dev/null +++ b/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch @@ -0,0 +1,33 @@ +diff --git a/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt b/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt +index 472ee09..1ef2459 100644 +--- a/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt ++++ b/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt +@@ -24,17 +24,24 @@ class KeyboardControllerModuleImpl( + + fun dismiss() { + val activity = mReactContext.currentActivity +- val view: View? = FocusedInputHolder.get() ++ val view: View? = FocusedInputHolder.get() ?: activity?.currentFocus + + if (view != null) { +- val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager +- imm?.hideSoftInputFromWindow(view.windowToken, 0) ++ UiThreadUtil.runOnUiThread { ++ val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager ++ imm?.hideSoftInputFromWindow(view.windowToken, 0) ++ view.clearFocus() ++ } + } + } + + fun setFocusTo(direction: String) { + if (direction == "current") { +- return FocusedInputHolder.focus() ++ UiThreadUtil.runOnUiThread { ++ FocusedInputHolder.focus() ++ } ++ ++ return + } + + val view: View? = FocusedInputHolder.get() From 9981c5a41fbbf456c28270d6b96a2af69bdcdcf1 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Mon, 2 Dec 2024 15:46:16 +0100 Subject: [PATCH 2/3] fix: use `Keyboard` instead of `KeyboardEvents` --- src/utils/keyboard.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/utils/keyboard.ts b/src/utils/keyboard.ts index ed1df0efc700..a2b1d329aa0a 100644 --- a/src/utils/keyboard.ts +++ b/src/utils/keyboard.ts @@ -1,16 +1,15 @@ -import {KeyboardController, KeyboardEvents} from 'react-native-keyboard-controller'; +import {Keyboard} from 'react-native'; let isVisible = false; -KeyboardEvents.addListener('keyboardDidHide', () => { +Keyboard.addListener('keyboardDidHide', () => { isVisible = false; }); -KeyboardEvents.addListener('keyboardDidShow', () => { +Keyboard.addListener('keyboardDidShow', () => { isVisible = true; }); -// starting from react-native-keyboard-controller@1.15+ we can use `KeyboardController.dismiss()` directly const dismiss = (): Promise => { return new Promise((resolve) => { if (!isVisible) { @@ -19,12 +18,12 @@ const dismiss = (): Promise => { return; } - const subscription = KeyboardEvents.addListener('keyboardDidHide', () => { + const subscription = Keyboard.addListener('keyboardDidHide', () => { resolve(undefined); subscription.remove(); }); - KeyboardController.dismiss(); + Keyboard.dismiss(); }); }; From b7ca605a0c749d46732a20d9b1185f3414a73876 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Mon, 2 Dec 2024 15:47:26 +0100 Subject: [PATCH 3/3] fix: remove patch since it's not necessary anymore --- ...1+fallback-to-activity-current-focus.patch | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch diff --git a/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch b/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch deleted file mode 100644 index 12161534dbfa..000000000000 --- a/patches/react-native-keyboard-controller+1.14.4+001+fallback-to-activity-current-focus.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt b/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt -index 472ee09..1ef2459 100644 ---- a/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt -+++ b/node_modules/react-native-keyboard-controller/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt -@@ -24,17 +24,24 @@ class KeyboardControllerModuleImpl( - - fun dismiss() { - val activity = mReactContext.currentActivity -- val view: View? = FocusedInputHolder.get() -+ val view: View? = FocusedInputHolder.get() ?: activity?.currentFocus - - if (view != null) { -- val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager -- imm?.hideSoftInputFromWindow(view.windowToken, 0) -+ UiThreadUtil.runOnUiThread { -+ val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager -+ imm?.hideSoftInputFromWindow(view.windowToken, 0) -+ view.clearFocus() -+ } - } - } - - fun setFocusTo(direction: String) { - if (direction == "current") { -- return FocusedInputHolder.focus() -+ UiThreadUtil.runOnUiThread { -+ FocusedInputHolder.focus() -+ } -+ -+ return - } - - val view: View? = FocusedInputHolder.get()