react-native-keyboard-controller 1.21.0-beta.1 → 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 (89) 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/jest/index.js +1 -0
  5. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +7 -4
  6. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  7. package/lib/commonjs/components/KeyboardChatScrollView/hooks.js +13 -0
  8. package/lib/commonjs/components/KeyboardChatScrollView/hooks.js.map +1 -0
  9. package/lib/commonjs/components/KeyboardChatScrollView/index.js +80 -0
  10. package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
  11. package/lib/commonjs/components/KeyboardChatScrollView/types.js +6 -0
  12. package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
  13. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +135 -0
  14. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  15. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +121 -0
  16. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  17. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +205 -0
  18. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  19. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
  20. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  21. package/lib/commonjs/components/KeyboardStickyView/index.js +9 -5
  22. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  23. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +46 -13
  24. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  25. package/lib/commonjs/components/hooks/useScrollState.js +20 -1
  26. package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
  27. package/lib/commonjs/components/index.js +7 -0
  28. package/lib/commonjs/components/index.js.map +1 -1
  29. package/lib/commonjs/index.js +7 -0
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  32. package/lib/commonjs/types/views.js.map +1 -1
  33. package/lib/module/components/KeyboardAwareScrollView/index.js +7 -4
  34. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  35. package/lib/module/components/KeyboardChatScrollView/hooks.js +2 -0
  36. package/lib/module/components/KeyboardChatScrollView/hooks.js.map +1 -0
  37. package/lib/module/components/KeyboardChatScrollView/index.js +73 -0
  38. package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
  39. package/lib/module/components/KeyboardChatScrollView/types.js +2 -0
  40. package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
  41. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +125 -0
  42. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  43. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +115 -0
  44. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  45. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +199 -0
  46. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  47. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
  48. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  49. package/lib/module/components/KeyboardStickyView/index.js +9 -5
  50. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  51. package/lib/module/components/ScrollViewWithBottomPadding/index.js +47 -14
  52. package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  53. package/lib/module/components/hooks/useScrollState.js +21 -2
  54. package/lib/module/components/hooks/useScrollState.js.map +1 -1
  55. package/lib/module/components/index.js +1 -0
  56. package/lib/module/components/index.js.map +1 -1
  57. package/lib/module/index.js +1 -1
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  60. package/lib/module/types/views.js.map +1 -1
  61. package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
  62. package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +12 -0
  63. package/lib/typescript/components/KeyboardChatScrollView/types.d.ts +48 -0
  64. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts +77 -0
  65. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +21 -0
  66. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
  67. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +22 -0
  68. package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +3 -0
  69. package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
  70. package/lib/typescript/components/index.d.ts +2 -0
  71. package/lib/typescript/index.d.ts +2 -2
  72. package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +1 -0
  73. package/lib/typescript/types/views.d.ts +2 -0
  74. package/package.json +12 -4
  75. package/src/components/KeyboardAwareScrollView/index.tsx +10 -3
  76. package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
  77. package/src/components/KeyboardChatScrollView/index.tsx +106 -0
  78. package/src/components/KeyboardChatScrollView/types.ts +49 -0
  79. package/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts +163 -0
  80. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +180 -0
  81. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +300 -0
  82. package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +30 -0
  83. package/src/components/KeyboardStickyView/index.tsx +8 -8
  84. package/src/components/ScrollViewWithBottomPadding/index.tsx +63 -17
  85. package/src/components/hooks/useScrollState.ts +24 -2
  86. package/src/components/index.ts +2 -0
  87. package/src/index.ts +2 -0
  88. package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +1 -0
  89. package/src/types/views.ts +2 -0
@@ -1,5 +1,5 @@
1
1
  import React, { forwardRef } from "react";
2
- import { Platform } from "react-native";
2
+ import { Platform, View } from "react-native";
3
3
  import Reanimated, { useAnimatedProps } from "react-native-reanimated";
4
4
 
5
5
  import { ClippingScrollView } from "../../bindings";
@@ -9,8 +9,9 @@ import styles from "./styles";
9
9
  import type { ScrollViewProps } from "react-native";
10
10
  import type { SharedValue } from "react-native-reanimated";
11
11
 
12
+ const OS = Platform.OS;
12
13
  const ReanimatedClippingScrollView =
