Skip to content

Commit b2c8777

Browse files
committed
fix(mobile): update keyboard state after nonanimated inset recovery
1 parent 9c6b80e commit b2c8777

2 files changed

Lines changed: 103 additions & 3 deletions

File tree

‎patches/[email protected]‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,39 @@ index 827436c..fe9f371 100644
229229
}
230230
//# sourceMappingURL=index.js.map
231231
\ No newline at end of file
232+
diff --git a/lib/commonjs/hooks/useKeyboardState/index.js b/lib/commonjs/hooks/useKeyboardState/index.js
233+
index a4b287006a47011a58c8a16f19b31a479087f44e..fc1da8b8c843968ade0a7033a70136166a80b674 100644
234+
--- a/lib/commonjs/hooks/useKeyboardState/index.js
235+
+++ b/lib/commonjs/hooks/useKeyboardState/index.js
236+
@@ -7,7 +7,7 @@ exports.useKeyboardState = useKeyboardState;
237+
var _react = require("react");
238+
var _bindings = require("../../bindings");
239+
var _module = require("../../module");
240+
-const EVENTS = ["keyboardWillShow", "keyboardDidHide"];
241+
+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"];
242+
const getLatestState = () => ({
243+
..._module.KeyboardController.state(),
244+
isVisible: _module.KeyboardController.isVisible()
245+
diff --git a/lib/commonjs/module.js b/lib/commonjs/module.js
246+
index f27c5a095129cf60831088a73ce94d44f3ba52cd..9f64d066a2e647759046a7e8bda2c1f7c29a6585 100644
247+
--- a/lib/commonjs/module.js
248+
+++ b/lib/commonjs/module.js
249+
@@ -18,10 +18,13 @@ _bindings.KeyboardEvents.addListener("keyboardDidHide", e => {
250+
isClosed = true;
251+
lastState = e;
252+
});
253+
-_bindings.KeyboardEvents.addListener("keyboardWillShow", e => {
254+
+const updateShownState = e => {
255+
isClosed = false;
256+
lastState = e;
257+
-});
258+
+};
259+
+_bindings.KeyboardEvents.addListener("keyboardWillShow", updateShownState);
260+
+// Android can restore IME insets without an animation and emit only didShow.
261+
+_bindings.KeyboardEvents.addListener("keyboardDidShow", updateShownState);
262+
const dismiss = async options => {
263+
const keepFocus = (options === null || options === void 0 ? void 0 : options.keepFocus) ?? false;
264+
const animated = (options === null || options === void 0 ? void 0 : options.animated) ?? true;
232265
diff --git a/lib/module/components/KeyboardChatScrollView/index.js b/lib/module/components/KeyboardChatScrollView/index.js
233266
index e0c8391..8df802a 100644
234267
--- a/lib/module/components/KeyboardChatScrollView/index.js
@@ -473,6 +506,39 @@ index 3c90439..9e7ebb6 100644
473506
export { useExtraContentPadding };
474507
//# sourceMappingURL=index.js.map
475508
\ No newline at end of file
509+
diff --git a/lib/module/hooks/useKeyboardState/index.js b/lib/module/hooks/useKeyboardState/index.js
510+
index 8da7c09fbb398253420d7bfcd9a85abdb981065b..813b8ec3471c3695f76cf911a4a9dc3853f8e23b 100644
511+
--- a/lib/module/hooks/useKeyboardState/index.js
512+
+++ b/lib/module/hooks/useKeyboardState/index.js
513+
@@ -1,7 +1,7 @@
514+
import { useEffect, useState } from "react";
515+
import { KeyboardEvents } from "../../bindings";
516+
import { KeyboardController } from "../../module";
517+
-const EVENTS = ["keyboardWillShow", "keyboardDidHide"];
518+
+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"];
519+
const getLatestState = () => ({
520+
...KeyboardController.state(),
521+
isVisible: KeyboardController.isVisible()
522+
diff --git a/lib/module/module.js b/lib/module/module.js
523+
index 01aad2effee498a8daec55e1d4644a5fbc723765..f4a87b3f0b7b39d819bc4ee7a2e1795211a8cf75 100644
524+
--- a/lib/module/module.js
525+
+++ b/lib/module/module.js
526+
@@ -12,10 +12,13 @@ KeyboardEvents.addListener("keyboardDidHide", e => {
527+
isClosed = true;
528+
lastState = e;
529+
});
530+
-KeyboardEvents.addListener("keyboardWillShow", e => {
531+
+const updateShownState = e => {
532+
isClosed = false;
533+
lastState = e;
534+
-});
535+
+};
536+
+KeyboardEvents.addListener("keyboardWillShow", updateShownState);
537+
+// Android can restore IME insets without an animation and emit only didShow.
538+
+KeyboardEvents.addListener("keyboardDidShow", updateShownState);
539+
const dismiss = async options => {
540+
const keepFocus = (options === null || options === void 0 ? void 0 : options.keepFocus) ?? false;
541+
const animated = (options === null || options === void 0 ? void 0 : options.animated) ?? true;
476542
diff --git a/lib/typescript/components/KeyboardChatScrollView/types.d.ts b/lib/typescript/components/KeyboardChatScrollView/types.d.ts
477543
index eba1514..6597d80 100644
478544
--- a/lib/typescript/components/KeyboardChatScrollView/types.d.ts
@@ -902,3 +968,37 @@ index e7584ed..dc653b0 100644
902968
);
903969
}
904970

971+
diff --git a/src/hooks/useKeyboardState/index.ts b/src/hooks/useKeyboardState/index.ts
972+
index e5fe38dd8e7b8370bfb575296259933094857ca5..d0b98f60a6d7ad7f72ebd70b22e1ce6b7fb56874 100644
973+
--- a/src/hooks/useKeyboardState/index.ts
974+
+++ b/src/hooks/useKeyboardState/index.ts
975+
@@ -5,7 +5,7 @@ import { KeyboardController } from "../../module";
976+
977+
import type { IKeyboardState } from "../../types";
978+
979+
-const EVENTS = ["keyboardWillShow", "keyboardDidHide"] as const;
980+
+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"] as const;
981+
982+
const getLatestState = () => ({
983+
...KeyboardController.state(),
984+
diff --git a/src/module.ts b/src/module.ts
985+
index f74941914c9ecebbd0a6c2ba55c5436378de79d4..317f9908d88cd2812567c079611d4884807b713d 100644
986+
--- a/src/module.ts
987+
+++ b/src/module.ts
988+
@@ -21,10 +21,14 @@ KeyboardEvents.addListener("keyboardDidHide", (e) => {
989+
lastState = e;
990+
});
991+
992+
-KeyboardEvents.addListener("keyboardWillShow", (e) => {
993+
+const updateShownState = (e: KeyboardEventData) => {
994+
isClosed = false;
995+
lastState = e;
996+
-});
997+
+};
998+
+
999+
+KeyboardEvents.addListener("keyboardWillShow", updateShownState);
1000+
+// Android can restore IME insets without an animation and emit only didShow.
1001+
+KeyboardEvents.addListener("keyboardDidShow", updateShownState);
1002+
1003+
const dismiss = async (options?: Partial<DismissOptions>): Promise<void> => {
1004+
const keepFocus = options?.keepFocus ?? false;

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)