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.
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +7 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt +28 -1
- package/android/src/paper/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +8 -0
- package/jest/index.js +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +7 -4
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardChatScrollView/hooks.js +13 -0
- package/lib/commonjs/components/KeyboardChatScrollView/hooks.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/index.js +80 -0
- package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/types.js +6 -0
- package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +135 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +121 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +205 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js +9 -5
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +46 -13
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/commonjs/components/hooks/useScrollState.js +20 -1
- package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
- package/lib/commonjs/components/index.js +7 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
- package/lib/commonjs/types/views.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +7 -4
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardChatScrollView/hooks.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/hooks.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/index.js +73 -0
- package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/types.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +125 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +115 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +199 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/module/components/KeyboardStickyView/index.js +9 -5
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/ScrollViewWithBottomPadding/index.js +47 -14
- package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/module/components/hooks/useScrollState.js +21 -2
- package/lib/module/components/hooks/useScrollState.js.map +1 -1
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
- package/lib/module/types/views.js.map +1 -1
- package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
- package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +12 -0
- package/lib/typescript/components/KeyboardChatScrollView/types.d.ts +48 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts +77 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +21 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +22 -0
- package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +3 -0
- package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +1 -0
- package/lib/typescript/types/views.d.ts +2 -0
- package/package.json +12 -4
- package/src/components/KeyboardAwareScrollView/index.tsx +10 -3
- package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
- package/src/components/KeyboardChatScrollView/index.tsx +106 -0
- package/src/components/KeyboardChatScrollView/types.ts +49 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts +163 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +180 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +300 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +30 -0
- package/src/components/KeyboardStickyView/index.tsx +8 -8
- package/src/components/ScrollViewWithBottomPadding/index.tsx +63 -17
- package/src/components/hooks/useScrollState.ts +24 -2
- package/src/components/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +1 -0
- 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
|
-
|
|
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
|
-
{
|
|
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:
|
|
44
|
-
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:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
{
|
|
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
|
-
|
|
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;
|
package/src/components/index.ts
CHANGED
|
@@ -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,
|
package/src/types/views.ts
CHANGED
|
@@ -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
|
>;
|