13
- Platform.OS === "android"
14
+ OS === "android"
14
15
  ? Reanimated.createAnimatedComponent(ClippingScrollView)
15
16
  : ClippingScrollView;
16
17
 
@@ -25,7 +26,10 @@ export type AnimatedScrollViewComponent = React.ForwardRefExoticComponent<
25
26
  type ScrollViewWithBottomPaddingProps = {
26
27
  ScrollViewComponent: AnimatedScrollViewComponent;
27
28
  children?: React.ReactNode;
29
+ inverted?: boolean;
28
30
  bottomPadding: SharedValue<number>;
31
+ /** Absolute Y content offset (iOS only, for KeyboardChatScrollView). */
32
+ contentOffsetY?: SharedValue<number>;
29
33
  } & ScrollViewProps;
30
34
 
31
35
  const ScrollViewWithBottomPadding = forwardRef<
@@ -33,28 +37,60 @@ const ScrollViewWithBottomPadding = forwardRef<
33
37
  ScrollViewWithBottomPaddingProps
34
38
  >(
35
39
  (
36
- { ScrollViewComponent, bottomPadding, contentInset, children, ...rest },
40
+ {
41
+ ScrollViewComponent,
42
+ bottomPadding,
43
+ contentInset,
44
+ scrollIndicatorInsets,
45
+ inverted,
46
+ contentOffsetY,
47
+ children,
48
+ ...rest
49
+ },
37
50
  ref,
38
51
  ) => {
39
- const animatedProps = useAnimatedProps(
40
- () => ({
52
+ const animatedProps = useAnimatedProps(() => {
53
+ const insetTop = inverted ? bottomPadding.value : 0;
54
+ const insetBottom = !inverted ? bottomPadding.value : 0;
55
+ const bottom = insetBottom + (contentInset?.bottom || 0);
56
+ const top = insetTop + (contentInset?.top || 0);
57
+
58
+ const result: Record<string, unknown> = {
41
59
  // iOS prop
42
60
  contentInset: {
43
- bottom: bottomPadding.value + (contentInset?.bottom || 0),
44
- top: contentInset?.top,
61
+ bottom: bottom,
62
+ top: top,
45
63
  right: contentInset?.right,
46
64
  left: contentInset?.left,
47
65
  },
66
+ scrollIndicatorInsets: {
67
+ bottom: bottom,
68
+ top: top,
69
+ right: scrollIndicatorInsets?.right,
70
+ left: scrollIndicatorInsets?.left,
71
+ },
48
72
  // Android prop
49
- contentInsetBottom: bottomPadding.value,
50
- }),
51
- [
52
- contentInset?.bottom,
53
- contentInset?.top,
54
- contentInset?.right,
55
- contentInset?.left,
56
- ],
57
- );
73
+ contentInsetBottom: insetBottom,
74
+ contentInsetTop: insetTop,
75
+ };
76
+
77
+ if (contentOffsetY) {
78
+ result.contentOffset = { x: 0, y: contentOffsetY.value };
79
+ }
80
+
81
+ return result;
82
+ }, [
83
+ contentInset?.bottom,
84
+ contentInset?.top,
85
+ contentInset?.right,
86
+ contentInset?.left,
87
+ scrollIndicatorInsets?.bottom,
88
+ scrollIndicatorInsets?.top,
89
+ scrollIndicatorInsets?.right,
90
+ scrollIndicatorInsets?.left,
91
+ inverted,
92
+ contentOffsetY,
93
+ ]);
58
94
 
59
95
  return (
60
96
  <ReanimatedClippingScrollView
@@ -62,7 +98,17 @@ const ScrollViewWithBottomPadding = forwardRef<
62
98
  style={styles.container}
63
99
  >
64
100
  <ScrollViewComponent ref={ref} animatedProps={animatedProps} {...rest}>
65
- {children}
101
+ {inverted ? (
102
+ // The only thing it can break is `StickyHeader`, but it's already broken in FlatList and other lists
103
+ // don't support this functionality, so we can add additional view here
104
+ // The correct fix would be to add a new prop in ScrollView that allows
105
+ // to customize children extraction logic and skip custom view
106
+ <View collapsable={false} nativeID="container">
107
+ {children}
108
+ </View>
109
+ ) : (
110
+ children
111
+ )}
66
112
  </ScrollViewComponent>
67
113
  </ReanimatedClippingScrollView>
68
114
  );
@@ -1,8 +1,9 @@
1
- import { useEffect } from "react";
1
+ import { useCallback, useEffect } from "react";
2
2
  import { useEvent, useSharedValue } from "react-native-reanimated";
3
3
 
4
4
  import { useEventHandlerRegistration } from "../../internal";
5
5
 
6
+ import type { LayoutChangeEvent } from "react-native";
6
7
  import type { AnimatedRef } from "react-native-reanimated";
7
8
  import type Reanimated from "react-native-reanimated";
8
9
 
@@ -53,7 +54,28 @@ const useScrollState = (ref: AnimatedRef<Reanimated.ScrollView>) => {
53
54
  };
54
55
  }, []);
