react-native-keyboard-controller 1.21.0-beta.2 → 1.21.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/android/src/fabric/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +7 -0
  2. package/android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt +28 -1
  3. package/android/src/paper/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +8 -0
  4. package/ios/animations/KeyboardAnimation.swift +2 -2
  5. package/ios/animations/SpringAnimation.swift +1 -1
  6. package/ios/animations/TimingAnimation.swift +1 -3
  7. package/ios/delegates/KCTextInputCompositeDelegate.swift +2 -2
  8. package/ios/extensions/CGFloat.swift +1 -3
  9. package/ios/interactive/KeyboardAreaExtender.swift +2 -1
  10. package/ios/observers/FocusedInputObserver.swift +4 -2
  11. package/ios/observers/movement/KeyboardTrackingView.swift +4 -1
  12. package/ios/observers/movement/observer/KeyboardMovementObserver+Interactive.swift +2 -0
  13. package/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift +30 -7
  14. package/ios/observers/movement/observer/KeyboardMovementObserver.swift +2 -48
  15. package/ios/protocols/TextInput.swift +1 -1
  16. package/ios/swizzling/UIResponderSwizzle.swift +2 -4
  17. package/ios/traversal/FocusedInputHolder.swift +3 -3
  18. package/ios/traversal/KeyboardView.swift +1 -1
  19. package/ios/traversal/ViewHierarchyNavigator.swift +2 -2
  20. package/ios/views/KeyboardControllerViewManager.swift +5 -5
  21. package/jest/index.js +1 -3
  22. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +43 -11
  23. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  24. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  25. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/index.js +37 -12
  26. package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
  27. package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
  28. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +35 -1
  29. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  30. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +121 -0
  31. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  32. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +205 -0
  33. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  34. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
  35. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  36. package/lib/commonjs/components/KeyboardStickyView/index.js +3 -1
  37. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  38. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +18 -9
  39. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  40. package/lib/commonjs/components/hooks/useScrollState.js +20 -1
  41. package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
  42. package/lib/commonjs/components/index.js +7 -7
  43. package/lib/commonjs/components/index.js.map +1 -1
  44. package/lib/commonjs/index.js +7 -7
  45. package/lib/commonjs/index.js.map +1 -1
  46. package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  47. package/lib/commonjs/types/views.js.map +1 -1
  48. package/lib/module/components/KeyboardAwareScrollView/index.js +43 -11
  49. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  50. package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  51. package/lib/module/components/KeyboardChatScrollView/index.js +73 -0
  52. package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
  53. package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
  54. package/lib/module/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +34 -1
  55. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  56. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +115 -0
  57. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  58. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +199 -0
  59. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  60. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
  61. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  62. package/lib/module/components/KeyboardStickyView/index.js +3 -1
  63. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  64. package/lib/module/components/ScrollViewWithBottomPadding/index.js +19 -10
  65. package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  66. package/lib/module/components/hooks/useScrollState.js +21 -2
  67. package/lib/module/components/hooks/useScrollState.js.map +1 -1
  68. package/lib/module/components/index.js +1 -1
  69. package/lib/module/components/index.js.map +1 -1
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/index.js.map +1 -1
  72. package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  73. package/lib/module/types/views.js.map +1 -1
  74. package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
  75. package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +12 -0
  76. package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/types.d.ts +5 -6
  77. package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.d.ts +23 -3
  78. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +21 -0
  79. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
  80. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +22 -0
  81. package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +2 -4
  82. package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
  83. package/lib/typescript/components/index.d.ts +2 -2
  84. package/lib/typescript/index.d.ts +2 -2
  85. package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +1 -0
  86. package/lib/typescript/types/views.d.ts +2 -0
  87. package/package.json +1 -1
  88. package/src/components/KeyboardAwareScrollView/index.tsx +53 -10
  89. package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
  90. package/src/components/KeyboardChatScrollView/index.tsx +106 -0
  91. package/src/components/{ChatKit → KeyboardChatScrollView}/types.ts +5 -6
  92. package/src/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.ts +46 -1
  93. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +180 -0
  94. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +300 -0
  95. package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +30 -0
  96. package/src/components/KeyboardStickyView/index.tsx +4 -3
  97. package/src/components/ScrollViewWithBottomPadding/index.tsx +22 -25
  98. package/src/components/hooks/useScrollState.ts +24 -2
  99. package/src/components/index.ts +2 -2
  100. package/src/index.ts +2 -2
  101. package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +1 -0
  102. package/src/types/views.ts +2 -0
  103. package/lib/commonjs/components/ChatKit/TODO.md +0 -20
  104. package/lib/commonjs/components/ChatKit/index.js.map +0 -1
  105. package/lib/commonjs/components/ChatKit/types.js.map +0 -1
  106. package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  107. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js +0 -147
  108. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  109. package/lib/module/components/ChatKit/TODO.md +0 -20
  110. package/lib/module/components/ChatKit/index.js +0 -48
  111. package/lib/module/components/ChatKit/index.js.map +0 -1
  112. package/lib/module/components/ChatKit/types.js.map +0 -1
  113. package/lib/module/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  114. package/lib/module/components/ChatKit/useChatKeyboard/index.js +0 -141
  115. package/lib/module/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  116. package/lib/typescript/components/ChatKit/hooks.d.ts +0 -2
  117. package/lib/typescript/components/ChatKit/index.d.ts +0 -14
  118. package/lib/typescript/components/ChatKit/useChatKeyboard/index.d.ts +0 -36
  119. package/src/components/ChatKit/TODO.md +0 -20
  120. package/src/components/ChatKit/hooks.ts +0 -2
  121. package/src/components/ChatKit/index.tsx +0 -63
  122. package/src/components/ChatKit/useChatKeyboard/index.ts +0 -228
  123. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  124. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
  125. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  126. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
