Skip to content

Commit 8b7cd25

Browse files
fix(mobile): the chat inset resets after the keyboard closes while frozen
KeyboardChatScrollView skips every keyboard write while frozen. On unfreeze, useFrozenPadding reconciled padding but not currentHeight, which iOS uses for the inset reported through onContentInsetChange. Legend List kept the open keyboard's inset, so scrolling to the end left a keyboard-sized gap under the last message. Reconcile currentHeight together with padding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dc72705 commit 8b7cd25

2 files changed

Lines changed: 143 additions & 9 deletions

File tree

‎patches/[email protected]‎

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ index ae97d611a7f727ebbb0e17eabbb3294e1cc76a2f..2ea1d2ddd3fac6ad418d97c700ab885f
8686
@objc public init(
8787
handler: @escaping (NSString, NSNumber, NSNumber, NSNumber, NSNumber) -> Void,
8888
diff --git a/lib/commonjs/components/KeyboardChatScrollView/index.js b/lib/commonjs/components/KeyboardChatScrollView/index.js
89-
index 0b78ff38d8f0a2360632df3d9988c0c32bd56b99..98b3b6cd71626fae57e83b214ebfb2a58850879a 100644
89+
index 0b78ff38d8f0a2360632df3d9988c0c32bd56b99..9600d6c8ac857a3f56753f49b5a52e3eb830eaba 100644
9090
--- a/lib/commonjs/components/KeyboardChatScrollView/index.js
9191
+++ b/lib/commonjs/components/KeyboardChatScrollView/index.js
9292
@@ -28,9 +28,12 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
@@ -120,7 +120,17 @@ index 0b78ff38d8f0a2360632df3d9988c0c32bd56b99..98b3b6cd71626fae57e83b214ebfb2a5
120120
scroll,
121121
layout,
122122
size,
123-
@@ -91,10 +98,26 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
123+
@@ -72,7 +79,8 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
124+
(0, _useFrozenPadding.useFrozenPadding)({
125+
freeze: freezeSV,
126+
offset,
127+
- padding
128+
+ padding,
129+
+ currentHeight
130+
});
131+
(0, _useEndVisible.useEndVisible)({
132+
scroll,
133+
@@ -91,10 +99,26 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
124134
// a bug for you, please open an issue.
125135
const totalPadding = (0, _reanimated.useDerivedValue)(() => Math.min(layout.value.height, Math.max(blankSpace.value, padding.value + extraContentPadding.value)));
126136

@@ -320,6 +330,31 @@ index 1c2912e70a1a0c4a75ae8ec4cfbc4d7fa7bc6b83..eaf845042700207e4251b2fa66e5797b
320330
}
321331
//# sourceMappingURL=index.js.map
322332
\ No newline at end of file
333+
diff --git a/lib/commonjs/components/KeyboardChatScrollView/useFrozenPadding/index.js b/lib/commonjs/components/KeyboardChatScrollView/useFrozenPadding/index.js
334+
index 444fef5eea3988b60cb62a6b4b42084ef0510fd9..3e684bf71d5e58659a8367733a7c2ee47cc05455 100644
335+
--- a/lib/commonjs/components/KeyboardChatScrollView/useFrozenPadding/index.js
336+
+++ b/lib/commonjs/components/KeyboardChatScrollView/useFrozenPadding/index.js
337+
@@ -30,7 +30,8 @@ var _helpers = require("../useChatKeyboard/helpers");
338+
function useFrozenPadding({
339+
freeze,
340+
offset,
341+
- padding
342+
+ padding,
343+
+ currentHeight
344+
}) {
345+
const lastHeight = (0, _reactNativeReanimated.useSharedValue)(0);
346+
const targetKeyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
347+
@@ -56,7 +57,9 @@ function useFrozenPadding({
348+
}, []);
349+
(0, _reanimated.useAnimatedReaction)(() => freeze.value, (isFrozen, wasFrozen) => {
350+
if (!isFrozen && wasFrozen === true) {
351+
- padding.value = (0, _helpers.getEffectiveHeight)(lastHeight.value, targetKeyboardHeight.value, offset);
352+
+ const effective = (0, _helpers.getEffectiveHeight)(lastHeight.value, targetKeyboardHeight.value, offset);
353+
+ padding.value = effective;
354+
+ currentHeight.value = effective;
355+
}
356+
}, [offset]);
357+
}
323358
diff --git a/lib/commonjs/hooks/useKeyboardState/index.js b/lib/commonjs/hooks/useKeyboardState/index.js
324359
index a4b287006a47011a58c8a16f19b31a479087f44e..4084025d644c8555b269f9d496266e2cb3234024 100644
325360
--- a/lib/commonjs/hooks/useKeyboardState/index.js
@@ -351,7 +386,7 @@ index f27c5a095129cf60831088a73ce94d44f3ba52cd..3c2f7569510d0a56fd937b6e91a6adc0
351386
const keepFocus = (options === null || options === void 0 ? void 0 : options.keepFocus) ?? false;
352387
const animated = (options === null || options === void 0 ? void 0 : options.animated) ?? true;
353388
diff --git a/lib/module/components/KeyboardChatScrollView/index.js b/lib/module/components/KeyboardChatScrollView/index.js
354-
index e0c83918d9569e2ff541e45d31460121c73ec225..8df802ae65ea322c3f004395b622dd3563d00835 100644
389+
index e0c83918d9569e2ff541e45d31460121c73ec225..724c62e2892f75f6bb53844b84c1ade1bf87c7ec 100644
355390
--- a/lib/module/components/KeyboardChatScrollView/index.js
356391
+++ b/lib/module/components/KeyboardChatScrollView/index.js
357392
@@ -1,9 +1,9 @@
@@ -398,7 +433,17 @@ index e0c83918d9569e2ff541e45d31460121c73ec225..8df802ae65ea322c3f004395b622dd35
398433
scroll,
399434
layout,
400435
size,
401-
@@ -84,10 +91,26 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
436+
@@ -65,7 +72,8 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
437+
useFrozenPadding({
438+
freeze: freezeSV,
439+
offset,
440+
- padding
441+
+ padding,
442+
+ currentHeight
443+
});
444+
useEndVisible({
445+
scroll,
446+
@@ -84,10 +92,26 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
402447
// a bug for you, please open an issue.
403448
const totalPadding = useDerivedValue(() => Math.min(layout.value.height, Math.max(blankSpace.value, padding.value + extraContentPadding.value)));
404449

@@ -598,6 +643,31 @@ index 458bced308670ec6bb30f8f5ef037ab841f4372b..9b7f1a5e9fa38928a07e7a462919105b
598643
export { useExtraContentPadding };
599644
//# sourceMappingURL=index.js.map
600645
\ No newline at end of file
646+
diff --git a/lib/module/components/KeyboardChatScrollView/useFrozenPadding/index.js b/lib/module/components/KeyboardChatScrollView/useFrozenPadding/index.js
647+
index eddfd75913fef9111178771b4d5b4ba49864d217..d03dbd1e1fcbecb1866fb02547961a754eaf06e7 100644
648+
--- a/lib/module/components/KeyboardChatScrollView/useFrozenPadding/index.js
649+
+++ b/lib/module/components/KeyboardChatScrollView/useFrozenPadding/index.js
650+
@@ -24,7 +24,8 @@ import { getEffectiveHeight } from "../useChatKeyboard/helpers";
651+
function useFrozenPadding({
652+
freeze,
653+
offset,
654+
- padding
655+
+ padding,
656+
+ currentHeight
657+
}) {
658+
const lastHeight = useSharedValue(0);
659+
const targetKeyboardHeight = useSharedValue(0);
660+
@@ -50,7 +51,9 @@ function useFrozenPadding({
661+
}, []);
662+
useAnimatedReaction(() => freeze.value, (isFrozen, wasFrozen) => {
663+
if (!isFrozen && wasFrozen === true) {
664+
- padding.value = getEffectiveHeight(lastHeight.value, targetKeyboardHeight.value, offset);
665+
+ const effective = getEffectiveHeight(lastHeight.value, targetKeyboardHeight.value, offset);
666+
+ padding.value = effective;
667+
+ currentHeight.value = effective;
668+
}
669+
}, [offset]);
670+
}
601671
diff --git a/lib/module/hooks/useKeyboardState/index.js b/lib/module/hooks/useKeyboardState/index.js
602672
index 8da7c09fbb398253420d7bfcd9a85abdb981065b..31b1ff4370d8328a0569e559e3bbfa4b201f5a9d 100644
603673
--- a/lib/module/hooks/useKeyboardState/index.js
@@ -683,8 +753,27 @@ index ec73f70544a062fbecfc1d8be92d839d3e0bea6f..45b387446587fd3e611fa02a01534bb5
683753
/** Current vertical scroll offset. */
684754
scroll: SharedValue<number>;
685755
/** Visible viewport dimensions. */
756+
diff --git a/lib/typescript/components/KeyboardChatScrollView/useFrozenPadding/index.d.ts b/lib/typescript/components/KeyboardChatScrollView/useFrozenPadding/index.d.ts
757+
index 5c92b3850e21039eb7f11eb2944e2478c0ebab88..01d310135f5328f687087db09d9efb6a498e53d1 100644
758+
--- a/lib/typescript/components/KeyboardChatScrollView/useFrozenPadding/index.d.ts
759+
+++ b/lib/typescript/components/KeyboardChatScrollView/useFrozenPadding/index.d.ts
760+
@@ -6,6 +6,7 @@ type UseFrozenPaddingOptions = {
761+
offset: number;
762+
/** Keyboard-driven padding managed by `useChatKeyboard`. */
763+
padding: SharedValue<number>;
764+
+ currentHeight: SharedValue<number>;
765+
};
766+
/**
767+
* Hook that reconciles keyboard padding after a frozen interval.
768+
@@ -26,5 +27,5 @@ type UseFrozenPaddingOptions = {
769+
* useFrozenPadding({ freeze, offset, padding });
770+
* ```
771+
*/
772+
-declare function useFrozenPadding({ freeze, offset, padding, }: UseFrozenPaddingOptions): void;
773+
+declare function useFrozenPadding({ freeze, offset, padding, currentHeight, }: UseFrozenPaddingOptions): void;
774+
export { useFrozenPadding };
686775
diff --git a/src/components/KeyboardChatScrollView/index.tsx b/src/components/KeyboardChatScrollView/index.tsx
687-
index 935bc71dabad6cd5c82bab77f64b5b6e1e5dc9b6..d411dc4a895c6a4c07bba31676defbacb77e056b 100644
776+
index 935bc71dabad6cd5c82bab77f64b5b6e1e5dc9b6..5306506e791c64e6c64abc91499c8974ac318301 100644
688777
--- a/src/components/KeyboardChatScrollView/index.tsx
689778
+++ b/src/components/KeyboardChatScrollView/index.tsx
690779
@@ -1,9 +1,13 @@
@@ -735,7 +824,15 @@ index 935bc71dabad6cd5c82bab77f64b5b6e1e5dc9b6..d411dc4a895c6a4c07bba31676defbac
735824
scroll,
736825
layout,
737826
size,
738-
@@ -109,13 +120,40 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
827+
@@ -85,6 +96,7 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
828+
freeze: freezeSV,
829+
offset,
830+
padding,
831+
+ currentHeight,
832+
});
833+
834+
useEndVisible({
835+
@@ -109,13 +121,40 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
739836
),
740837
);
741838

@@ -1055,6 +1152,43 @@ index 78fe7cf88b110c955a36d8df2ee5b90c088d4228..98719c1a320c474fc45a846d8ea8b16a
10551152
);
10561153
}
10571154

