Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

react-native-keyboard-controller@1.22.8.patch

1,088 lines51.2 KB

1diff --git a/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift b/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift
2index cdbd633..41a72bc 100644
3--- a/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift
4+++ b/ios/observers/movement/observer/KeyboardMovementObserver+Lifecycle.swift
5@@ -25,6 +25,12 @@ public extension KeyboardMovementObserver {
6 name: UIResponder.keyboardWillShowNotification,
7 object: nil
8 )
9+ NotificationCenter.default.addObserver(
10+ self,
11+ selector: #selector(keyboardWillChangeFrame),
12+ name: UIResponder.keyboardWillChangeFrameNotification,
13+ object: nil
14+ )
15 }
17 @objc func unmount() {
18diff --git a/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift b/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift
19index 545a5b2..fbdc984 100644
20--- a/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift
21+++ b/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift
22@@ -8,6 +8,12 @@
23 extension KeyboardMovementObserver {
24 @objc func keyboardWillAppear(_ notification: Notification) {
25 guard !UIResponder.isKeyboardPreloading else { return }
26+ floatingHideTask?.cancel()
28+ if isFloatingKeyboard(notification) {
29+ hideIfKeyboardShown(notification)
30+ return
31+ }
33 let (duration, frame) = notification.keyboardMetaData()
34 if let keyboardFrame = frame {
35@@ -36,8 +42,40 @@ extension KeyboardMovementObserver {
36 }
37 }
39+ @objc func keyboardWillChangeFrame(_ notification: Notification) {
40+ guard !UIResponder.isKeyboardPreloading, isFloatingKeyboard(notification) else { return }
41+ // runs after a willShow/willHide posted with this notification, which cancel it, so hide events fire once
42+ floatingHideTask?.cancel()
43+ let task = DispatchWorkItem { [weak self] in
44+ self?.hideIfKeyboardShown(notification)
45+ }
46+ floatingHideTask = task
47+ DispatchQueue.main.async(execute: task)
48+ }
50+ // iPadOS floating and minimized keyboards are narrower than the screen or end above the app's bottom, so
51+ // they cover no app content; UIKit switches to them without willHide, so they must count as hidden.
52+ private func isFloatingKeyboard(_ notification: Notification) -> Bool {
53+ guard let frame = notification.keyboardMetaData().1?.cgRectValue, !frame.isEmpty else { return false }
54+ let screen = (notification.object as? UIScreen ?? UIScreen.main).bounds
55+ // in Slide Over a docked keyboard ends at the app window's bottom, above the screen's
56+ let windowBottom = UIApplication.shared.activeWindow.map {
57+ $0.convert($0.bounds, to: $0.screen.coordinateSpace).maxY
58+ } ?? screen.height
59+ let dockedBottom = min(screen.height, windowBottom)
60+ return frame.width.rounded() < screen.width.rounded() || frame.maxY.rounded() < dockedBottom.rounded()
61+ }
63+ private func hideIfKeyboardShown(_ notification: Notification) {
64+ let targetHeight = self.notification?.keyboardMetaData().1?.cgRectValue.height ?? 0
65+ if targetHeight > 0 {
66+ keyboardWillDisappear(notification)
67+ }
68+ }
70 @objc func keyboardWillDisappear(_ notification: Notification) {
71 guard !UIResponder.isKeyboardPreloading else { return }
72+ floatingHideTask?.cancel()
73 let (duration, _) = notification.keyboardMetaData()
74 tag = UIResponder.current.reactViewTag
75 self.notification = notification
76diff --git a/ios/observers/movement/observer/KeyboardMovementObserver.swift b/ios/observers/movement/observer/KeyboardMovementObserver.swift
77index ae97d61..2ea1d2d 100644
78--- a/ios/observers/movement/observer/KeyboardMovementObserver.swift
79+++ b/ios/observers/movement/observer/KeyboardMovementObserver.swift
80@@ -37,6 +37,7 @@ public class KeyboardMovementObserver: NSObject {
81 // manual did events
82 var notification: Notification?
83 var keyboardDidTask: DispatchWorkItem?
84+ var floatingHideTask: DispatchWorkItem?
86 @objc public init(
87 handler: @escaping (NSString, NSNumber, NSNumber, NSNumber, NSNumber) -> Void,
88diff --git a/lib/commonjs/components/KeyboardChatScrollView/index.js b/lib/commonjs/components/KeyboardChatScrollView/index.js
89index 0b78ff3..98b3b6c 100644
90--- a/lib/commonjs/components/KeyboardChatScrollView/index.js
91+++ b/lib/commonjs/components/KeyboardChatScrollView/index.js
92@@ -28,9 +28,12 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
93 offset = 0,
94 extraContentPadding = ZERO_CONTENT_PADDING,
95 blankSpace = ZERO_BLANK_SPACE,
96+ adjustedInsetCompensation = 0,
97+ adjustedStartInsetCompensation = 0,
98 applyWorkaroundForContentInsetHitTestBug = false,
99 onLayout: onLayoutProp,
100 onContentSizeChange: onContentSizeChangeProp,
101+ onContentInsetChange,
102 onEndVisible,
103 ...rest
104 }, ref) => {
105@@ -54,6 +57,8 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
106 offset,
107 blankSpace,
108 extraContentPadding,
109+ adjustedInsetCompensation,
110+ adjustedStartInsetCompensation,
111 initialContentOffsetY: (_rest$contentOffset = rest.contentOffset) === null || _rest$contentOffset === void 0 ? void 0 : _rest$contentOffset.y
112 });
113 (0, _useExtraContentPadding.useExtraContentPadding)({
114@@ -61,6 +66,8 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
115 extraContentPadding,
116 keyboardPadding: padding,
117 blankSpace,
118+ adjustedInsetCompensation,
119+ adjustedStartInsetCompensation,
120 scroll,
121 layout,
122 size,
123@@ -91,10 +98,26 @@ const KeyboardChatScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
124 // a bug for you, please open an issue.
125 const totalPadding = (0, _reanimated.useDerivedValue)(() => Math.min(layout.value.height, Math.max(blankSpace.value, padding.value + extraContentPadding.value)));
127+ // iOS applies the destination contentInset and contentOffset together at
128+ // keyboard-animation start. Keep that native target behavior, but report
129+ // the presentation height so virtualized-list layout follows the keyboard.
130+ const reportedPadding = (0, _reanimated.useDerivedValue)(() => _reactNative.Platform.OS === "ios" ? Math.min(layout.value.height, Math.max(blankSpace.value, currentHeight.value + extraContentPadding.value)) : totalPadding.value);
132+ // Mirror the effective bottom padding (keyboard + composer + blank floor)
133+ // to the consumer - a virtualized list needs it in its own scroll math or
134+ // its end/maintain targets point at the under-the-keyboard resting offset.
135+ (0, _reanimated.useAnimatedReaction)(() => reportedPadding.value, (current, previous) => {
136+ if (onContentInsetChange && current !== previous) {
137+ (0, _reactNativeReanimated.runOnJS)(onContentInsetChange)({
138+ bottom: current
139+ });
140+ }
141+ }, [onContentInsetChange]);
143 // Scroll indicator inset = keyboard + extraContentPadding (excludes blankSpace).
144 // Apps that render into the unsafe area can supply a negative
145 // scrollIndicatorInsets adjustment at the application layer.
146- const indicatorPadding = (0, _reanimated.useDerivedValue)(() => padding.value + extraContentPadding.value);
147+ const indicatorPadding = (0, _reanimated.useDerivedValue)(() => padding.value);
148 const onLayout = (0, _react.useCallback)(e => {
149 onLayoutInternal(e);
150 onLayoutProp === null || onLayoutProp === void 0 || onLayoutProp(e);
151diff --git a/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js b/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
152index 4d33b3f..6a787d3 100644
153--- a/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
154+++ b/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
155@@ -206,7 +206,7 @@ const clampedScrollTarget = (offsetBeforeScroll, keyboardHeight, contentHeight,
156 * ```
157 */
158 exports.clampedScrollTarget = clampedScrollTarget;
159-const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentHeight, layoutHeight, inverted, totalPaddingForMaxScroll) => {
160+const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentHeight, layoutHeight, inverted, totalPaddingForMaxScroll, startInsetCompensation = 0) => {
161 "worklet";
163 const paddingForMax = totalPaddingForMaxScroll !== undefined ? totalPaddingForMaxScroll : keyboardHeight;
164@@ -214,8 +214,9 @@ const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentHeight,
165 const maxScroll = Math.max(contentHeight - layoutHeight, 0);
166 return Math.max(Math.min(relativeScroll - keyboardHeight, maxScroll), -paddingForMax);
167 }
168- const maxScroll = Math.max(contentHeight - layoutHeight + paddingForMax, 0);
169- return Math.min(Math.max(keyboardHeight + relativeScroll, 0), maxScroll);
170+ const minScroll = -startInsetCompensation;
171+ const maxScroll = Math.max(contentHeight - layoutHeight + paddingForMax, minScroll);
172+ return Math.min(Math.max(keyboardHeight + relativeScroll, minScroll), maxScroll);
173 };
174 exports.computeIOSContentOffset = computeIOSContentOffset;
175 //# sourceMappingURL=helpers.js.map
176\ No newline at end of file
177diff --git a/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js b/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
178index 6481228..0dc5dd1 100644
179--- a/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
180+++ b/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
181@@ -32,7 +32,9 @@ function useChatKeyboard(scrollViewRef, options) {
182 freeze,
183 offset,
184 blankSpace,
185- extraContentPadding
186+ extraContentPadding,
187+ adjustedInsetCompensation,
188+ adjustedStartInsetCompensation
189 } = options;
190 const padding = (0, _reactNativeReanimated.useSharedValue)(0);
191 const currentHeight = (0, _reactNativeReanimated.useSharedValue)(0);
192@@ -59,6 +61,9 @@ function useChatKeyboard(scrollViewRef, options) {
193 targetKeyboardHeight.value = e.height;
194 }
195 const effective = (0, _helpers.getEffectiveHeight)(e.height, targetKeyboardHeight.value, offset);
196+ if (e.duration === 0) {
197+ currentHeight.value = effective;
198+ }
199 const atEnd = (0, _helpers.isScrollAtEnd)(scroll.value, layout.value.height, size.value.height, inverted);
201 // Scale minimum padding absorption by how much of it is visible.
202@@ -67,7 +72,7 @@ function useChatKeyboard(scrollViewRef, options) {
203 const visiblePadding = visibleFraction * blankSpace.value;
204 const minimumPaddingAbsorbed = Math.max(0, visiblePadding - extraContentPadding.value);
205 const scrollEffective = (0, _helpers.getScrollEffective)(effective, minimumPaddingAbsorbed);
206- const actualTotalPadding = Math.max(blankSpace.value, effective + extraContentPadding.value);
207+ const actualTotalPadding = Math.max(blankSpace.value, effective + extraContentPadding.value) + adjustedInsetCompensation;
209 // `onInteractive` owns the native scroll offset. When its final
210 // keyboardWillHide event arrives, consume the marker so this
211@@ -87,8 +92,8 @@ function useChatKeyboard(scrollViewRef, options) {
212 const maxScroll = Math.max(size.value.height - layout.value.height, 0);
213 contentOffsetY.value = Math.max(-actualTotalPadding, Math.min(scroll.value, maxScroll));
214 } else {
215- const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, 0);
216- contentOffsetY.value = Math.max(0, Math.min(scroll.value, maxScroll));
217+ const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, -adjustedStartInsetCompensation);
218+ contentOffsetY.value = Math.max(-adjustedStartInsetCompensation, Math.min(scroll.value, maxScroll));
219 }
220 return;
221 }
222@@ -102,8 +107,8 @@ function useChatKeyboard(scrollViewRef, options) {
223 const maxScroll = Math.max(size.value.height - layout.value.height, 0);
224 contentOffsetY.value = Math.max(-actualTotalPadding, Math.min(scroll.value, maxScroll));
225 } else {
226- const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, 0);
227- contentOffsetY.value = Math.max(0, Math.min(scroll.value, maxScroll));
228+ const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, -adjustedStartInsetCompensation);
229+ contentOffsetY.value = Math.max(-adjustedStartInsetCompensation, Math.min(scroll.value, maxScroll));
230 }
231 return;
232 }
233@@ -129,17 +134,25 @@ function useChatKeyboard(scrollViewRef, options) {
234 contentOffsetY.value = scroll.value;
235 return;
236 }
237- contentOffsetY.value = (0, _helpers.computeIOSContentOffset)(relativeScroll, scrollEffective, size.value.height, layout.value.height, inverted, actualTotalPadding);
238+ contentOffsetY.value = (0, _helpers.computeIOSContentOffset)(relativeScroll, scrollEffective, size.value.height, layout.value.height, inverted, actualTotalPadding, adjustedStartInsetCompensation);
239 },
240- onInteractive: () => {
241+ onMove: e => {
242 "worklet";
244- isInteractiveDismissal.value = true;
245+ if (freeze.value) {
246+ return;
247+ }
248+ currentHeight.value = (0, _helpers.getEffectiveHeight)(e.height, targetKeyboardHeight.value, offset);
249 },
250- onMove: () => {
251+ onInteractive: e => {
252 "worklet";
254- // iOS doesn't need per-frame updates (contentOffset handles it)
255+ isInteractiveDismissal.value = true;
257+ if (freeze.value) {
258+ return;
259+ }
260+ currentHeight.value = (0, _helpers.getEffectiveHeight)(e.height, targetKeyboardHeight.value, offset);
261 },
262 onEnd: e => {
263 "worklet";
264@@ -148,9 +161,10 @@ function useChatKeyboard(scrollViewRef, options) {
265 return;
266 }
267 const effective = (0, _helpers.getEffectiveHeight)(e.height, targetKeyboardHeight.value, offset);
268+ currentHeight.value = effective;
269 padding.value = effective;
270 }
271- }, [inverted, keyboardLiftBehavior, offset, extraContentPadding]);
272+ }, [inverted, keyboardLiftBehavior, offset, extraContentPadding, adjustedInsetCompensation, adjustedStartInsetCompensation]);
273 return {
274 padding,
275 currentHeight,
276diff --git a/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js b/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js
277index 11e81a9..de39eac 100644
278--- a/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js
279+++ b/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js
280@@ -33,6 +33,8 @@ function useExtraContentPadding(options) {
281 extraContentPadding,
282 keyboardPadding,
283 blankSpace,
284+ adjustedInsetCompensation,
285+ adjustedStartInsetCompensation,
286 scroll,
287 layout,
288 size,
289@@ -74,8 +76,8 @@ function useExtraContentPadding(options) {
290 }
292 // Compute effective delta considering blankSpace floor
293- const previousTotal = Math.max(blankSpace.value, keyboardPadding.value + previous);
294- const currentTotal = Math.max(blankSpace.value, keyboardPadding.value + current);
295+ const previousTotal = Math.max(blankSpace.value, keyboardPadding.value + previous) + adjustedInsetCompensation;
296+ const currentTotal = Math.max(blankSpace.value, keyboardPadding.value + current) + adjustedInsetCompensation;
297 const effectiveDelta = currentTotal - previousTotal;
298 if (effectiveDelta === 0) {
299 // blankSpace absorbed the change
300@@ -116,14 +118,15 @@ function useExtraContentPadding(options) {
301 if (inverted) {
302 target = Math.max(base - effectiveDelta, -currentTotal);
303 } else {
304- const maxScroll = Math.max(size.value.height - layout.value.height + currentTotal, 0);
305+ const minScroll = -adjustedStartInsetCompensation;
306+ const maxScroll = Math.max(size.value.height - layout.value.height + currentTotal, minScroll);
308- // Clamp at 0 as well: when the content is shorter than the viewport a
309- // shrinking padding makes `effectiveDelta` negative while `base` is
310- // already 0, so the target would go below the top of the content.
311- target = Math.max(Math.min(base + effectiveDelta, maxScroll), 0);
312+ // Clamp at the top as well: when the content is shorter than the
313+ // viewport a shrinking padding makes `effectiveDelta` negative while
314+ // `base` is already at the top.
315+ target = Math.max(minScroll, Math.min(base + effectiveDelta, maxScroll));
316 }
317 scrollToTarget(target);
318- }, [inverted, keyboardLiftBehavior]);
319+ }, [inverted, keyboardLiftBehavior, adjustedInsetCompensation, adjustedStartInsetCompensation]);
320 }
321 //# sourceMappingURL=index.js.map
322\ No newline at end of file
323diff --git a/lib/commonjs/hooks/useKeyboardState/index.js b/lib/commonjs/hooks/useKeyboardState/index.js
324index a4b287006a47011a58c8a16f19b31a479087f44e..4084025d644c8555b269f9d496266e2cb3234024 100644
325--- a/lib/commonjs/hooks/useKeyboardState/index.js
326+++ b/lib/commonjs/hooks/useKeyboardState/index.js
327@@ -7,7 +7,7 @@ exports.useKeyboardState = useKeyboardState;
328 var _react = require("react");
329 var _bindings = require("../../bindings");
330 var _module = require("../../module");
331-const EVENTS = ["keyboardWillShow", "keyboardDidHide"];
332+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"];
333 const getLatestState = () => ({
334 ..._module.KeyboardController.state(),
335 isVisible: _module.KeyboardController.isVisible()
336diff --git a/lib/commonjs/module.js b/lib/commonjs/module.js
337index f27c5a095129cf60831088a73ce94d44f3ba52cd..3c2f7569510d0a56fd937b6e91a6adc0d5ff6f59 100644
338--- a/lib/commonjs/module.js
339+++ b/lib/commonjs/module.js
340@@ -22,6 +22,12 @@ _bindings.KeyboardEvents.addListener("keyboardWillShow", e => {
341 isClosed = false;
342 lastState = e;
343 });
344+// Android re-syncs an IME inset that changes without an animation with keyboardDidShow
345+// alone. Drop with kirillzyusko/react-native-keyboard-controller#1698.
346+_bindings.KeyboardEvents.addListener("keyboardDidShow", e => {
347+ isClosed = false;
348+ lastState = e;
349+});
350 const dismiss = async options => {
351 const keepFocus = (options === null || options === void 0 ? void 0 : options.keepFocus) ?? false;
352 const animated = (options === null || options === void 0 ? void 0 : options.animated) ?? true;
353diff --git a/lib/module/components/KeyboardChatScrollView/index.js b/lib/module/components/KeyboardChatScrollView/index.js
354index e0c8391..8df802a 100644
355--- a/lib/module/components/KeyboardChatScrollView/index.js
356+++ b/lib/module/components/KeyboardChatScrollView/index.js
357@@ -1,9 +1,9 @@
358 function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
359 import React, { forwardRef, useCallback, useMemo } from "react";
360-import { StyleSheet } from "react-native";
361-import { makeMutable, useAnimatedRef } from "react-native-reanimated";
362+import { Platform, StyleSheet } from "react-native";
363+import { makeMutable, runOnJS, useAnimatedRef } from "react-native-reanimated";
364 import Reanimated from "react-native-reanimated";
365-import { useAnimatedStyle, useDerivedValue } from "../../reanimated";
366+import { useAnimatedReaction, useAnimatedStyle, useDerivedValue } from "../../reanimated";
367 import useCombinedRef from "../hooks/useCombinedRef";
368 import ScrollViewWithBottomPadding from "../ScrollViewWithBottomPadding";
369 import { useChatKeyboard } from "./useChatKeyboard";
370@@ -21,9 +21,12 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
371 offset = 0,
372 extraContentPadding = ZERO_CONTENT_PADDING,
373 blankSpace = ZERO_BLANK_SPACE,
374+ adjustedInsetCompensation = 0,
375+ adjustedStartInsetCompensation = 0,
376 applyWorkaroundForContentInsetHitTestBug = false,
377 onLayout: onLayoutProp,
378 onContentSizeChange: onContentSizeChangeProp,
379+ onContentInsetChange,
380 onEndVisible,
381 ...rest
382 }, ref) => {
383@@ -47,6 +50,8 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
384 offset,
385 blankSpace,
386 extraContentPadding,
387+ adjustedInsetCompensation,
388+ adjustedStartInsetCompensation,
389 initialContentOffsetY: (_rest$contentOffset = rest.contentOffset) === null || _rest$contentOffset === void 0 ? void 0 : _rest$contentOffset.y
390 });
391 useExtraContentPadding({
392@@ -54,6 +59,8 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
393 extraContentPadding,
394 keyboardPadding: padding,
395 blankSpace,
396+ adjustedInsetCompensation,
397+ adjustedStartInsetCompensation,
398 scroll,
399 layout,
400 size,
401@@ -84,10 +91,26 @@ const KeyboardChatScrollView = /*#__PURE__*/forwardRef(({
402 // a bug for you, please open an issue.
403 const totalPadding = useDerivedValue(() => Math.min(layout.value.height, Math.max(blankSpace.value, padding.value + extraContentPadding.value)));
405+ // iOS applies the destination contentInset and contentOffset together at
406+ // keyboard-animation start. Keep that native target behavior, but report
407+ // the presentation height so virtualized-list layout follows the keyboard.
408+ const reportedPadding = useDerivedValue(() => Platform.OS === "ios" ? Math.min(layout.value.height, Math.max(blankSpace.value, currentHeight.value + extraContentPadding.value)) : totalPadding.value);
410+ // Mirror the effective bottom padding (keyboard + composer + blank floor)
411+ // to the consumer - a virtualized list needs it in its own scroll math or
412+ // its end/maintain targets point at the under-the-keyboard resting offset.
413+ useAnimatedReaction(() => reportedPadding.value, (current, previous) => {
414+ if (onContentInsetChange && current !== previous) {
415+ runOnJS(onContentInsetChange)({
416+ bottom: current
417+ });
418+ }
419+ }, [onContentInsetChange]);
421 // Scroll indicator inset = keyboard + extraContentPadding (excludes blankSpace).
422 // Apps that render into the unsafe area can supply a negative
423 // scrollIndicatorInsets adjustment at the application layer.
424- const indicatorPadding = useDerivedValue(() => padding.value + extraContentPadding.value);
425+ const indicatorPadding = useDerivedValue(() => padding.value);
426 const onLayout = useCallback(e => {
427 onLayoutInternal(e);
428 onLayoutProp === null || onLayoutProp === void 0 || onLayoutProp(e);
429diff --git a/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js b/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
430index 295e221..2f7b87e 100644
431--- a/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
432+++ b/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js
433@@ -193,7 +193,7 @@ export const clampedScrollTarget = (offsetBeforeScroll, keyboardHeight, contentH
434 * computeIOSContentOffset(100, 300, 1000, 800, false); // 400
435 * ```
436 */
437-export const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentHeight, layoutHeight, inverted, totalPaddingForMaxScroll) => {
438+export const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentHeight, layoutHeight, inverted, totalPaddingForMaxScroll, startInsetCompensation = 0) => {
439 "worklet";
441 const paddingForMax = totalPaddingForMaxScroll !== undefined ? totalPaddingForMaxScroll : keyboardHeight;
442@@ -201,7 +201,8 @@ export const computeIOSContentOffset = (relativeScroll, keyboardHeight, contentH
443 const maxScroll = Math.max(contentHeight - layoutHeight, 0);
444 return Math.max(Math.min(relativeScroll - keyboardHeight, maxScroll), -paddingForMax);
445 }
446- const maxScroll = Math.max(contentHeight - layoutHeight + paddingForMax, 0);
447- return Math.min(Math.max(keyboardHeight + relativeScroll, 0), maxScroll);
448+ const minScroll = -startInsetCompensation;
449+ const maxScroll = Math.max(contentHeight - layoutHeight + paddingForMax, minScroll);
450+ return Math.min(Math.max(keyboardHeight + relativeScroll, minScroll), maxScroll);
451 };
452 //# sourceMappingURL=helpers.js.map
453\ No newline at end of file
454diff --git a/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js b/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
455index 043b973..df5a408 100644
456--- a/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
457+++ b/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js
458@@ -25,7 +25,9 @@ function useChatKeyboard(scrollViewRef, options) {
459 freeze,
460 offset,
461 blankSpace,
462- extraContentPadding
463+ extraContentPadding,
464+ adjustedInsetCompensation,
465+ adjustedStartInsetCompensation
466 } = options;
467 const padding = useSharedValue(0);
468 const currentHeight = useSharedValue(0);
469@@ -52,6 +54,9 @@ function useChatKeyboard(scrollViewRef, options) {
470 targetKeyboardHeight.value = e.height;
471 }
472 const effective = getEffectiveHeight(e.height, targetKeyboardHeight.value, offset);
473+ if (e.duration === 0) {
474+ currentHeight.value = effective;
475+ }
476 const atEnd = isScrollAtEnd(scroll.value, layout.value.height, size.value.height, inverted);
478 // Scale minimum padding absorption by how much of it is visible.
479@@ -60,7 +65,7 @@ function useChatKeyboard(scrollViewRef, options) {
480 const visiblePadding = visibleFraction * blankSpace.value;
481 const minimumPaddingAbsorbed = Math.max(0, visiblePadding - extraContentPadding.value);
482 const scrollEffective = getScrollEffective(effective, minimumPaddingAbsorbed);
483- const actualTotalPadding = Math.max(blankSpace.value, effective + extraContentPadding.value);
484+ const actualTotalPadding = Math.max(blankSpace.value, effective + extraContentPadding.value) + adjustedInsetCompensation;
486 // `onInteractive` owns the native scroll offset. When its final
487 // keyboardWillHide event arrives, consume the marker so this
488@@ -80,8 +85,8 @@ function useChatKeyboard(scrollViewRef, options) {
489 const maxScroll = Math.max(size.value.height - layout.value.height, 0);
490 contentOffsetY.value = Math.max(-actualTotalPadding, Math.min(scroll.value, maxScroll));
491 } else {
492- const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, 0);
493- contentOffsetY.value = Math.max(0, Math.min(scroll.value, maxScroll));
494+ const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, -adjustedStartInsetCompensation);
495+ contentOffsetY.value = Math.max(-adjustedStartInsetCompensation, Math.min(scroll.value, maxScroll));
496 }
497 return;
498 }
499@@ -95,8 +100,8 @@ function useChatKeyboard(scrollViewRef, options) {
500 const maxScroll = Math.max(size.value.height - layout.value.height, 0);
501 contentOffsetY.value = Math.max(-actualTotalPadding, Math.min(scroll.value, maxScroll));
502 } else {
503- const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, 0);
504- contentOffsetY.value = Math.max(0, Math.min(scroll.value, maxScroll));
505+ const maxScroll = Math.max(size.value.height - layout.value.height + actualTotalPadding, -adjustedStartInsetCompensation);
506+ contentOffsetY.value = Math.max(-adjustedStartInsetCompensation, Math.min(scroll.value, maxScroll));
507 }
508 return;
509 }
510@@ -122,17 +127,25 @@ function useChatKeyboard(scrollViewRef, options) {
511 contentOffsetY.value = scroll.value;
512 return;
513 }
514- contentOffsetY.value = computeIOSContentOffset(relativeScroll, scrollEffective, size.value.height, layout.value.height, inverted, actualTotalPadding);
515+ contentOffsetY.value = computeIOSContentOffset(relativeScroll, scrollEffective, size.value.height, layout.value.height, inverted, actualTotalPadding, adjustedStartInsetCompensation);
516 },
517- onInteractive: () => {
518+ onMove: e => {
519 "worklet";
521- isInteractiveDismissal.value = true;
522+ if (freeze.value) {
523+ return;
524+ }
525+ currentHeight.value = getEffectiveHeight(e.height, targetKeyboardHeight.value, offset);
526 },
527- onMove: () => {
528+ onInteractive: e => {
529 "worklet";
531- // iOS doesn't need per-frame updates (contentOffset handles it)
532+ isInteractiveDismissal.value = true;
534+ if (freeze.value) {
535+ return;
536+ }
537+ currentHeight.value = getEffectiveHeight(e.height, targetKeyboardHeight.value, offset);
538 },
539 onEnd: e => {
540 "worklet";
541@@ -141,9 +154,10 @@ function useChatKeyboard(scrollViewRef, options) {
542 return;
543 }
544 const effective = getEffectiveHeight(e.height, targetKeyboardHeight.value, offset);
545+ currentHeight.value = effective;
546 padding.value = effective;
547 }
548- }, [inverted, keyboardLiftBehavior, offset, extraContentPadding]);
549+ }, [inverted, keyboardLiftBehavior, offset, extraContentPadding, adjustedInsetCompensation, adjustedStartInsetCompensation]);
550 return {
551 padding,
552 currentHeight,
553diff --git a/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js b/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js
554index cdca47b..3ea3a7f 100644
555--- a/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js
556+++ b/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js
557@@ -27,6 +27,8 @@ function useExtraContentPadding(options) {
558 extraContentPadding,
559 keyboardPadding,
560 blankSpace,
561+ adjustedInsetCompensation,
562+ adjustedStartInsetCompensation,
563 scroll,
564 layout,
565 size,
566@@ -68,8 +70,8 @@ function useExtraContentPadding(options) {
567 }
569 // Compute effective delta considering blankSpace floor
570- const previousTotal = Math.max(blankSpace.value, keyboardPadding.value + previous);
571- const currentTotal = Math.max(blankSpace.value, keyboardPadding.value + current);
572+ const previousTotal = Math.max(blankSpace.value, keyboardPadding.value + previous) + adjustedInsetCompensation;
573+ const currentTotal = Math.max(blankSpace.value, keyboardPadding.value + current) + adjustedInsetCompensation;
574 const effectiveDelta = currentTotal - previousTotal;
575 if (effectiveDelta === 0) {
576 // blankSpace absorbed the change
577@@ -110,15 +112,16 @@ function useExtraContentPadding(options) {
578 if (inverted) {
579 target = Math.max(base - effectiveDelta, -currentTotal);
580 } else {
581- const maxScroll = Math.max(size.value.height - layout.value.height + currentTotal, 0);
582+ const minScroll = -adjustedStartInsetCompensation;
583+ const maxScroll = Math.max(size.value.height - layout.value.height + currentTotal, minScroll);
585- // Clamp at 0 as well: when the content is shorter than the viewport a
586- // shrinking padding makes `effectiveDelta` negative while `base` is
587- // already 0, so the target would go below the top of the content.
588- target = Math.max(Math.min(base + effectiveDelta, maxScroll), 0);
589+ // Clamp at the top as well: when the content is shorter than the
590+ // viewport a shrinking padding makes `effectiveDelta` negative while
591+ // `base` is already at the top.
592+ target = Math.max(minScroll, Math.min(base + effectiveDelta, maxScroll));
593 }
594 scrollToTarget(target);
595- }, [inverted, keyboardLiftBehavior]);
596+ }, [inverted, keyboardLiftBehavior, adjustedInsetCompensation, adjustedStartInsetCompensation]);
597 }
598 export { useExtraContentPadding };
599 //# sourceMappingURL=index.js.map
600\ No newline at end of file
601diff --git a/lib/module/hooks/useKeyboardState/index.js b/lib/module/hooks/useKeyboardState/index.js
602index 8da7c09fbb398253420d7bfcd9a85abdb981065b..31b1ff4370d8328a0569e559e3bbfa4b201f5a9d 100644
603--- a/lib/module/hooks/useKeyboardState/index.js
604+++ b/lib/module/hooks/useKeyboardState/index.js
605@@ -1,7 +1,7 @@
606 import { useEffect, useState } from "react";
607 import { KeyboardEvents } from "../../bindings";
608 import { KeyboardController } from "../../module";
609-const EVENTS = ["keyboardWillShow", "keyboardDidHide"];
610+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"];
611 const getLatestState = () => ({
612 ...KeyboardController.state(),
613 isVisible: KeyboardController.isVisible()
614diff --git a/lib/module/module.js b/lib/module/module.js
615index 01aad2effee498a8daec55e1d4644a5fbc723765..1140b706265d6c4295581c96b82b27bbf9e6d020 100644
616--- a/lib/module/module.js
617+++ b/lib/module/module.js
618@@ -16,6 +16,12 @@ KeyboardEvents.addListener("keyboardWillShow", e => {
619 isClosed = false;
620 lastState = e;
621 });
622+// Android re-syncs an IME inset that changes without an animation with keyboardDidShow
623+// alone. Drop with kirillzyusko/react-native-keyboard-controller#1698.
624+KeyboardEvents.addListener("keyboardDidShow", e => {
625+ isClosed = false;
626+ lastState = e;
627+});
628 const dismiss = async options => {
629 const keepFocus = (options === null || options === void 0 ? void 0 : options.keepFocus) ?? false;
630 const animated = (options === null || options === void 0 ? void 0 : options.animated) ?? true;
631diff --git a/lib/typescript/components/KeyboardChatScrollView/types.d.ts b/lib/typescript/components/KeyboardChatScrollView/types.d.ts
632index eba1514..6597d80 100644
633--- a/lib/typescript/components/KeyboardChatScrollView/types.d.ts
634+++ b/lib/typescript/components/KeyboardChatScrollView/types.d.ts
635@@ -88,6 +88,10 @@ export type KeyboardChatScrollViewProps = {
636 * Default is `undefined` (equivalent to `0` — no minimum floor).
637 */
638 blankSpace?: SharedValue<number>;
639+ /** Extra bottom inset UIKit adds beyond the raw contentInset (safe area). Offset math only. */
640+ adjustedInsetCompensation?: number;
641+ /** Leading inset UIKit adds outside raw contentInset. Offset math only. */
642+ adjustedStartInsetCompensation?: number;
643 /**
644 * Fires whenever the effective content inset changes — the static `contentInset`
645 * prop combined with the dynamic keyboard-driven padding.
646diff --git a/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts b/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts
647index 2b51cc4..3acec1f 100644
648--- a/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts
649+++ b/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts
650@@ -129,4 +129,4 @@ export declare const clampedScrollTarget: (offsetBeforeScroll: number, keyboardH
651 * computeIOSContentOffset(100, 300, 1000, 800, false); // 400
652 * ```
653 */
654-export declare const computeIOSContentOffset: (relativeScroll: number, keyboardHeight: number, contentHeight: number, layoutHeight: number, inverted: boolean, totalPaddingForMaxScroll?: number) => number;
655+export declare const computeIOSContentOffset: (relativeScroll: number, keyboardHeight: number, contentHeight: number, layoutHeight: number, inverted: boolean, totalPaddingForMaxScroll?: number, startInsetCompensation?: number) => number;
656diff --git a/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts b/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts
657index 8d358bc..911f3d9 100644
658--- a/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts
659+++ b/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts
660@@ -11,6 +11,10 @@ type UseChatKeyboardOptions = {
661 blankSpace: SharedValue<number>;
662 /** Extra content padding shared value — needed on iOS to correctly clamp contentOffset. */
663 extraContentPadding: SharedValue<number>;
664+ /** Safe-area extra beyond raw contentInset. Offset math only. */
665+ adjustedInsetCompensation: number;
666+ /** Leading inset UIKit adds beyond the raw contentInset. Offset math only. */
667+ adjustedStartInsetCompensation: number;
668 };
669 type UseChatKeyboardReturn = {
670 /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom/contentInsetTop on Android. */
671diff --git a/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts b/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts
672index ec73f70..45b3874 100644
673--- a/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts
674+++ b/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts
675@@ -8,6 +8,10 @@ type UseExtraContentPaddingOptions = {
676 keyboardPadding: SharedValue<number>;
677 /** Minimum inset floor — used to absorb keyboard and extraContentPadding changes. */
678 blankSpace: SharedValue<number>;
679+ /** Safe-area extra beyond raw contentInset. Offset math only. */
680+ adjustedInsetCompensation: number;
681+ /** Leading inset UIKit adds beyond raw contentInset. Offset math only. */
682+ adjustedStartInsetCompensation: number;
683 /** Current vertical scroll offset. */
684 scroll: SharedValue<number>;
685 /** Visible viewport dimensions. */
686diff --git a/src/components/KeyboardChatScrollView/index.tsx b/src/components/KeyboardChatScrollView/index.tsx
687index 935bc71..d411dc4 100644
688--- a/src/components/KeyboardChatScrollView/index.tsx
689+++ b/src/components/KeyboardChatScrollView/index.tsx
690@@ -1,9 +1,13 @@
691 import React, { forwardRef, useCallback, useMemo } from "react";
692-import { StyleSheet } from "react-native";
693-import { makeMutable, useAnimatedRef } from "react-native-reanimated";
694+import { Platform, StyleSheet } from "react-native";
695+import { makeMutable, runOnJS, useAnimatedRef } from "react-native-reanimated";
696 import Reanimated from "react-native-reanimated";
698-import { useAnimatedStyle, useDerivedValue } from "../../reanimated";
699+import {
700+ useAnimatedReaction,
701+ useAnimatedStyle,
702+ useDerivedValue,
703+} from "../../reanimated";
704 import useCombinedRef from "../hooks/useCombinedRef";
705 import ScrollViewWithBottomPadding from "../ScrollViewWithBottomPadding";
707@@ -35,9 +39,12 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
708 offset = 0,
709 extraContentPadding = ZERO_CONTENT_PADDING,
710 blankSpace = ZERO_BLANK_SPACE,
711+ adjustedInsetCompensation = 0,
712+ adjustedStartInsetCompensation = 0,
713 applyWorkaroundForContentInsetHitTestBug = false,
714 onLayout: onLayoutProp,
715 onContentSizeChange: onContentSizeChangeProp,
716+ onContentInsetChange,
717 onEndVisible,
718 ...rest
719 },
720@@ -64,6 +71,8 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
721 offset,
722 blankSpace,
723 extraContentPadding,
724+ adjustedInsetCompensation,
725+ adjustedStartInsetCompensation,
726 initialContentOffsetY: rest.contentOffset?.y,
727 });
729@@ -72,6 +81,8 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
730 extraContentPadding,
731 keyboardPadding: padding,
732 blankSpace,
733+ adjustedInsetCompensation,
734+ adjustedStartInsetCompensation,
735 scroll,
736 layout,
737 size,
738@@ -109,13 +120,40 @@ const KeyboardChatScrollView: React.ForwardRefExoticComponent<
739 ),
740 );
742- // Scroll indicator inset = keyboard + extraContentPadding (excludes blankSpace).
743- // Apps that render into the unsafe area can supply a negative
744- // scrollIndicatorInsets adjustment at the application layer.
745- const indicatorPadding = useDerivedValue(
746- () => padding.value + extraContentPadding.value,
747+ // iOS applies the destination contentInset and contentOffset together at
748+ // keyboard-animation start. Keep that native target behavior, but report
749+ // the presentation height so virtualized-list layout follows the keyboard.
750+ const reportedPadding = useDerivedValue(() =>
751+ Platform.OS === "ios"
752+ ? Math.min(
753+ layout.value.height,
754+ Math.max(
755+ blankSpace.value,
756+ currentHeight.value + extraContentPadding.value,
757+ ),
758+ )
759+ : totalPadding.value,
760 );
762+ // Mirror the effective bottom padding (keyboard + composer + blank floor)
763+ // to the consumer — a virtualized list needs it in its own scroll math or
764+ // its end/maintain targets point at the under-the-keyboard resting offset.
765+ useAnimatedReaction(
766+ () => reportedPadding.value,
767+ (current, previous) => {
768+ if (onContentInsetChange && current !== previous) {
769+ runOnJS(onContentInsetChange)({ bottom: current });
770+ }
771+ },
772+ [onContentInsetChange],
773+ );
775+ // Scroll indicator inset = keyboard only (excludes extraContentPadding and
776+ // blankSpace): with a floating composer the indicator track should run the
777+ // full height of the scroll view, behind the composer, like iOS Messages.
778+ // The keyboard still lifts it so it never disappears under the keyboard.
779+ const indicatorPadding = useDerivedValue(() => padding.value);
781 const onLayout = useCallback(
782 (e: LayoutChangeEvent) => {
783 onLayoutInternal(e);
784diff --git a/src/components/KeyboardChatScrollView/types.ts b/src/components/KeyboardChatScrollView/types.ts
785index b7c98c8..e1012a8 100644
786--- a/src/components/KeyboardChatScrollView/types.ts
787+++ b/src/components/KeyboardChatScrollView/types.ts
788@@ -93,6 +93,17 @@ export type KeyboardChatScrollViewProps = {
789 * Default is `undefined` (equivalent to `0` — no minimum floor).
790 */
791 blankSpace?: SharedValue<number>;
792+ /**
793+ * Extra bottom inset UIKit adds on top of the raw `contentInset` this
794+ * component writes (e.g. the home-indicator safe area under
795+ * `contentInsetAdjustmentBehavior="automatic"`). Used ONLY in scroll-offset
796+ * math (max scroll / end pinning) — never written into `contentInset`.
797+ *
798+ * Default is `0`.
799+ */
800+ adjustedInsetCompensation?: number;
801+ /** Leading inset UIKit adds outside raw contentInset. Offset math only. */
802+ adjustedStartInsetCompensation?: number;
803 /**
804 * Fires whenever the effective content inset changes — the static `contentInset`
805 * prop combined with the dynamic keyboard-driven padding.
806diff --git a/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts b/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts
807index 37eacd1..3d77ab2 100644
808--- a/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts
809+++ b/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts
810@@ -245,6 +245,7 @@ export const computeIOSContentOffset = (
811 layoutHeight: number,
812 inverted: boolean,
813 totalPaddingForMaxScroll?: number,
814+ startInsetCompensation: number = 0,
815 ): number => {
816 "worklet";
818@@ -262,7 +263,14 @@ export const computeIOSContentOffset = (
819 );
820 }
822- const maxScroll = Math.max(contentHeight - layoutHeight + paddingForMax, 0);
823+ const minScroll = -startInsetCompensation;
824+ const maxScroll = Math.max(
825+ contentHeight - layoutHeight + paddingForMax,
826+ minScroll,
827+ );
829- return Math.min(Math.max(keyboardHeight + relativeScroll, 0), maxScroll);
830+ return Math.min(
831+ Math.max(keyboardHeight + relativeScroll, minScroll),
832+ maxScroll,
833+ );
834 };
835diff --git a/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts b/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts
836index 1ae9b81..208505b 100644
837--- a/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts
838+++ b/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts
839@@ -43,6 +43,8 @@ function useChatKeyboard(
840 offset,
841 blankSpace,
842 extraContentPadding,
843+ adjustedInsetCompensation,
844+ adjustedStartInsetCompensation,
845 } = options;
847 const padding = useSharedValue(0);
848@@ -80,6 +82,10 @@ function useChatKeyboard(
849 offset,
850 );
852+ if (e.duration === 0) {
853+ currentHeight.value = effective;
854+ }
856 const atEnd = isScrollAtEnd(
857 scroll.value,
858 layout.value.height,
859@@ -105,10 +111,12 @@ function useChatKeyboard(
860 effective,
861 minimumPaddingAbsorbed,
862 );
863- const actualTotalPadding = Math.max(
864- blankSpace.value,
865- effective + extraContentPadding.value,
866- );
867+ // UIKit adds adjustedInsetCompensation (safe area) on top of the raw
868+ // inset; include it here so end/max-scroll targets match the real
869+ // resting offsets.
870+ const actualTotalPadding =
871+ Math.max(blankSpace.value, effective + extraContentPadding.value) +
872+ adjustedInsetCompensation;
874 // `onInteractive` owns the native scroll offset. When its final
875 // keyboardWillHide event arrives, consume the marker so this
876@@ -142,11 +150,11 @@ function useChatKeyboard(
877 } else {
878 const maxScroll = Math.max(
879 size.value.height - layout.value.height + actualTotalPadding,
880- 0,
881+ -adjustedStartInsetCompensation,
882 );
884 contentOffsetY.value = Math.max(
885- 0,
886+ -adjustedStartInsetCompensation,
887 Math.min(scroll.value, maxScroll),
888 );
889 }
890@@ -177,11 +185,11 @@ function useChatKeyboard(
891 } else {
892 const maxScroll = Math.max(
893 size.value.height - layout.value.height + actualTotalPadding,
894- 0,
895+ -adjustedStartInsetCompensation,
896 );
898 contentOffsetY.value = Math.max(
899- 0,
900+ -adjustedStartInsetCompensation,
901 Math.min(scroll.value, maxScroll),
902 );
903 }
904@@ -231,17 +239,36 @@ function useChatKeyboard(
905 layout.value.height,
906 inverted,
907 actualTotalPadding,
908+ adjustedStartInsetCompensation,
909 );
910 },
911- onInteractive: () => {
912+ onMove: (e) => {
913 "worklet";
915- isInteractiveDismissal.value = true;
916+ if (freeze.value) {
917+ return;
918+ }
920+ currentHeight.value = getEffectiveHeight(
921+ e.height,
922+ targetKeyboardHeight.value,
923+ offset,
924+ );
925 },
926- onMove: () => {
927+ onInteractive: (e) => {
928 "worklet";
930- // iOS doesn't need per-frame updates (contentOffset handles it)
931+ isInteractiveDismissal.value = true;
933+ if (freeze.value) {
934+ return;
935+ }
937+ currentHeight.value = getEffectiveHeight(
938+ e.height,
939+ targetKeyboardHeight.value,
940+ offset,
941+ );
942 },
943 onEnd: (e) => {
944 "worklet";
945@@ -256,10 +283,18 @@ function useChatKeyboard(
946 offset,
947 );
949+ currentHeight.value = effective;
950 padding.value = effective;
951 },
952 },
953- [inverted, keyboardLiftBehavior, offset, extraContentPadding],
954+ [
955+ inverted,
956+ keyboardLiftBehavior,
957+ offset,
958+ extraContentPadding,
959+ adjustedInsetCompensation,
960+ adjustedStartInsetCompensation,
961+ ],
962 );
964 return {
965diff --git a/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts b/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts
966index f89b7c8..02e0e19 100644
967--- a/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts
968+++ b/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts
969@@ -13,6 +13,10 @@ type UseChatKeyboardOptions = {
970 blankSpace: SharedValue<number>;
971 /** Extra content padding shared value — needed on iOS to correctly clamp contentOffset. */
972 extraContentPadding: SharedValue<number>;
973+ /** Extra bottom inset UIKit adds beyond the raw contentInset (safe area). Offset math only. */
974+ adjustedInsetCompensation: number;
975+ /** Leading inset UIKit adds beyond the raw contentInset. Offset math only. */
976+ adjustedStartInsetCompensation: number;
977 };
979 type UseChatKeyboardReturn = {
980diff --git a/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts b/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts
981index 99cc6c6..d883e76 100644
982--- a/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts
983+++ b/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts
984@@ -18,6 +18,10 @@ type UseExtraContentPaddingOptions = {
985 keyboardPadding: SharedValue<number>;
986 /** Minimum inset floor — used to absorb keyboard and extraContentPadding changes. */
987 blankSpace: SharedValue<number>;
988+ /** Extra bottom inset UIKit adds beyond the raw contentInset (safe area). Offset math only. */
989+ adjustedInsetCompensation: number;
990+ /** Leading inset UIKit adds beyond raw contentInset. Offset math only. */
991+ adjustedStartInsetCompensation: number;
992 /** Current vertical scroll offset. */
993 scroll: SharedValue<number>;
994 /** Visible viewport dimensions. */
995@@ -53,6 +57,8 @@ function useExtraContentPadding(options: UseExtraContentPaddingOptions): void {
996 extraContentPadding,
997 keyboardPadding,
998 blankSpace,
999+ adjustedInsetCompensation,
1000+ adjustedStartInsetCompensation,
1001 scroll,
1002 layout,
1003 size,
1004@@ -104,14 +110,12 @@ function useExtraContentPadding(options: UseExtraContentPaddingOptions): void {
1007 // Compute effective delta considering blankSpace floor
1008- const previousTotal = Math.max(
1009- blankSpace.value,
1010- keyboardPadding.value + previous,
1011- );
1012- const currentTotal = Math.max(
1013- blankSpace.value,
1014- keyboardPadding.value + current,
1015- );
1016+ const previousTotal =
1017+ Math.max(blankSpace.value, keyboardPadding.value + previous) +
1018+ adjustedInsetCompensation;
1019+ const currentTotal =
1020+ Math.max(blankSpace.value, keyboardPadding.value + current) +
1021+ adjustedInsetCompensation;
1022 const effectiveDelta = currentTotal - previousTotal;
1024 if (effectiveDelta === 0) {
1025@@ -170,20 +174,26 @@ function useExtraContentPadding(options: UseExtraContentPaddingOptions): void {
1026 if (inverted) {
1027 target = Math.max(base - effectiveDelta, -currentTotal);
1028 } else {
1029+ const minScroll = -adjustedStartInsetCompensation;
1030 const maxScroll = Math.max(
1031 size.value.height - layout.value.height + currentTotal,
1032- 0,
1033+ minScroll,
1034 );
1036- // Clamp at 0 as well: when the content is shorter than the viewport a
1037- // shrinking padding makes `effectiveDelta` negative while `base` is
1038- // already 0, so the target would go below the top of the content.
1039- target = Math.max(Math.min(base + effectiveDelta, maxScroll), 0);
1040+ // Clamp at the top as well: when the content is shorter than the
1041+ // viewport a shrinking padding makes `effectiveDelta` negative while
1042+ // `base` is already at the top.
1043+ target = Math.max(minScroll, Math.min(base + effectiveDelta, maxScroll));
1046 scrollToTarget(target);
1047 },
1048- [inverted, keyboardLiftBehavior],
1049+ [
1050+ inverted,
1051+ keyboardLiftBehavior,
1052+ adjustedInsetCompensation,
1053+ adjustedStartInsetCompensation,
1054+ ],
1055 );
1058diff --git a/src/hooks/useKeyboardState/index.ts b/src/hooks/useKeyboardState/index.ts
1059index e5fe38dd8e7b8370bfb575296259933094857ca5..d0b98f60a6d7ad7f72ebd70b22e1ce6b7fb56874 100644
1060--- a/src/hooks/useKeyboardState/index.ts
1061+++ b/src/hooks/useKeyboardState/index.ts
1062@@ -5,7 +5,7 @@ import { KeyboardController } from "../../module";
1064 import type { IKeyboardState } from "../../types";
1066-const EVENTS = ["keyboardWillShow", "keyboardDidHide"] as const;
1067+const EVENTS = ["keyboardWillShow", "keyboardDidShow", "keyboardDidHide"] as const;
1069 const getLatestState = () => ({
1070 ...KeyboardController.state(),
1071diff --git a/src/module.ts b/src/module.ts
1072index f74941914c9ecebbd0a6c2ba55c5436378de79d4..b7223cff162d18be11f8de248a7bb8f32e694658 100644
1073--- a/src/module.ts
1074+++ b/src/module.ts
1075@@ -26,6 +26,13 @@ KeyboardEvents.addListener("keyboardWillShow", (e) => {
1076 lastState = e;
1077 });
1079+// Android re-syncs an IME inset that changes without an animation with keyboardDidShow
1080+// alone. Drop with kirillzyusko/react-native-keyboard-controller#1698.
1081+KeyboardEvents.addListener("keyboardDidShow", (e) => {
1082+ isClosed = false;
1083+ lastState = e;
1084+});
1086 const dismiss = async (options?: Partial<DismissOptions>): Promise<void> => {
1087 const keepFocus = options?.keepFocus ?? false;
1088 const animated = options?.animated ?? true;