@@ -1,147 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useChatKeyboard = useChatKeyboard;
7
- var _reactNative = require("react-native");
8
- var _reactNativeReanimated = require("react-native-reanimated");
9
- var _hooks = require("../../../hooks");
10
- var _useScrollState = _interopRequireDefault(require("../../hooks/useScrollState"));
11
- var _helpers = require("./helpers");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- const OS = _reactNative.Platform.OS;
14
- /**
15
- * Hook that manages keyboard-driven scrolling for chat-style scroll views.
16
- * Calculates padding (extra scrollable space) and content shift values,
17
- * using the optimal strategy per platform.
18
- *
19
- * @param scrollViewRef - Animated ref to the scroll view.
20
- * @param options - Configuration for inverted and keyboardLiftBehavior.
21
- * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).
22
- * @example
23
- * ```tsx
24
- * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {
25
- * inverted: false,
26
- * keyboardLiftBehavior: "always",
27
- * });
28
- * ```
29
- */
30
- function useChatKeyboard(scrollViewRef, options) {
31
- const {
32
- inverted,
33
- keyboardLiftBehavior,
34
- freeze,
35
- offset
36
- } = options;
37
- const padding = (0, _reactNativeReanimated.useSharedValue)(0);
38
- const contentOffsetY = (0, _reactNativeReanimated.useSharedValue)(0);
39
- const containerTranslateY = (0, _reactNativeReanimated.useSharedValue)(0);
40
- const offsetBeforeScroll = (0, _reactNativeReanimated.useSharedValue)(0);
41
- const targetKeyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
42
- const {
43
- layout,
44
- size,
45
- offset: scroll
46
- } = (0, _useScrollState.default)(scrollViewRef);
47
- const getEffectiveHeight = height => {
48
- "worklet";
49
-
50
- if (offset === 0 || targetKeyboardHeight.value === 0) {
51
- return height;
52
- }
53
- return (0, _reactNativeReanimated.interpolate)(height, [0, targetKeyboardHeight.value], [0, Math.max(targetKeyboardHeight.value - offset, 0)]);
54
- };
55
- (0, _hooks.useKeyboardHandler)({
56
- onStart: e => {
57
- "worklet";
58
-
59
- if (freeze) {
60
- return;
61
- }
62
- if (e.height > 0) {
63
- // eslint-disable-next-line react-compiler/react-compiler
64
- targetKeyboardHeight.value = e.height;
65
- }
66
- const effective = getEffectiveHeight(e.height);
67
- const atEnd = (0, _helpers.isScrollAtEnd)(scroll.value, layout.value.height, size.value.height);
68
- if (OS === "ios") {
69
- // iOS: set padding + contentOffset once in onStart
70
- const relativeScroll = inverted ? scroll.value + padding.value : scroll.value - padding.value;
71
- padding.value = effective;
72
- if (!(0, _helpers.shouldShiftContent)(keyboardLiftBehavior, atEnd)) {
73
- return;
74
- }
75
- if (keyboardLiftBehavior === "persistent" && effective < padding.value) {
76
- return;
77
- }
78
- contentOffsetY.value = (0, _helpers.computeIOSContentOffset)(relativeScroll, effective, size.value.height, layout.value.height, inverted);
79
- } else if (e.height > 0) {
80
- // Android: keyboard opening — set padding + capture scroll position
81
- padding.value = effective;
82
- offsetBeforeScroll.value = scroll.value;
83
- if (keyboardLiftBehavior === "whenAtEnd" && !atEnd) {
84
- // Sentinel: don't scroll in onMove
85
- offsetBeforeScroll.value = -1;
86
- }
87
- } else {
88
- // Android: keyboard closing — re-capture from current position
89
- // so onMove smoothly scrolls back from where the user is now
90
- offsetBeforeScroll.value = scroll.value - padding.value;
91
- }
92
- },
93
- onMove: e => {
94
- "worklet";
95
-
96
- if (freeze) {
97
- return;
98
- }
99
-
100
- // iOS doesn't need per-frame updates (contentOffset handles it)
101
- if (OS === "ios") {
102
- return;
103
- }
104
- if (!(0, _helpers.shouldShiftContent)(keyboardLiftBehavior, true)) {
105
- return;
106
- }
107
-
108
- // "whenAtEnd" sentinel check
109
- if (offsetBeforeScroll.value === -1) {
110
- return;
111
- }
112
- const effective = getEffectiveHeight(e.height);
113
- if (inverted) {
114
- // Android inverted: translateY on container
115
- if (keyboardLiftBehavior === "persistent" && effective < Math.abs(containerTranslateY.value)) {
116
- return;
117
- }
118
- containerTranslateY.value = -effective;
119
- } else {
120
- // Android non-inverted: scrollTo per-frame
121
- if (keyboardLiftBehavior === "persistent" && effective < scroll.value - offsetBeforeScroll.value) {
122
- return;
123
- }
124
- const target = (0, _helpers.clampedScrollTarget)(offsetBeforeScroll.value, effective, size.value.height, layout.value.height);
125
- (0, _reactNativeReanimated.scrollTo)(scrollViewRef, 0, target, false);
126
- }
127
- },
128
- onEnd: e => {
129
- "worklet";
130
-
131
- if (freeze) {
132
- return;
133
- }
134
- const effective = getEffectiveHeight(e.height);
135
- padding.value = effective;
136
- if (OS !== "ios" && inverted && e.height === 0 && keyboardLiftBehavior !== "persistent") {
137
- containerTranslateY.value = 0;
138
- }
139
- }
140
- }, [inverted, keyboardLiftBehavior, freeze, offset]);
141
- return {
142
- padding,
143
- contentOffsetY: OS === "ios" ? contentOffsetY : undefined,
144
- containerTranslateY
145
- };
146
- }
147
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_reactNativeReanimated","_hooks","_useScrollState","_interopRequireDefault","_helpers","e","__esModule","default","OS","Platform","useChatKeyboard","scrollViewRef","options","inverted","keyboardLiftBehavior","freeze","offset","padding","useSharedValue","contentOffsetY","containerTranslateY","offsetBeforeScroll","targetKeyboardHeight","layout","size","scroll","useScrollState","getEffectiveHeight","height","value","interpolate","Math","max","useKeyboardHandler","onStart","effective","atEnd","isScrollAtEnd","relativeScroll","shouldShiftContent","computeIOSContentOffset","onMove","abs","target","clampedScrollTarget","scrollTo","onEnd","undefined"],"sources":["index.ts"],"sourcesContent":["import { Platform } from \"react-native\";\nimport { interpolate, scrollTo, useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardHandler } from \"../../../hooks\";\nimport useScrollState from \"../../hooks/useScrollState\";\n\nimport {\n clampedScrollTarget,\n computeIOSContentOffset,\n isScrollAtEnd,\n shouldShiftContent,\n} from \"./helpers\";\n\nimport type { AnimatedRef, SharedValue } from \"react-native-reanimated\";\nimport type Reanimated from \"react-native-reanimated\";\n\nconst OS = Platform.OS;\n\ntype KeyboardLiftBehavior = \"always\" | \"whenAtEnd\" | \"persistent\" | \"never\";\n\ntype UseChatKeyboardOptions = {\n inverted: boolean;\n keyboardLiftBehavior: KeyboardLiftBehavior;\n freeze: boolean;\n offset: number;\n};\n\ntype UseChatKeyboardReturn = {\n /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom on Android. */\n padding: SharedValue<number>;\n /** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */\n contentOffsetY: SharedValue<number> | undefined;\n /** TranslateY for the container wrapper on Android inverted lists. 0 otherwise. */\n containerTranslateY: SharedValue<number>;\n};\n\n/**\n * Hook that manages keyboard-driven scrolling for chat-style scroll views.\n * Calculates padding (extra scrollable space) and content shift values,\n * using the optimal strategy per platform.\n *\n * @param scrollViewRef - Animated ref to the scroll view.\n * @param options - Configuration for inverted and keyboardLiftBehavior.\n * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).\n * @example\n * ```tsx\n * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {\n * inverted: false,\n * keyboardLiftBehavior: \"always\",\n * });\n * ```\n */\nfunction useChatKeyboard(\n scrollViewRef: AnimatedRef<Reanimated.ScrollView>,\n options: UseChatKeyboardOptions,\n): UseChatKeyboardReturn {\n const { inverted, keyboardLiftBehavior, freeze, offset } = options;\n\n const padding = useSharedValue(0);\n const contentOffsetY = useSharedValue(0);\n const containerTranslateY = useSharedValue(0);\n const offsetBeforeScroll = useSharedValue(0);\n const targetKeyboardHeight = useSharedValue(0);\n\n const { layout, size, offset: scroll } = useScrollState(scrollViewRef);\n\n const getEffectiveHeight = (height: number): number => {\n \"worklet\";\n\n if (offset === 0 || targetKeyboardHeight.value === 0) {\n return height;\n }\n\n return interpolate(\n height,\n [0, targetKeyboardHeight.value],\n [0, Math.max(targetKeyboardHeight.value - offset, 0)],\n );\n };\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n targetKeyboardHeight.value = e.height;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n const atEnd = isScrollAtEnd(\n scroll.value,\n layout.value.height,\n size.value.height,\n );\n\n if (OS === \"ios\") {\n // iOS: set padding + contentOffset once in onStart\n const relativeScroll = inverted\n ? scroll.value + padding.value\n : scroll.value - padding.value;\n\n padding.value = effective;\n\n if (!shouldShiftContent(keyboardLiftBehavior, atEnd)) {\n return;\n }\n\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < padding.value\n ) {\n return;\n }\n\n contentOffsetY.value = computeIOSContentOffset(\n relativeScroll,\n effective,\n size.value.height,\n layout.value.height,\n inverted,\n );\n } else if (e.height > 0) {\n // Android: keyboard opening — set padding + capture scroll position\n padding.value = effective;\n offsetBeforeScroll.value = scroll.value;\n\n if (keyboardLiftBehavior === \"whenAtEnd\" && !atEnd) {\n // Sentinel: don't scroll in onMove\n offsetBeforeScroll.value = -1;\n }\n } else {\n // Android: keyboard closing — re-capture from current position\n // so onMove smoothly scrolls back from where the user is now\n offsetBeforeScroll.value = scroll.value - padding.value;\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n // iOS doesn't need per-frame updates (contentOffset handles it)\n if (OS === \"ios\") {\n return;\n }\n\n if (!shouldShiftContent(keyboardLiftBehavior, true)) {\n return;\n }\n\n // \"whenAtEnd\" sentinel check\n if (offsetBeforeScroll.value === -1) {\n return;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n if (inverted) {\n // Android inverted: translateY on container\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < Math.abs(containerTranslateY.value)\n ) {\n return;\n }\n\n containerTranslateY.value = -effective;\n } else {\n // Android non-inverted: scrollTo per-frame\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < scroll.value - offsetBeforeScroll.value\n ) {\n return;\n }\n\n const target = clampedScrollTarget(\n offsetBeforeScroll.value,\n effective,\n size.value.height,\n layout.value.height,\n );\n\n scrollTo(scrollViewRef, 0, target, false);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n padding.value = effective;\n\n if (\n OS !== \"ios\" &&\n inverted &&\n e.height === 0 &&\n keyboardLiftBehavior !== \"persistent\"\n ) {\n containerTranslateY.value = 0;\n }\n },\n },\n [inverted, keyboardLiftBehavior, freeze, offset],\n );\n\n return {\n padding,\n contentOffsetY: OS === \"ios\" ? contentOffsetY : undefined,\n containerTranslateY,\n };\n}\n\nexport { useChatKeyboard };\nexport type { KeyboardLiftBehavior };\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAA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;MAEA,MAAMoB,SAAS,GAAGR,kBAAkB,CAACtB,CAAC,CAACuB,MAAM,CAAC;MAE9CX,OAAO,CAACY,KAAK,GAAGM,SAAS;MAEzB,IACE3B,EAAE,KAAK,KAAK,IACZK,QAAQ,IACRR,CAAC,CAACuB,MAAM,KAAK,CAAC,IACdd,oBAAoB,KAAK,YAAY,EACrC;QACAM,mBAAmB,CAACS,KAAK,GAAG,CAAC;MAC/B;IACF;EACF,CAAC,EACD,CAAChB,QAAQ,EAAEC,oBAAoB,EAAEC,MAAM,EAAEC,MAAM,CACjD,CAAC;EAED,OAAO;IACLC,OAAO;IACPE,cAAc,EAAEX,EAAE,KAAK,KAAK,GAAGW,cAAc,GAAG4B,SAAS;IACzD3B;EACF,CAAC;AACH","ignoreList":[]}
@@ -1,20 +0,0 @@
1
- # Findings
2
-
3
- 1. We can not translate whole `ScrollView` because interactive dismissal will have double scroll if we move it by `translateY` or content will be truncated if we don't do it (same with external container).
4
- 2. So we need to move only content inside `ScrollView`.
5
- 3. If we use a separate `scrollTo` we still may have a random jump. The only one way is to use `contentOffset` + `padding` on `ScrollView`.
6
- 4. Input must be always in `KeyboardStickyView` because it's always pushing above the keyboard (unlike content, which may stay in place).
7
- 5. Changing `contentOffset` on `ScrollView` will not work. On iOS it works, but on Android sometimes it doesn't scroll to correct position (when you scroll list to the end) and on paper architecture it is flickering.
8
- 6. Next idea is to use `contentInset` on iOS and create custom `ClippingScrollView` on Android (with polyfill `contentInsetBottom` prop).
9
-
10
- ## To Do
11
-
12
- - [x] check how `ClippingScrollView` works in `KeyboardAwareScrollView` on Android (seems to be working well)
13
- - [x] introduce `useCombinedRef` hook in separate PR
14
- - [x] make sure, that style property doesn't affect the behavior with/without `ClippingScrollView` (test on a ScrollView that doesn't tke full screen?) <-- tested by comparing iOS with Android + `ClippingScrollView` (`contentInsetBottom` never override `paddingBottom` from `style`/`contentContainerStyle` even if ScrollView has `maxHeight=150` and we have only 2 inputs limitation + also tested `ScrollView` without height restrictions, in this case `paddingBottom` on `style` is not getting applied (it doesn't have an effect on both iOS/Android), but `contentContainerStyle` + `paddingBottom` works as expected and if I add `contentInsetBottom` to `ClippingScrollView` it doesn't overwrite a padding and increases scrollable area)
15
- - [x] `ClippingScrollView` + `KeyboardAwareScrollView` check by e2e tests (seems to be working, though on Android emulator + e2e tests sometimes when keyboard disappear we still have keyboard space)
16
- - [x] introduce `ClippingScrollView` in separate PR
17
- - [x] create a polyfill-version of ScrollView `that` can add scrollable padding in the bottom of the content? How to wrap custom `ScrollView` with it (cause we may pass one from react-native-gesture-handler)? Should just adjust `contentInset` (scroll management should belong to `KeyboardAwareScrollView`) (ScrollViewWithKeyboardPadding/ScrollViewWithKeyboardSpace)
18
- - [x] use `ClippingScrollView` in `KeyboardAwareScrollView` in separate PR
19
- - [-] introduce `ChatKit`
20
- - [] create issue in reanimated repo about `scrollTo` performance regression
@@ -1,48 +0,0 @@
1
- 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); }
2
- import React, { forwardRef } from "react";
3
- import { useAnimatedRef, useAnimatedStyle } from "react-native-reanimated";
4
- import Reanimated from "react-native-reanimated";
5
- import useCombinedRef from "../hooks/useCombinedRef";
6
- import ScrollViewWithBottomPadding from "../ScrollViewWithBottomPadding";
7
- import { useChatKeyboard } from "./useChatKeyboard";
8
- const ChatScrollView = /*#__PURE__*/forwardRef(({
9
- children,
10
- ScrollViewComponent = Reanimated.ScrollView,
11
- inverted = false,
12
- keyboardLiftBehavior = "always",
13
- freeze = false,
14
- offset = 0,
15
- ...rest
16
- }, ref) => {
17
- const scrollViewRef = useAnimatedRef();
18
- const onRef = useCombinedRef(ref, scrollViewRef);
19
- const {
20
- padding,
21
- contentOffsetY,
22
- containerTranslateY
23
- } = useChatKeyboard(scrollViewRef, {
24
- inverted,
25
- keyboardLiftBehavior,
26
- freeze,
27
- offset
28
- });
29
- const containerStyle = useAnimatedStyle(() => ({
30
- transform: [{
31
- translateY: containerTranslateY.value
32
- }]
33
- }), []);
34
- return /*#__PURE__*/React.createElement(ScrollViewWithBottomPadding, _extends({
35
- ref: onRef
36
- }, rest, {
37
- bottomPadding: padding,
38
- containerStyle: containerStyle,
39
- contentOffsetY: contentOffsetY,
40
- inverted: inverted,
41
- ScrollViewComponent: ScrollViewComponent
42
- }), children);
43
- });
44
- const ChatKit = {
45
- ScrollView: ChatScrollView
46
- };
47
- export default ChatKit;
48
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","forwardRef","useAnimatedRef","useAnimatedStyle","Reanimated","useCombinedRef","ScrollViewWithBottomPadding","useChatKeyboard","ChatScrollView","children","ScrollViewComponent","ScrollView","inverted","keyboardLiftBehavior","freeze","offset","rest","ref","scrollViewRef","onRef","padding","contentOffsetY","containerTranslateY","containerStyle","transform","translateY","value","createElement","_extends","bottomPadding","ChatKit"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\nimport { useAnimatedRef, useAnimatedStyle } from \"react-native-reanimated\";\nimport Reanimated from \"react-native-reanimated\";\n\nimport useCombinedRef from \"../hooks/useCombinedRef\";\nimport ScrollViewWithBottomPadding from \"../ScrollViewWithBottomPadding\";\n\nimport { useChatKeyboard } from \"./useChatKeyboard\";\n\nimport type { ChatKitScrollViewProps } from \"./types\";\n\nconst ChatScrollView = forwardRef<\n Reanimated.ScrollView,\n React.PropsWithChildren<ChatKitScrollViewProps>\n>(\n (\n {\n children,\n ScrollViewComponent = Reanimated.ScrollView,\n inverted = false,\n keyboardLiftBehavior = \"always\",\n freeze = false,\n offset = 0,\n ...rest\n },\n ref,\n ) => {\n const scrollViewRef = useAnimatedRef<Reanimated.ScrollView>();\n const onRef = useCombinedRef(ref, scrollViewRef);\n\n const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(\n scrollViewRef,\n { inverted, keyboardLiftBehavior, freeze, offset },\n );\n\n const containerStyle = useAnimatedStyle(\n () => ({\n transform: [{ translateY: containerTranslateY.value }],\n }),\n [],\n );\n\n return (\n <ScrollViewWithBottomPadding\n ref={onRef}\n {...rest}\n bottomPadding={padding}\n containerStyle={containerStyle}\n contentOffsetY={contentOffsetY}\n inverted={inverted}\n ScrollViewComponent={ScrollViewComponent}\n >\n {children}\n </ScrollViewWithBottomPadding>\n );\n },\n);\n\nconst ChatKit = {\n ScrollView: ChatScrollView,\n};\n\nexport default ChatKit;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,yBAAyB;AAC1E,OAAOC,UAAU,MAAM,yBAAyB;AAEhD,OAAOC,cAAc,MAAM,yBAAyB;AACpD,OAAOC,2BAA2B,MAAM,gCAAgC;AAExE,SAASC,eAAe,QAAQ,mBAAmB;AAInD,MAAMC,cAAc,gBAAGP,UAAU,CAI/B,CACE;EACEQ,QAAQ;EACRC,mBAAmB,GAAGN,UAAU,CAACO,UAAU;EAC3CC,QAAQ,GAAG,KAAK;EAChBC,oBAAoB,GAAG,QAAQ;EAC/BC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAG,CAAC;EACV,GAAGC;AACL,CAAC,EACDC,GAAG,KACA;EACH,MAAMC,aAAa,GAAGhB,cAAc,CAAwB,CAAC;EAC7D,MAAMiB,KAAK,GAAGd,cAAc,CAACY,GAAG,EAAEC,aAAa,CAAC;EAEhD,MAAM;IAAEE,OAAO;IAAEC,cAAc;IAAEC;EAAoB,CAAC,GAAGf,eAAe,CACtEW,aAAa,EACb;IAAEN,QAAQ;IAAEC,oBAAoB;IAAEC,MAAM;IAAEC;EAAO,CACnD,CAAC;EAED,MAAMQ,cAAc,GAAGpB,gBAAgB,CACrC,OAAO;IACLqB,SAAS,EAAE,CAAC;MAAEC,UAAU,EAAEH,mBAAmB,CAACI;IAAM,CAAC;EACvD,CAAC,CAAC,EACF,EACF,CAAC;EAED,oBACE1B,KAAA,CAAA2B,aAAA,CAACrB,2BAA2B,EAAAsB,QAAA;IAC1BX,GAAG,EAAEE;EAAM,GACPH,IAAI;IACRa,aAAa,EAAET,OAAQ;IACvBG,cAAc,EAAEA,cAAe;IAC/BF,cAAc,EAAEA,cAAe;IAC/BT,QAAQ,EAAEA,QAAS;IACnBF,mBAAmB,EAAEA;EAAoB,IAExCD,QAC0B,CAAC;AAElC,CACF,CAAC;AAED,MAAMqB,OAAO,GAAG;EACdnB,UAAU,EAAEH;AACd,CAAC;AAED,eAAesB,OAAO","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { AnimatedScrollViewComponent } from \"../ScrollViewWithBottomPadding\";\nimport type { ScrollViewProps } from \"react-native\";\n\ntype KeyboardLiftBehavior = \"always\" | \"whenAtEnd\" | \"persistent\" | \"never\";\n\nexport type ChatKitScrollViewProps = {\n /** Custom component for `ScrollView`. Default is `ScrollView`. */\n ScrollViewComponent: AnimatedScrollViewComponent;\n /** Whether list are using `inverted` prop. Default is `false`. */\n inverted?: boolean;\n /**\n * The distance (in pixels) between the bottom of the screen and the `ScrollView`.\n * When the keyboard appears, the scroll view will only push content by the effective\n * distance (`keyboardHeight - offset`) instead of the full keyboard height.\n *\n * Useful when the input is not at the very bottom of the screen (e.g., above safe area, above\n * bottom tabs, etc. - in this case offset should be equal to the height of the elements between\n * `ScrollView` and bottom of the screen).\n *\n * Default is `0`.\n */\n offset?: number;\n /**\n * Determines how the chat content should behave when the keyboard appears, specifically whether\n * the scroll view should automatically lift its content to keep it visible above the keyboard.\n *\n * Possible values:\n * - `'always'`: The content always lifts along with the keyboard, ensuring the messages from the bottom part of screen\n * remain visible regardless of the current scroll position. This is the default behavior for most chat applications (used in Telegram).\n * - `'whenAtEnd'`: The content lifts only if the scroll view is at the end (i.e., the last message\n * is visible or near the bottom). This prevents unnecessary adjustments when the user is scrolling\n * through older messages (ChatGPT mobile app behavior).\n * - `'persistent'`: The content always lifts when the keyboard appears (similar to `'always'`), but\n * does not reset (lower) when the keyboard hides. This mimics behaviors where the view remains adjusted\n * after keyboard dismissal to maintain focus on the latest content without shifting back (Claude mobile app behavior).\n * - `'never'`: The content does not lift at all when the keyboard appears. Use this for scenarios\n * when you don't want to disturb user attention with animations (Perplexity mobile app behavior).\n *\n * Default is `'always'`.\n */\n keyboardLiftBehavior?: KeyboardLiftBehavior;\n /**\n * When `true`, freezes all keyboard-driven layout changes (padding, content offset, scroll position).\n * Useful when dismissing the keyboard to open a bottom sheet — prevents visual disruption\n * while the sheet is visible.\n *\n * Default is `false`.\n */\n freeze?: boolean;\n} & ScrollViewProps;\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["AT_END_THRESHOLD","isScrollAtEnd","scrollOffset","layoutHeight","contentHeight","shouldShiftContent","behavior","isAtEnd","clampedScrollTarget","offsetBeforeScroll","keyboardHeight","maxScroll","Math","max","min","computeIOSContentOffset","relativeScroll","inverted"],"sources":["helpers.ts"],"sourcesContent":["type KeyboardLiftBehavior = \"always\" | \"whenAtEnd\" | \"persistent\" | \"never\";\n\nconst AT_END_THRESHOLD = 20;\n\n/**\n * Check whether the scroll view is at the end of its content.\n *\n * @param scrollOffset - Current vertical scroll offset.\n * @param layoutHeight - Visible height of the scroll view.\n * @param contentHeight - Total height of the scrollable content.\n * @returns `true` if the scroll position is within the threshold of the content end.\n * @example\n * ```ts\n * const atEnd = isScrollAtEnd(100, 800, 920); // true (100 + 800 >= 920 - 20)\n * ```\n */\nexport function isScrollAtEnd(\n scrollOffset: number,\n layoutHeight: number,\n contentHeight: number,\n): boolean {\n \"worklet\";\n\n return scrollOffset + layoutHeight >= contentHeight - AT_END_THRESHOLD;\n}\n\n/**\n * Decide whether content should be shifted based on the keyboard lift behavior.\n *\n * @param behavior - The configured keyboard lift behavior.\n * @param isAtEnd - Whether the scroll view is currently at the end.\n * @returns `true` if content should be shifted.\n * @example\n * ```ts\n * shouldShiftContent(\"always\", false); // true\n * shouldShiftContent(\"whenAtEnd\", false); // false\n * ```\n */\nexport function shouldShiftContent(\n behavior: KeyboardLiftBehavior,\n isAtEnd: boolean,\n): boolean {\n \"worklet\";\n\n switch (behavior) {\n case \"always\":\n return true;\n case \"never\":\n return false;\n case \"whenAtEnd\":\n return isAtEnd;\n case \"persistent\":\n return true;\n }\n}\n\n/**\n * Compute the clamped scroll target for non-inverted lists.\n *\n * @param offsetBeforeScroll - Scroll position before keyboard appeared.\n * @param keyboardHeight - Current keyboard height.\n * @param contentHeight - Total height of the scrollable content.\n * @param layoutHeight - Visible height of the scroll view.\n * @returns Clamped scroll target between 0 and maxScroll.\n * @example\n * ```ts\n * clampedScrollTarget(100, 300, 1000, 800); // 400\n * ```\n */\nexport function clampedScrollTarget(\n offsetBeforeScroll: number,\n keyboardHeight: number,\n contentHeight: number,\n layoutHeight: number,\n): number {\n \"worklet\";\n\n const maxScroll = Math.max(contentHeight - layoutHeight + keyboardHeight, 0);\n\n return Math.min(Math.max(offsetBeforeScroll + keyboardHeight, 0), maxScroll);\n}\n\n/**\n * Compute contentOffset.y for iOS lists.\n *\n * @param relativeScroll - Scroll position relative to current inset.\n * @param keyboardHeight - Target keyboard height.\n * @param contentHeight - Total height of the scrollable content.\n * @param layoutHeight - Visible height of the scroll view.\n * @param inverted - Whether the list is inverted.\n * @returns The absolute contentOffset.y to set.\n * @example\n * ```ts\n * computeIOSContentOffset(100, 300, 1000, 800, false); // 400\n * ```\n */\nexport function computeIOSContentOffset(\n relativeScroll: number,\n keyboardHeight: number,\n contentHeight: number,\n layoutHeight: number,\n inverted: boolean,\n): number {\n \"worklet\";\n\n if (inverted) {\n const maxScroll = Math.max(contentHeight - layoutHeight, 0);\n\n return Math.max(\n Math.min(relativeScroll - keyboardHeight, maxScroll),\n -keyboardHeight,\n );\n }\n\n const maxScroll = Math.max(contentHeight - layoutHeight + keyboardHeight, 0);\n\n return Math.min(Math.max(keyboardHeight + relativeScroll, 0), maxScroll);\n}\n"],"mappings":"AAEA,MAAMA,gBAAgB,GAAG,EAAE;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAC3BC,YAAoB,EACpBC,YAAoB,EACpBC,aAAqB,EACZ;EACT,SAAS;;EAET,OAAOF,YAAY,GAAGC,YAAY,IAAIC,aAAa,GAAGJ,gBAAgB;AACxE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,kBAAkBA,CAChCC,QAA8B,EAC9BC,OAAgB,EACP;EACT,SAAS;;EAET,QAAQD,QAAQ;IACd,KAAK,QAAQ;MACX,OAAO,IAAI;IACb,KAAK,OAAO;MACV,OAAO,KAAK;IACd,KAAK,WAAW;MACd,OAAOC,OAAO;IAChB,KAAK,YAAY;MACf,OAAO,IAAI;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CACjCC,kBAA0B,EAC1BC,cAAsB,EACtBN,aAAqB,EACrBD,YAAoB,EACZ;EACR,SAAS;;EAET,MAAMQ,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACT,aAAa,GAAGD,YAAY,GAAGO,cAAc,EAAE,CAAC,CAAC;EAE5E,OAAOE,IAAI,CAACE,GAAG,CAACF,IAAI,CAACC,GAAG,CAACJ,kBAAkB,GAAGC,cAAc,EAAE,CAAC,CAAC,EAAEC,SAAS,CAAC;AAC9E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,uBAAuBA,CACrCC,cAAsB,EACtBN,cAAsB,EACtBN,aAAqB,EACrBD,YAAoB,EACpBc,QAAiB,EACT;EACR,SAAS;;EAET,IAAIA,QAAQ,EAAE;IACZ,MAAMN,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACT,aAAa,GAAGD,YAAY,EAAE,CAAC,CAAC;IAE3D,OAAOS,IAAI,CAACC,GAAG,CACbD,IAAI,CAACE,GAAG,CAACE,cAAc,GAAGN,cAAc,EAAEC,SAAS,CAAC,EACpD,CAACD,cACH,CAAC;EACH;EAEA,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACT,aAAa,GAAGD,YAAY,GAAGO,cAAc,EAAE,CAAC,CAAC;EAE5E,OAAOE,IAAI,CAACE,GAAG,CAACF,IAAI,CAACC,GAAG,CAACH,cAAc,GAAGM,cAAc,EAAE,CAAC,CAAC,EAAEL,SAAS,CAAC;AAC1E","ignoreList":[]}
@@ -1,141 +0,0 @@
1
- import { Platform } from "react-native";
2
- import { interpolate, scrollTo, useSharedValue } from "react-native-reanimated";
3
- import { useKeyboardHandler } from "../../../hooks";
4
- import useScrollState from "../../hooks/useScrollState";
5
- import { clampedScrollTarget, computeIOSContentOffset, isScrollAtEnd, shouldShiftContent } from "./helpers";
6
- const OS = Platform.OS;
7
- /**
8
- * Hook that manages keyboard-driven scrolling for chat-style scroll views.
9
- * Calculates padding (extra scrollable space) and content shift values,
10
- * using the optimal strategy per platform.
11
- *
12
- * @param scrollViewRef - Animated ref to the scroll view.
13
- * @param options - Configuration for inverted and keyboardLiftBehavior.
14
- * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).
15
- * @example
16
- * ```tsx
17
- * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {
18
- * inverted: false,
19
- * keyboardLiftBehavior: "always",
20
- * });
21
- * ```
22
- */
23
- function useChatKeyboard(scrollViewRef, options) {
24
- const {
25
- inverted,
26
- keyboardLiftBehavior,
27
- freeze,
28
- offset
29
- } = options;
30
- const padding = useSharedValue(0);
31
- const contentOffsetY = useSharedValue(0);
32
- const containerTranslateY = useSharedValue(0);
33
- const offsetBeforeScroll = useSharedValue(0);
34
- const targetKeyboardHeight = useSharedValue(0);
35
- const {
36
- layout,
37
- size,
38
- offset: scroll
39
- } = useScrollState(scrollViewRef);
40
- const getEffectiveHeight = height => {
41
- "worklet";
42
-
43
- if (offset === 0 || targetKeyboardHeight.value === 0) {
44
- return height;
45
- }
46
- return interpolate(height, [0, targetKeyboardHeight.value], [0, Math.max(targetKeyboardHeight.value - offset, 0)]);
47
- };
48
- useKeyboardHandler({
49
- onStart: e => {
50
- "worklet";
51
-
52
- if (freeze) {
53
- return;
54
- }
55
- if (e.height > 0) {
56
- // eslint-disable-next-line react-compiler/react-compiler
57
- targetKeyboardHeight.value = e.height;
58
- }
59
- const effective = getEffectiveHeight(e.height);
60
- const atEnd = isScrollAtEnd(scroll.value, layout.value.height, size.value.height);
61
- if (OS === "ios") {
62
- // iOS: set padding + contentOffset once in onStart
63
- const relativeScroll = inverted ? scroll.value + padding.value : scroll.value - padding.value;
64
- padding.value = effective;
65
- if (!shouldShiftContent(keyboardLiftBehavior, atEnd)) {
66
- return;
67
- }
68
- if (keyboardLiftBehavior === "persistent" && effective < padding.value) {
69
- return;
70
- }
71
- contentOffsetY.value = computeIOSContentOffset(relativeScroll, effective, size.value.height, layout.value.height, inverted);
72
- } else if (e.height > 0) {
73
- // Android: keyboard opening — set padding + capture scroll position
74
- padding.value = effective;
75
- offsetBeforeScroll.value = scroll.value;
76
- if (keyboardLiftBehavior === "whenAtEnd" && !atEnd) {
77
- // Sentinel: don't scroll in onMove
78
- offsetBeforeScroll.value = -1;
79
- }
80
- } else {
81
- // Android: keyboard closing — re-capture from current position
82
- // so onMove smoothly scrolls back from where the user is now
83
- offsetBeforeScroll.value = scroll.value - padding.value;
84
- }
85
- },
86
- onMove: e => {
87
- "worklet";
88
-
89
- if (freeze) {
90
- return;
91
- }
92
-
93
- // iOS doesn't need per-frame updates (contentOffset handles it)
94
- if (OS === "ios") {
95
- return;
96
- }
97
- if (!shouldShiftContent(keyboardLiftBehavior, true)) {
98
- return;
99
- }
100
-
101
- // "whenAtEnd" sentinel check
102
- if (offsetBeforeScroll.value === -1) {
103
- return;
104
- }
105
- const effective = getEffectiveHeight(e.height);
106
- if (inverted) {
107
- // Android inverted: translateY on container
108
- if (keyboardLiftBehavior === "persistent" && effective < Math.abs(containerTranslateY.value)) {
109
- return;
110
- }
111
- containerTranslateY.value = -effective;
112
- } else {
113
- // Android non-inverted: scrollTo per-frame
114
- if (keyboardLiftBehavior === "persistent" && effective < scroll.value - offsetBeforeScroll.value) {
115
- return;
116
- }
117
- const target = clampedScrollTarget(offsetBeforeScroll.value, effective, size.value.height, layout.value.height);
118
- scrollTo(scrollViewRef, 0, target, false);
119
- }
120
- },
121
- onEnd: e => {
122
- "worklet";
123
-
124
- if (freeze) {
125
- return;
126
- }
127
- const effective = getEffectiveHeight(e.height);
128
- padding.value = effective;
129
- if (OS !== "ios" && inverted && e.height === 0 && keyboardLiftBehavior !== "persistent") {
130
- containerTranslateY.value = 0;
131
- }
132
- }
133
- }, [inverted, keyboardLiftBehavior, freeze, offset]);
134
- return {
135
- padding,
136
- contentOffsetY: OS === "ios" ? contentOffsetY : undefined,
137
- containerTranslateY
138
- };
139
- }
140
- export { useChatKeyboard };
141
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Platform","interpolate","scrollTo","useSharedValue","useKeyboardHandler","useScrollState","clampedScrollTarget","computeIOSContentOffset","isScrollAtEnd","shouldShiftContent","OS","useChatKeyboard","scrollViewRef","options","inverted","keyboardLiftBehavior","freeze","offset","padding","contentOffsetY","containerTranslateY","offsetBeforeScroll","targetKeyboardHeight","layout","size","scroll","getEffectiveHeight","height","value","Math","max","onStart","e","effective","atEnd","relativeScroll","onMove","abs","target","onEnd","undefined"],"sources":["index.ts"],"sourcesContent":["import { Platform } from \"react-native\";\nimport { interpolate, scrollTo, useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardHandler } from \"../../../hooks\";\nimport useScrollState from \"../../hooks/useScrollState\";\n\nimport {\n clampedScrollTarget,\n computeIOSContentOffset,\n isScrollAtEnd,\n shouldShiftContent,\n} from \"./helpers\";\n\nimport type { AnimatedRef, SharedValue } from \"react-native-reanimated\";\nimport type Reanimated from \"react-native-reanimated\";\n\nconst OS = Platform.OS;\n\ntype KeyboardLiftBehavior = \"always\" | \"whenAtEnd\" | \"persistent\" | \"never\";\n\ntype UseChatKeyboardOptions = {\n inverted: boolean;\n keyboardLiftBehavior: KeyboardLiftBehavior;\n freeze: boolean;\n offset: number;\n};\n\ntype UseChatKeyboardReturn = {\n /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom on Android. */\n padding: SharedValue<number>;\n /** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */\n contentOffsetY: SharedValue<number> | undefined;\n /** TranslateY for the container wrapper on Android inverted lists. 0 otherwise. */\n containerTranslateY: SharedValue<number>;\n};\n\n/**\n * Hook that manages keyboard-driven scrolling for chat-style scroll views.\n * Calculates padding (extra scrollable space) and content shift values,\n * using the optimal strategy per platform.\n *\n * @param scrollViewRef - Animated ref to the scroll view.\n * @param options - Configuration for inverted and keyboardLiftBehavior.\n * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).\n * @example\n * ```tsx\n * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {\n * inverted: false,\n * keyboardLiftBehavior: \"always\",\n * });\n * ```\n */\nfunction useChatKeyboard(\n scrollViewRef: AnimatedRef<Reanimated.ScrollView>,\n options: UseChatKeyboardOptions,\n): UseChatKeyboardReturn {\n const { inverted, keyboardLiftBehavior, freeze, offset } = options;\n\n const padding = useSharedValue(0);\n const contentOffsetY = useSharedValue(0);\n const containerTranslateY = useSharedValue(0);\n const offsetBeforeScroll = useSharedValue(0);\n const targetKeyboardHeight = useSharedValue(0);\n\n const { layout, size, offset: scroll } = useScrollState(scrollViewRef);\n\n const getEffectiveHeight = (height: number): number => {\n \"worklet\";\n\n if (offset === 0 || targetKeyboardHeight.value === 0) {\n return height;\n }\n\n return interpolate(\n height,\n [0, targetKeyboardHeight.value],\n [0, Math.max(targetKeyboardHeight.value - offset, 0)],\n );\n };\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n targetKeyboardHeight.value = e.height;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n const atEnd = isScrollAtEnd(\n scroll.value,\n layout.value.height,\n size.value.height,\n );\n\n if (OS === \"ios\") {\n // iOS: set padding + contentOffset once in onStart\n const relativeScroll = inverted\n ? scroll.value + padding.value\n : scroll.value - padding.value;\n\n padding.value = effective;\n\n if (!shouldShiftContent(keyboardLiftBehavior, atEnd)) {\n return;\n }\n\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < padding.value\n ) {\n return;\n }\n\n contentOffsetY.value = computeIOSContentOffset(\n relativeScroll,\n effective,\n size.value.height,\n layout.value.height,\n inverted,\n );\n } else if (e.height > 0) {\n // Android: keyboard opening — set padding + capture scroll position\n padding.value = effective;\n offsetBeforeScroll.value = scroll.value;\n\n if (keyboardLiftBehavior === \"whenAtEnd\" && !atEnd) {\n // Sentinel: don't scroll in onMove\n offsetBeforeScroll.value = -1;\n }\n } else {\n // Android: keyboard closing — re-capture from current position\n // so onMove smoothly scrolls back from where the user is now\n offsetBeforeScroll.value = scroll.value - padding.value;\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n // iOS doesn't need per-frame updates (contentOffset handles it)\n if (OS === \"ios\") {\n return;\n }\n\n if (!shouldShiftContent(keyboardLiftBehavior, true)) {\n return;\n }\n\n // \"whenAtEnd\" sentinel check\n if (offsetBeforeScroll.value === -1) {\n return;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n if (inverted) {\n // Android inverted: translateY on container\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < Math.abs(containerTranslateY.value)\n ) {\n return;\n }\n\n containerTranslateY.value = -effective;\n } else {\n // Android non-inverted: scrollTo per-frame\n if (\n keyboardLiftBehavior === \"persistent\" &&\n effective < scroll.value - offsetBeforeScroll.value\n ) {\n return;\n }\n\n const target = clampedScrollTarget(\n offsetBeforeScroll.value,\n effective,\n size.value.height,\n layout.value.height,\n );\n\n scrollTo(scrollViewRef, 0, target, false);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n if (freeze) {\n return;\n }\n\n const effective = getEffectiveHeight(e.height);\n\n padding.value = effective;\n\n if (\n OS !== \"ios\" &&\n inverted &&\n e.height === 0 &&\n keyboardLiftBehavior !== \"persistent\"\n ) {\n containerTranslateY.value = 0;\n }\n },\n },\n [inverted, keyboardLiftBehavior, freeze, offset],\n );\n\n return {\n padding,\n contentOffsetY: OS === \"ios\" ? contentOffsetY : undefined,\n containerTranslateY,\n };\n}\n\nexport { useChatKeyboard };\nexport type { KeyboardLiftBehavior };\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,WAAW,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,yBAAyB;AAE/E,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,OAAOC,cAAc,MAAM,4BAA4B;AAEvD,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,aAAa,EACbC,kBAAkB,QACb,WAAW;AAKlB,MAAMC,EAAE,GAAGV,QAAQ,CAACU,EAAE;AAoBtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CACtBC,aAAiD,EACjDC,OAA+B,EACR;EACvB,MAAM;IAAEC,QAAQ;IAAEC,oBAAoB;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGJ,OAAO;EAElE,MAAMK,OAAO,GAAGf,cAAc,CAAC,CAAC,CAAC;EACjC,MAAMgB,cAAc,GAAGhB,cAAc,CAAC,CAAC,CAAC;EACxC,MAAMiB,mBAAmB,GAAGjB,cAAc,CAAC,CAAC,CAAC;EAC7C,MAAMkB,kBAAkB,GAAGlB,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AG,CAACK,SAAS;MACxC,CAAC,MAAM;QACL;QACA,IACElB,oBAAoB,KAAK,YAAY,IACrCkB,SAAS,GAAGR,MAAM,CAACG,KAAK,GAAGP,kBAAkB,CAACO,KAAK,EACnD;UACA;QACF;QAEA,MAAMU,MAAM,GAAGhC,mBAAmB,CAChCe,kBAAkB,CAACO,KAAK,EACxBK,SAAS,EACTT,IAAI,CAACI,KAAK,CAACD,MAAM,EACjBJ,MAAM,CAACK,KAAK,CAACD,MACf,CAAC;QAEDzB,QAAQ,CAACU,aAAa,EAAE,CAAC,EAAE0B,MAAM,EAAE,KAAK,CAAC;MAC3C;IACF,CAAC;IACDC,KAAK,EAAGP,CAAC,IAAK;MACZ,SAAS;;MAET,IAAIhB,MAAM,EAAE;QACV;MACF;MAEA,MAAMiB,SAAS,GAAGP,kBAAkB,CAACM,CAAC,CAACL,MAAM,CAAC;MAE9CT,OAAO,CAACU,KAAK,GAAGK,SAAS;MAEzB,IACEvB,EAAE,KAAK,KAAK,IACZI,QAAQ,IACRkB,CAAC,CAACL,MAAM,KAAK,CAAC,IACdZ,oBAAoB,KAAK,YAAY,EACrC;QACAK,mBAAmB,CAACQ,KAAK,GAAG,CAAC;MAC/B;IACF;EACF,CAAC,EACD,CAACd,QAAQ,EAAEC,oBAAoB,EAAEC,MAAM,EAAEC,MAAM,CACjD,CAAC;EAED,OAAO;IACLC,OAAO;IACPC,cAAc,EAAET,EAAE,KAAK,KAAK,GAAGS,cAAc,GAAGqB,SAAS;IACzDpB;EACF,CAAC;AACH;AAEA,SAAST,eAAe","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export { useChatKeyboard } from "./useChatKeyboard";
2
- export type { KeyboardLiftBehavior } from "./useChatKeyboard";
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import Reanimated from "react-native-reanimated";
3
- declare const ChatKit: {
4
- ScrollView: React.ForwardRefExoticComponent<{
5
- ScrollViewComponent: import("../ScrollViewWithBottomPadding").AnimatedScrollViewComponent;
6
- inverted?: boolean;
7
- offset?: number;
8
- keyboardLiftBehavior?: "always" | "never" | "whenAtEnd" | "persistent";
9
- freeze?: boolean;
10
- } & import("react-native").ScrollViewProps & {
11
- children?: React.ReactNode | undefined;
12
- } & React.RefAttributes<Reanimated.ScrollView>>;
13
- };
14
- export default ChatKit;
@@ -1,36 +0,0 @@
1
- import type { AnimatedRef, SharedValue } from "react-native-reanimated";
2
- import type Reanimated from "react-native-reanimated";
3
- type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
4
- type UseChatKeyboardOptions = {
5
- inverted: boolean;
6
- keyboardLiftBehavior: KeyboardLiftBehavior;
7
- freeze: boolean;
8
- offset: number;
9
- };
10
- type UseChatKeyboardReturn = {
11
- /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom on Android. */
12
- padding: SharedValue<number>;
13
- /** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */
14
- contentOffsetY: SharedValue<number> | undefined;
15
- /** TranslateY for the container wrapper on Android inverted lists. 0 otherwise. */
16
- containerTranslateY: SharedValue<number>;
17
- };
18
- /**
19
- * Hook that manages keyboard-driven scrolling for chat-style scroll views.
20
- * Calculates padding (extra scrollable space) and content shift values,
21
- * using the optimal strategy per platform.
22
- *
23
- * @param scrollViewRef - Animated ref to the scroll view.
24
- * @param options - Configuration for inverted and keyboardLiftBehavior.
25
- * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).
26
- * @example
27
- * ```tsx
28
- * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {
29
- * inverted: false,
30
- * keyboardLiftBehavior: "always",
31
- * });
32
- * ```
33
- */
34
- declare function useChatKeyboard(scrollViewRef: AnimatedRef<Reanimated.ScrollView>, options: UseChatKeyboardOptions): UseChatKeyboardReturn;
35
- export { useChatKeyboard };
36
- export type { KeyboardLiftBehavior };
@@ -1,20 +0,0 @@
1
- # Findings
2
-
3
- 1. We can not translate whole `ScrollView` because interactive dismissal will have double scroll if we move it by `translateY` or content will be truncated if we don't do it (same with external container).
4
- 2. So we need to move only content inside `ScrollView`.
5
- 3. If we use a separate `scrollTo` we still may have a random jump. The only one way is to use `contentOffset` + `padding` on `ScrollView`.
6
- 4. Input must be always in `KeyboardStickyView` because it's always pushing above the keyboard (unlike content, which may stay in place).
7
- 5. Changing `contentOffset` on `ScrollView` will not work. On iOS it works, but on Android sometimes it doesn't scroll to correct position (when you scroll list to the end) and on paper architecture it is flickering.
8
- 6. Next idea is to use `contentInset` on iOS and create custom `ClippingScrollView` on Android (with polyfill `contentInsetBottom` prop).
9
-
10
- ## To Do
11
-
12
- - [x] check how `ClippingScrollView` works in `KeyboardAwareScrollView` on Android (seems to be working well)
13
- - [x] introduce `useCombinedRef` hook in separate PR
14
- - [x] make sure, that style property doesn't affect the behavior with/without `ClippingScrollView` (test on a ScrollView that doesn't tke full screen?) <-- tested by comparing iOS with Android + `ClippingScrollView` (`contentInsetBottom` never override `paddingBottom` from `style`/`contentContainerStyle` even if ScrollView has `maxHeight=150` and we have only 2 inputs limitation + also tested `ScrollView` without height restrictions, in this case `paddingBottom` on `style` is not getting applied (it doesn't have an effect on both iOS/Android), but `contentContainerStyle` + `paddingBottom` works as expected and if I add `contentInsetBottom` to `ClippingScrollView` it doesn't overwrite a padding and increases scrollable area)
15
- - [x] `ClippingScrollView` + `KeyboardAwareScrollView` check by e2e tests (seems to be working, though on Android emulator + e2e tests sometimes when keyboard disappear we still have keyboard space)
16
- - [x] introduce `ClippingScrollView` in separate PR
17
- - [x] create a polyfill-version of ScrollView `that` can add scrollable padding in the bottom of the content? How to wrap custom `ScrollView` with it (cause we may pass one from react-native-gesture-handler)? Should just adjust `contentInset` (scroll management should belong to `KeyboardAwareScrollView`) (ScrollViewWithKeyboardPadding/ScrollViewWithKeyboardSpace)
18
- - [x] use `ClippingScrollView` in `KeyboardAwareScrollView` in separate PR
19
- - [-] introduce `ChatKit`
20
- - [] create issue in reanimated repo about `scrollTo` performance regression
@@ -1,2 +0,0 @@
1
- export { useChatKeyboard } from "./useChatKeyboard";
2
- export type { KeyboardLiftBehavior } from "./useChatKeyboard";
@@ -1,63 +0,0 @@
1
- import React, { forwardRef } from "react";
2
- import { useAnimatedRef, useAnimatedStyle } from "react-native-reanimated";
3
- import Reanimated from "react-native-reanimated";
4
-
5
- import useCombinedRef from "../hooks/useCombinedRef";
6
- import ScrollViewWithBottomPadding from "../ScrollViewWithBottomPadding";
7
-
8
- import { useChatKeyboard } from "./useChatKeyboard";
9
-
10
- import type { ChatKitScrollViewProps } from "./types";
11
-
12
- const ChatScrollView = forwardRef<
13
- Reanimated.ScrollView,
14
- React.PropsWithChildren<ChatKitScrollViewProps>
15
- >(
16
- (
17
- {
18
- children,
19
- ScrollViewComponent = Reanimated.ScrollView,
20
- inverted = false,
21
- keyboardLiftBehavior = "always",
22
- freeze = false,
23
- offset = 0,
24
- ...rest
25
- },
26
- ref,
27
- ) => {
28
- const scrollViewRef = useAnimatedRef<Reanimated.ScrollView>();
29
- const onRef = useCombinedRef(ref, scrollViewRef);
30
-
31
- const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(
32
- scrollViewRef,
33
- { inverted, keyboardLiftBehavior, freeze, offset },
34
- );
35
-
36
- const containerStyle = useAnimatedStyle(
37
- () => ({
38
- transform: [{ translateY: containerTranslateY.value }],
39
- }),
40
- [],
41
- );
42
-
43
- return (
44
- <ScrollViewWithBottomPadding
45
- ref={onRef}
46
- {...rest}
47
- bottomPadding={padding}
48
- containerStyle={containerStyle}
49
- contentOffsetY={contentOffsetY}
50
- inverted={inverted}
51
- ScrollViewComponent={ScrollViewComponent}
52
- >
53
- {children}
54
- </ScrollViewWithBottomPadding>
55
- );
56
- },
57
- );
58
-
59
- const ChatKit = {
60
- ScrollView: ChatScrollView,
61
- };
62
-
63
- export default ChatKit;