1155+
diff --git a/src/components/KeyboardChatScrollView/useFrozenPadding/index.ts b/src/components/KeyboardChatScrollView/useFrozenPadding/index.ts
1156+
index 00b01bf2e8c8e948c15e1b89318bb82fef2c5f3f..26c4560230921074aa8ce31fad4615e5188e26c1 100644
1157+
--- a/src/components/KeyboardChatScrollView/useFrozenPadding/index.ts
1158+
+++ b/src/components/KeyboardChatScrollView/useFrozenPadding/index.ts
1159+
@@ -13,6 +13,8 @@ type UseFrozenPaddingOptions = {
1160+
offset: number;
1161+
/** Keyboard-driven padding managed by `useChatKeyboard`. */
1162+
padding: SharedValue<number>;
1163+
+ /** Presentation keyboard height managed by `useChatKeyboard`. */
1164+
+ currentHeight: SharedValue<number>;
1165+
};
1166+
1167+
/**
1168+
@@ -38,6 +40,7 @@ function useFrozenPadding({
1169+
freeze,
1170+
offset,
1171+
padding,
1172+
+ currentHeight,
1173+
}: UseFrozenPaddingOptions): void {
1174+
const lastHeight = useSharedValue(0);
1175+
const targetKeyboardHeight = useSharedValue(0);
1176+
@@ -70,11 +73,14 @@ function useFrozenPadding({
1177+
() => freeze.value,
1178+
(isFrozen, wasFrozen) => {
1179+
if (!isFrozen && wasFrozen === true) {
1180+
- padding.value = getEffectiveHeight(
1181+
+ const effective = getEffectiveHeight(
1182+
lastHeight.value,
1183+
targetKeyboardHeight.value,
1184+
offset,
1185+
);
1186+
+
1187+
+ padding.value = effective;
1188+
+ currentHeight.value = effective;
1189+
}
1190+
},
1191+
[offset],
10581192
diff --git a/src/hooks/useKeyboardState/index.ts b/src/hooks/useKeyboardState/index.ts
10591193
index e5fe38dd8e7b8370bfb575296259933094857ca5..d0b98f60a6d7ad7f72ebd70b22e1ce6b7fb56874 100644
10601194
--- a/src/hooks/useKeyboardState/index.ts

‎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)