55
56
 
56
- return { offset, layout, size };
57
+ // `onContentSizeChange` is synthesized in JS (from the content container's
58
+ // onLayout) and `onLayout` has a different payload shape than scroll events,
59
+ // so neither can be reliably captured via native event registration.
60
+ // Instead we expose callbacks for the consumer to attach as props.
61
+ const onLayout = useCallback(
62
+ (e: LayoutChangeEvent) => {
63
+ layout.value = {
64
+ width: e.nativeEvent.layout.width,
65
+ height: e.nativeEvent.layout.height,
66
+ };
67
+ },
68
+ [layout],
69
+ );
70
+
71
+ const onContentSizeChange = useCallback(
72
+ (w: number, h: number) => {
73
+ size.value = { width: w, height: h };
74
+ },
75
+ [size],
76
+ );
77
+
78
+ return { offset, layout, size, onLayout, onContentSizeChange };
57
79
  };
58
80
 
59
81
  export default useScrollState;
@@ -5,6 +5,7 @@ export {
5
5
  default as KeyboardToolbar,
6
6
  DefaultKeyboardToolbarTheme,
7
7
  } from "./KeyboardToolbar";
8
+ export { default as KeyboardChatScrollView } from "./KeyboardChatScrollView";
8
9
  export type { KeyboardAvoidingViewProps } from "./KeyboardAvoidingView";
9
10
  export type { KeyboardStickyViewProps } from "./KeyboardStickyView";
10
11
  export type {
@@ -12,3 +13,4 @@ export type {
12
13
  KeyboardAwareScrollViewRef,
13
14
  } from "./KeyboardAwareScrollView";
14
15
  export type { KeyboardToolbarProps } from "./KeyboardToolbar";
16
+ export type { KeyboardChatScrollViewProps } from "./KeyboardChatScrollView/types";
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./types";
8
8
  export * from "./compat";
9
9
 
10
10
  export {
11
+ KeyboardChatScrollView,
11
12
  KeyboardAvoidingView,
12
13
  KeyboardStickyView,
13
14
  KeyboardAwareScrollView,
@@ -16,6 +17,7 @@ export {
16
17
  DefaultKeyboardToolbarTheme,
17
18
  } from "./components";
18
19
  export type {
20
+ KeyboardChatScrollViewProps,
19
21
  KeyboardAvoidingViewProps,
20
22
  KeyboardStickyViewProps,
21
23
  KeyboardAwareScrollViewProps,
@@ -6,6 +6,7 @@ import type { Double } from "react-native/Libraries/Types/CodegenTypes";
6
6
 
7
7
  export interface NativeProps extends ViewProps {
8
8
  contentInsetBottom: Double;
9
+ contentInsetTop: Double;
9
10
  }
10
11
 
11
12
  export default codegenNativeComponent<NativeProps>(
@@ -53,5 +53,7 @@ export type ClippingScrollViewProps = PropsWithChildren<
53
53
  ViewProps & {
54
54
  /** An additional space that gets applied to the bottom of the `ScrollView` (inside a scrollable content). Default is `0`. */
55
55
  contentInsetBottom?: number;
56
+ /** An additional space that gets applied to the top of the `ScrollView` (inside a scrollable content). Default is `0`. */
57
+ contentInsetTop?: number;
56
58
  }
57
59
  >;