react-native-keyboard-controller 1.10.0 → 1.10.1
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/ios/.clang-format +30 -30
- package/ios/.swiftlint.yml +1 -1
- package/jest/index.js +4 -4
- package/lib/commonjs/animated.js +19 -19
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/bindings.native.js +6 -6
- package/lib/commonjs/bindings.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +5 -3
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +12 -7
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +5 -5
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +5 -5
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +2 -2
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +7 -3
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/hooks/useKeyboardInterpolation.js +81 -0
- package/lib/commonjs/components/hooks/useKeyboardInterpolation.js.map +1 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +1 -1
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +1 -1
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/reanimated.js.map +1 -1
- package/lib/commonjs/reanimated.native.js +12 -12
- package/lib/commonjs/reanimated.native.js.map +1 -1
- package/lib/commonjs/replicas.js +5 -5
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +2 -2
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/animated.js +27 -27
- package/lib/module/animated.js.map +1 -1
- package/lib/module/bindings.js +1 -1
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/bindings.native.js +7 -7
- package/lib/module/bindings.native.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js +7 -5
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +15 -11
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +11 -11
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +8 -8
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/utils.js +2 -2
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js +9 -6
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/hooks/useKeyboardInterpolation.js +74 -0
- package/lib/module/components/hooks/useKeyboardInterpolation.js.map +1 -0
- package/lib/module/components/index.js +3 -3
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/context.js +2 -2
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks.js +5 -5
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +8 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +4 -4
- package/lib/module/internal.js.map +1 -1
- package/lib/module/monkey-patch.android.js +2 -2
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/reanimated.js.map +1 -1
- package/lib/module/reanimated.native.js +13 -13
- package/lib/module/reanimated.native.js.map +1 -1
- package/lib/module/replicas.js +11 -11
- package/lib/module/replicas.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +2 -2
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +3 -3
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/module/specs/NativeKeyboardController.js +2 -2
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/specs/NativeStatusBarManagerCompat.js +2 -2
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/animated.d.ts +1 -1
- package/lib/typescript/bindings.d.ts +1 -1
- package/lib/typescript/bindings.native.d.ts +1 -1
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +4 -4
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +2 -2
- package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +1 -1
- package/lib/typescript/components/KeyboardStickyView/index.d.ts +2 -2
- package/lib/typescript/components/hooks/useKeyboardInterpolation.d.ts +20 -0
- package/lib/typescript/components/index.d.ts +3 -3
- package/lib/typescript/context.d.ts +4 -4
- package/lib/typescript/hooks.d.ts +3 -3
- package/lib/typescript/index.d.ts +8 -8
- package/lib/typescript/internal.d.ts +2 -2
- package/lib/typescript/reanimated.d.ts +1 -1
- package/lib/typescript/reanimated.native.d.ts +1 -1
- package/lib/typescript/replicas.d.ts +1 -1
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +3 -3
- package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +4 -4
- package/lib/typescript/specs/NativeKeyboardController.d.ts +1 -1
- package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +1 -1
- package/lib/typescript/types.d.ts +3 -3
- package/package.json +8 -10
- package/src/animated.tsx +39 -39
- package/src/bindings.native.ts +11 -11
- package/src/bindings.ts +3 -3
- package/src/components/KeyboardAvoidingView/hooks.ts +9 -6
- package/src/components/KeyboardAvoidingView/index.tsx +25 -24
- package/src/components/KeyboardAwareScrollView/index.tsx +23 -23
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +13 -13
- package/src/components/KeyboardAwareScrollView/utils.ts +3 -3
- package/src/components/KeyboardStickyView/index.tsx +11 -12
- package/src/components/hooks/useKeyboardInterpolation.ts +96 -0
- package/src/components/index.ts +3 -3
- package/src/context.ts +7 -7
- package/src/hooks.ts +12 -12
- package/src/index.ts +8 -8
- package/src/internal.ts +9 -9
- package/src/monkey-patch.android.ts +2 -2
- package/src/reanimated.native.ts +20 -20
- package/src/reanimated.ts +1 -1
- package/src/replicas.ts +16 -16
- package/src/specs/KeyboardControllerViewNativeComponent.ts +5 -5
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +7 -7
- package/src/specs/NativeKeyboardController.ts +3 -3
- package/src/specs/NativeStatusBarManagerCompat.ts +3 -3
- package/src/types.ts +21 -21
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Platform } from
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
2
|
import {
|
|
3
3
|
Easing,
|
|
4
4
|
useAnimatedReaction,
|
|
5
5
|
useSharedValue,
|
|
6
6
|
withTiming,
|
|
7
|
-
} from
|
|
7
|
+
} from "react-native-reanimated";
|
|
8
8
|
|
|
9
|
-
import { useKeyboardHandler } from
|
|
9
|
+
import { useKeyboardHandler } from "react-native-keyboard-controller";
|
|
10
10
|
|
|
11
11
|
const IS_ANDROID_ELEVEN_OR_HIGHER =
|
|
12
|
-
Platform.OS ===
|
|
12
|
+
Platform.OS === "android" && Platform.Version >= 30;
|
|
13
13
|
// on these platforms keyboard transitions will be smooth
|
|
14
14
|
const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS =
|
|
15
|
-
IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS ===
|
|
15
|
+
IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === "ios";
|
|
16
16
|
// on Android Telegram is not using androidx.core values and uses custom interpolation
|
|
17
17
|
// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39
|
|
18
18
|
// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40
|
|
@@ -22,7 +22,7 @@ const TELEGRAM_ANDROID_TIMING_CONFIG = {
|
|
|
22
22
|
0.19919472913616398,
|
|
23
23
|
0.010644531250000006,
|
|
24
24
|
0.27920937042459737,
|
|
25
|
-
0.91025390625
|
|
25
|
+
0.91025390625,
|
|
26
26
|
),
|
|
27
27
|
};
|
|
28
28
|
|
|
@@ -32,7 +32,7 @@ const TELEGRAM_ANDROID_TIMING_CONFIG = {
|
|
|
32
32
|
*/
|
|
33
33
|
export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
34
34
|
handler,
|
|
35
|
-
deps
|
|
35
|
+
deps,
|
|
36
36
|
) => {
|
|
37
37
|
const target = useSharedValue(-1);
|
|
38
38
|
const persistedHeight = useSharedValue(0);
|
|
@@ -64,13 +64,13 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
64
64
|
handler.onEnd?.(evt);
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
[handler]
|
|
67
|
+
[handler],
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
useKeyboardHandler(
|
|
71
71
|
{
|
|
72
72
|
onStart: (e) => {
|
|
73
|
-
|
|
73
|
+
"worklet";
|
|
74
74
|
|
|
75
75
|
// immediately dispatch onStart/onEnd events if onStart dispatched with the same height
|
|
76
76
|
// and don't wait for animation 250ms
|
|
@@ -95,21 +95,21 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
95
95
|
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
96
96
|
animatedKeyboardHeight.value = withTiming(
|
|
97
97
|
e.height,
|
|
98
|
-
TELEGRAM_ANDROID_TIMING_CONFIG
|
|
98
|
+
TELEGRAM_ANDROID_TIMING_CONFIG,
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
handler.onStart?.(e);
|
|
103
103
|
},
|
|
104
104
|
onMove: (e) => {
|
|
105
|
-
|
|
105
|
+
"worklet";
|
|
106
106
|
|
|
107
107
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
108
108
|
handler.onMove?.(e);
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
onEnd: (e) => {
|
|
112
|
-
|
|
112
|
+
"worklet";
|
|
113
113
|
|
|
114
114
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
115
115
|
handler.onEnd?.(e);
|
|
@@ -118,6 +118,6 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
118
118
|
persistedHeight.value = e.height;
|
|
119
119
|
},
|
|
120
120
|
},
|
|
121
|
-
deps
|
|
121
|
+
deps,
|
|
122
122
|
);
|
|
123
123
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(
|
|
2
2
|
worklet: F,
|
|
3
|
-
wait = 0
|
|
3
|
+
wait = 0,
|
|
4
4
|
) => {
|
|
5
|
-
|
|
5
|
+
"worklet";
|
|
6
6
|
|
|
7
7
|
const value = {
|
|
8
8
|
time: 0,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
return (...args: Parameters<F>): ReturnType<F> | void => {
|
|
12
|
-
|
|
12
|
+
"worklet";
|
|
13
13
|
|
|
14
14
|
const t = Date.now();
|
|
15
15
|
const now = t - value.time;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import React, { forwardRef, useMemo } from
|
|
2
|
-
import Reanimated, {
|
|
3
|
-
interpolate,
|
|
4
|
-
useAnimatedStyle,
|
|
5
|
-
} from 'react-native-reanimated';
|
|
1
|
+
import React, { forwardRef, useMemo } from "react";
|
|
2
|
+
import Reanimated, { useAnimatedStyle } from "react-native-reanimated";
|
|
6
3
|
|
|
7
|
-
import { useReanimatedKeyboardAnimation } from
|
|
4
|
+
import { useReanimatedKeyboardAnimation } from "../../hooks";
|
|
5
|
+
import useKeyboardInterpolation from "../hooks/useKeyboardInterpolation";
|
|
8
6
|
|
|
9
|
-
import type { View, ViewProps } from
|
|
7
|
+
import type { View, ViewProps } from "react-native";
|
|
10
8
|
|
|
11
9
|
type KeyboardStickyViewProps = {
|
|
12
10
|
/**
|
|
@@ -30,12 +28,13 @@ const KeyboardStickyView = forwardRef<
|
|
|
30
28
|
>(
|
|
31
29
|
(
|
|
32
30
|
{ children, offset: { closed = 0, opened = 0 } = {}, style, ...props },
|
|
33
|
-
ref
|
|
31
|
+
ref,
|
|
34
32
|
) => {
|
|
35
|
-
const { height
|
|
33
|
+
const { height } = useReanimatedKeyboardAnimation();
|
|
34
|
+
const { interpolate } = useKeyboardInterpolation();
|
|
36
35
|
|
|
37
36
|
const stickyViewStyle = useAnimatedStyle(() => {
|
|
38
|
-
const offset = interpolate(
|
|
37
|
+
const offset = interpolate(-height.value, [closed, opened]);
|
|
39
38
|
|
|
40
39
|
return {
|
|
41
40
|
transform: [{ translateY: height.value + offset }],
|
|
@@ -44,7 +43,7 @@ const KeyboardStickyView = forwardRef<
|
|
|
44
43
|
|
|
45
44
|
const styles = useMemo(
|
|
46
45
|
() => [style, stickyViewStyle],
|
|
47
|
-
[style, stickyViewStyle]
|
|
46
|
+
[style, stickyViewStyle],
|
|
48
47
|
);
|
|
49
48
|
|
|
50
49
|
return (
|
|
@@ -52,7 +51,7 @@ const KeyboardStickyView = forwardRef<
|
|
|
52
51
|
{children}
|
|
53
52
|
</Reanimated.View>
|
|
54
53
|
);
|
|
55
|
-
}
|
|
54
|
+
},
|
|
56
55
|
);
|
|
57
56
|
|
|
58
57
|
export default KeyboardStickyView;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
interpolate as interpolateREA,
|
|
3
|
+
useSharedValue,
|
|
4
|
+
} from "react-native-reanimated";
|
|
5
|
+
|
|
6
|
+
import { useKeyboardHandler } from "../../hooks";
|
|
7
|
+
|
|
8
|
+
type KeyboardInterpolationOutput = [number, number];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook that can be used for interpolation keyboard movement. The main concern is the thing
|
|
12
|
+
* when keyboard is opened and gets resized on Android. Let's say we are interpolating from
|
|
13
|
+
* closed to open [0, 200] and we want to interpolate it to [0, 230] (to achieve nice parallax effect).
|
|
14
|
+
* Then let's say keyboard changes its height to 220 (and we want to interpolate the value to 250, +30
|
|
15
|
+
* to keyboard height). If we interpolate based on `progress` value, then we will have a jump on first frame:
|
|
16
|
+
* the last interpolated position was 230, now we will interpolate to 250, but first frame will be calculated
|
|
17
|
+
* as 200 / 220 * 250 = 227 (and last interpolated position was 230) so we will have a jump.
|
|
18
|
+
*
|
|
19
|
+
* This hook handles it, and when keyboard changes its size it does an interpolation as:
|
|
20
|
+
* [200, 220] -> [230, 250], i. e. we preserve last interpolated value and use it as initial value for interpolation
|
|
21
|
+
* and because of that we will not have a jump and animation will start from the last frame and will be smooth.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/315
|
|
24
|
+
*/
|
|
25
|
+
const useKeyboardInterpolation = () => {
|
|
26
|
+
// keyboard heights
|
|
27
|
+
const nextKeyboardHeight = useSharedValue(0);
|
|
28
|
+
const prevKeyboardHeight = useSharedValue(0);
|
|
29
|
+
// save latest interpolated position
|
|
30
|
+
const lastInterpolation = useSharedValue(0);
|
|
31
|
+
// boolean flag indicating which output range should be used
|
|
32
|
+
const shouldUseInternalInterpolation = useSharedValue(false);
|
|
33
|
+
|
|
34
|
+
const interpolate = (
|
|
35
|
+
keyboardPosition: number,
|
|
36
|
+
output: KeyboardInterpolationOutput,
|
|
37
|
+
) => {
|
|
38
|
+
"worklet";
|
|
39
|
+
|
|
40
|
+
lastInterpolation.value = interpolateREA(
|
|
41
|
+
keyboardPosition,
|
|
42
|
+
[prevKeyboardHeight.value, nextKeyboardHeight.value],
|
|
43
|
+
shouldUseInternalInterpolation.value
|
|
44
|
+
? [lastInterpolation.value, output[1]]
|
|
45
|
+
: output,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return lastInterpolation.value;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
useKeyboardHandler(
|
|
52
|
+
{
|
|
53
|
+
onStart: (e) => {
|
|
54
|
+
"worklet";
|
|
55
|
+
|
|
56
|
+
const keyboardWillBeHidden = e.height === 0;
|
|
57
|
+
|
|
58
|
+
// keyboard will be hidden
|
|
59
|
+
if (keyboardWillBeHidden) {
|
|
60
|
+
shouldUseInternalInterpolation.value = false;
|
|
61
|
+
prevKeyboardHeight.value = 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// keyboard will change its size
|
|
65
|
+
if (
|
|
66
|
+
// keyboard is shown on screen
|
|
67
|
+
nextKeyboardHeight.value !== 0 &&
|
|
68
|
+
// it really changes size (handles iOS case when after interactive keyboard gets shown again)
|
|
69
|
+
nextKeyboardHeight.value !== e.height &&
|
|
70
|
+
// keyboard is not hiding
|
|
71
|
+
!keyboardWillBeHidden
|
|
72
|
+
) {
|
|
73
|
+
prevKeyboardHeight.value = nextKeyboardHeight.value;
|
|
74
|
+
shouldUseInternalInterpolation.value = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// keyboard will show or change size
|
|
78
|
+
if (!keyboardWillBeHidden) {
|
|
79
|
+
nextKeyboardHeight.value = e.height;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
onEnd: (e) => {
|
|
83
|
+
"worklet";
|
|
84
|
+
|
|
85
|
+
// handles case show -> resize -> hide -> show
|
|
86
|
+
// here we reset value to 0 when keyboard is hidden
|
|
87
|
+
nextKeyboardHeight.value = e.height;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
[],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return { interpolate };
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default useKeyboardInterpolation;
|
package/src/components/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as KeyboardAvoidingView } from
|
|
2
|
-
export { default as KeyboardStickyView } from
|
|
3
|
-
export { default as KeyboardAwareScrollView } from
|
|
1
|
+
export { default as KeyboardAvoidingView } from "./KeyboardAvoidingView";
|
|
2
|
+
export { default as KeyboardStickyView } from "./KeyboardStickyView";
|
|
3
|
+
export { default as KeyboardAwareScrollView } from "./KeyboardAwareScrollView";
|
package/src/context.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createContext, useContext } from
|
|
2
|
-
import { Animated } from
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
FocusedInputHandlers,
|
|
6
6
|
FocusedInputLayoutChangedEvent,
|
|
7
7
|
KeyboardHandlers,
|
|
8
|
-
} from
|
|
9
|
-
import type React from
|
|
10
|
-
import type { SharedValue } from
|
|
8
|
+
} from "./types";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
11
11
|
|
|
12
12
|
export type AnimatedContext = {
|
|
13
13
|
progress: Animated.Value;
|
|
@@ -35,7 +35,7 @@ const withSharedValue = <T>(value: T): SharedValue<T> => ({
|
|
|
35
35
|
});
|
|
36
36
|
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
37
37
|
const DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(
|
|
38
|
-
null
|
|
38
|
+
null,
|
|
39
39
|
);
|
|
40
40
|
const defaultContext: KeyboardAnimationContext = {
|
|
41
41
|
enabled: true,
|
|
@@ -58,7 +58,7 @@ export const useKeyboardContext = () => {
|
|
|
58
58
|
|
|
59
59
|
if (__DEV__ && context === defaultContext) {
|
|
60
60
|
console.warn(
|
|
61
|
-
"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work."
|
|
61
|
+
"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.",
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
package/src/hooks.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { useEffect } from
|
|
1
|
+
import { useEffect } from "react";
|
|
2
2
|
|
|
3
|
-
import { KeyboardController } from
|
|
4
|
-
import { AndroidSoftInputModes } from
|
|
5
|
-
import { useKeyboardContext } from
|
|
6
|
-
import { uuid } from
|
|
3
|
+
import { KeyboardController } from "./bindings";
|
|
4
|
+
import { AndroidSoftInputModes } from "./constants";
|
|
5
|
+
import { useKeyboardContext } from "./context";
|
|
6
|
+
import { uuid } from "./utils";
|
|
7
7
|
|
|
8
|
-
import type { AnimatedContext, ReanimatedContext } from
|
|
9
|
-
import type { FocusedInputHandler, KeyboardHandler } from
|
|
10
|
-
import type { DependencyList } from
|
|
8
|
+
import type { AnimatedContext, ReanimatedContext } from "./context";
|
|
9
|
+
import type { FocusedInputHandler, KeyboardHandler } from "./types";
|
|
10
|
+
import type { DependencyList } from "react";
|
|
11
11
|
|
|
12
12
|
export const useResizeMode = () => {
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
KeyboardController.setInputMode(
|
|
15
|
-
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
|
|
15
|
+
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
return () => KeyboardController.setDefaultMode();
|
|
@@ -35,7 +35,7 @@ export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
|
35
35
|
|
|
36
36
|
export function useGenericKeyboardHandler(
|
|
37
37
|
handler: KeyboardHandler,
|
|
38
|
-
deps?: DependencyList
|
|
38
|
+
deps?: DependencyList,
|
|
39
39
|
) {
|
|
40
40
|
const context = useKeyboardContext();
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ export function useGenericKeyboardHandler(
|
|
|
52
52
|
|
|
53
53
|
export function useKeyboardHandler(
|
|
54
54
|
handler: KeyboardHandler,
|
|
55
|
-
deps?: DependencyList
|
|
55
|
+
deps?: DependencyList,
|
|
56
56
|
) {
|
|
57
57
|
useResizeMode();
|
|
58
58
|
useGenericKeyboardHandler(handler, deps);
|
|
@@ -72,7 +72,7 @@ export function useReanimatedFocusedInput() {
|
|
|
72
72
|
|
|
73
73
|
export function useFocusedInputHandler(
|
|
74
74
|
handler?: FocusedInputHandler,
|
|
75
|
-
deps?: DependencyList
|
|
75
|
+
deps?: DependencyList,
|
|
76
76
|
) {
|
|
77
77
|
const context = useKeyboardContext();
|
|
78
78
|
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./bindings";
|
|
2
|
+
export * from "./animated";
|
|
3
|
+
export * from "./replicas";
|
|
4
|
+
export * from "./context";
|
|
5
|
+
export * from "./hooks";
|
|
6
|
+
export * from "./constants";
|
|
7
|
+
export * from "./types";
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
10
|
KeyboardAvoidingView,
|
|
11
11
|
KeyboardStickyView,
|
|
12
12
|
KeyboardAwareScrollView,
|
|
13
|
-
} from
|
|
13
|
+
} from "./components";
|
package/src/internal.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useCallback, useRef } from
|
|
2
|
-
import { Animated } from
|
|
3
|
-
import { useSharedValue } from
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
4
4
|
|
|
5
|
-
import type { Handlers } from
|
|
5
|
+
import type { Handlers } from "./types";
|
|
6
6
|
|
|
7
7
|
type UntypedHandler = Record<string, (event: never) => void>;
|
|
8
8
|
type SharedHandlersReturnType<T extends UntypedHandler> = [
|
|
9
9
|
(handler: Handlers<T>) => void,
|
|
10
|
-
<K extends keyof T>(type: K, event: Parameters<T[K]>[0]) => void
|
|
10
|
+
<K extends keyof T>(type: K, event: Parameters<T[K]>[0]) => void,
|
|
11
11
|
];
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -22,7 +22,7 @@ type SharedHandlersReturnType<T extends UntypedHandler> = [
|
|
|
22
22
|
* }
|
|
23
23
|
*/
|
|
24
24
|
export function useSharedHandlers<
|
|
25
|
-
T extends UntypedHandler
|
|
25
|
+
T extends UntypedHandler,
|
|
26
26
|
>(): SharedHandlersReturnType<T> {
|
|
27
27
|
const handlers = useSharedValue<Handlers<T>>({});
|
|
28
28
|
const jsHandlers = useRef<Handlers<T>>({});
|
|
@@ -48,9 +48,9 @@ export function useSharedHandlers<
|
|
|
48
48
|
}, []);
|
|
49
49
|
const broadcast = <K extends keyof T>(
|
|
50
50
|
type: K,
|
|
51
|
-
event: Parameters<T[K]>[0]
|
|
51
|
+
event: Parameters<T[K]>[0],
|
|
52
52
|
) => {
|
|
53
|
-
|
|
53
|
+
"worklet";
|
|
54
54
|
|
|
55
55
|
Object.keys(handlers.value).forEach((key) => {
|
|
56
56
|
handlers.value[key]?.[type]?.(event);
|
|
@@ -71,7 +71,7 @@ export function useSharedHandlers<
|
|
|
71
71
|
*/
|
|
72
72
|
export function useAnimatedValue(
|
|
73
73
|
initialValue: number,
|
|
74
|
-
config?: Animated.AnimatedConfig
|
|
74
|
+
config?: Animated.AnimatedConfig,
|
|
75
75
|
): Animated.Value {
|
|
76
76
|
const ref = useRef<Animated.Value | null>(null);
|
|
77
77
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @ts-expect-error because there is no corresponding type definition
|
|
2
|
-
import * as NativeAndroidManager from
|
|
2
|
+
import * as NativeAndroidManager from "react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid";
|
|
3
3
|
|
|
4
4
|
const DefaultNativeAndroidManager = NativeAndroidManager.default;
|
|
5
5
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
6
6
|
const RCTStatusBarManagerCompat =
|
|
7
|
-
require(
|
|
7
|
+
require("./specs/NativeStatusBarManagerCompat").default;
|
|
8
8
|
|
|
9
9
|
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
10
10
|
// in order to use library on all available platforms we have to monkey patch
|
package/src/reanimated.native.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEvent, useHandler } from
|
|
1
|
+
import { useEvent, useHandler } from "react-native-reanimated";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
EventWithName,
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
FocusedInputTextHandlerHook,
|
|
9
9
|
KeyboardHandlerHook,
|
|
10
10
|
NativeEvent,
|
|
11
|
-
} from
|
|
11
|
+
} from "./types";
|
|
12
12
|
|
|
13
13
|
export const useAnimatedKeyboardHandler: KeyboardHandlerHook<
|
|
14
14
|
Record<string, unknown>,
|
|
@@ -18,7 +18,7 @@ export const useAnimatedKeyboardHandler: KeyboardHandlerHook<
|
|
|
18
18
|
|
|
19
19
|
return useEvent(
|
|
20
20
|
(event) => {
|
|
21
|
-
|
|
21
|
+
"worklet";
|
|
22
22
|
const {
|
|
23
23
|
onKeyboardMoveStart,
|
|
24
24
|
onKeyboardMove,
|
|
@@ -28,33 +28,33 @@ export const useAnimatedKeyboardHandler: KeyboardHandlerHook<
|
|
|
28
28
|
|
|
29
29
|
if (
|
|
30
30
|
onKeyboardMoveStart &&
|
|
31
|
-
event.eventName.endsWith(
|
|
31
|
+
event.eventName.endsWith("onKeyboardMoveStart")
|
|
32
32
|
) {
|
|
33
33
|
onKeyboardMoveStart(event, context);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (onKeyboardMove && event.eventName.endsWith(
|
|
36
|
+
if (onKeyboardMove && event.eventName.endsWith("onKeyboardMove")) {
|
|
37
37
|
onKeyboardMove(event, context);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (onKeyboardMoveEnd && event.eventName.endsWith(
|
|
40
|
+
if (onKeyboardMoveEnd && event.eventName.endsWith("onKeyboardMoveEnd")) {
|
|
41
41
|
onKeyboardMoveEnd(event, context);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (
|
|
45
45
|
onKeyboardMoveInteractive &&
|
|
46
|
-
event.eventName.endsWith(
|
|
46
|
+
event.eventName.endsWith("onKeyboardMoveInteractive")
|
|
47
47
|
) {
|
|
48
48
|
onKeyboardMoveInteractive(event, context);
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
"onKeyboardMoveStart",
|
|
53
|
+
"onKeyboardMove",
|
|
54
|
+
"onKeyboardMoveEnd",
|
|
55
|
+
"onKeyboardMoveInteractive",
|
|
56
56
|
],
|
|
57
|
-
doDependenciesDiffer
|
|
57
|
+
doDependenciesDiffer,
|
|
58
58
|
);
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -66,18 +66,18 @@ export const useFocusedInputLayoutHandler: FocusedInputLayoutHandlerHook<
|
|
|
66
66
|
|
|
67
67
|
return useEvent(
|
|
68
68
|
(event) => {
|
|
69
|
-
|
|
69
|
+
"worklet";
|
|
70
70
|
const { onFocusedInputLayoutChanged } = handlers;
|
|
71
71
|
|
|
72
72
|
if (
|
|
73
73
|
onFocusedInputLayoutChanged &&
|
|
74
|
-
event.eventName.endsWith(
|
|
74
|
+
event.eventName.endsWith("onFocusedInputLayoutChanged")
|
|
75
75
|
) {
|
|
76
76
|
onFocusedInputLayoutChanged(event, context);
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
[
|
|
80
|
-
doDependenciesDiffer
|
|
79
|
+
["onFocusedInputLayoutChanged"],
|
|
80
|
+
doDependenciesDiffer,
|
|
81
81
|
);
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -89,17 +89,17 @@ export const useFocusedInputTextHandler: FocusedInputTextHandlerHook<
|
|
|
89
89
|
|
|
90
90
|
return useEvent(
|
|
91
91
|
(event) => {
|
|
92
|
-
|
|
92
|
+
"worklet";
|
|
93
93
|
const { onFocusedInputTextChanged } = handlers;
|
|
94
94
|
|
|
95
95
|
if (
|
|
96
96
|
onFocusedInputTextChanged &&
|
|
97
|
-
event.eventName.endsWith(
|
|
97
|
+
event.eventName.endsWith("onFocusedInputTextChanged")
|
|
98
98
|
) {
|
|
99
99
|
onFocusedInputTextChanged(event, context);
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
|
-
[
|
|
103
|
-
doDependenciesDiffer
|
|
102
|
+
["onFocusedInputTextChanged"],
|
|
103
|
+
doDependenciesDiffer,
|
|
104
104
|
);
|
|
105
105
|
};
|
package/src/reanimated.ts
CHANGED
package/src/replicas.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef } from
|
|
2
|
-
import { Animated, Easing, Keyboard, Platform } from
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { Animated, Easing, Keyboard, Platform } from "react-native";
|
|
3
3
|
import {
|
|
4
4
|
runOnUI,
|
|
5
5
|
useAnimatedReaction,
|
|
6
6
|
useDerivedValue,
|
|
7
7
|
useSharedValue,
|
|
8
8
|
withSpring,
|
|
9
|
-
} from
|
|
9
|
+
} from "react-native-reanimated";
|
|
10
10
|
|
|
11
|
-
import { KeyboardController } from
|
|
12
|
-
import { AndroidSoftInputModes } from
|
|
13
|
-
import { useReanimatedKeyboardAnimation } from
|
|
11
|
+
import { KeyboardController } from "./bindings";
|
|
12
|
+
import { AndroidSoftInputModes } from "./constants";
|
|
13
|
+
import { useReanimatedKeyboardAnimation } from "./hooks";
|
|
14
14
|
|
|
15
|
-
const availableOSEventType = Platform.OS ===
|
|
15
|
+
const availableOSEventType = Platform.OS === "ios" ? "Will" : "Did";
|
|
16
16
|
|
|
17
17
|
// cubic-bezier(.17,.67,.34,.94)
|
|
18
18
|
export const defaultAndroidEasing = Easing.bezier(0.4, 0.0, 0.2, 1);
|
|
@@ -37,12 +37,12 @@ export const useKeyboardAnimationReplica = (): KeyboardAnimation => {
|
|
|
37
37
|
height: height.current,
|
|
38
38
|
progress: progress.current,
|
|
39
39
|
}),
|
|
40
|
-
[]
|
|
40
|
+
[],
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
useEffect(() => {
|
|
44
44
|
KeyboardController.setInputMode(
|
|
45
|
-
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
|
|
45
|
+
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
return () => KeyboardController.setDefaultMode();
|
|
@@ -59,7 +59,7 @@ export const useKeyboardAnimationReplica = (): KeyboardAnimation => {
|
|
|
59
59
|
}).start();
|
|
60
60
|
|
|
61
61
|
return () => listener.remove();
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
63
|
);
|
|
64
64
|
}, []);
|
|
65
65
|
useEffect(() => {
|
|
@@ -74,7 +74,7 @@ export const useKeyboardAnimationReplica = (): KeyboardAnimation => {
|
|
|
74
74
|
}).start();
|
|
75
75
|
|
|
76
76
|
return () => listener.remove();
|
|
77
|
-
}
|
|
77
|
+
},
|
|
78
78
|
);
|
|
79
79
|
}, []);
|
|
80
80
|
|
|
@@ -111,7 +111,7 @@ export const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
111
111
|
const progress = useDerivedValue(() => height.value / heightEvent.value);
|
|
112
112
|
|
|
113
113
|
const handler = useCallback((_height: number) => {
|
|
114
|
-
|
|
114
|
+
"worklet";
|
|
115
115
|
|
|
116
116
|
heightEvent.value = _height;
|
|
117
117
|
}, []);
|
|
@@ -128,14 +128,14 @@ export const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
128
128
|
height.value = withSpring(_keyboardHeight, IOS_SPRING_CONFIG);
|
|
129
129
|
}
|
|
130
130
|
},
|
|
131
|
-
[]
|
|
131
|
+
[],
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
useEffect(() => {
|
|
135
|
-
const show = Keyboard.addListener(
|
|
135
|
+
const show = Keyboard.addListener("keyboardWillShow", (e) => {
|
|
136
136
|
runOnUI(handler)(-e.endCoordinates.height);
|
|
137
137
|
});
|
|
138
|
-
const hide = Keyboard.addListener(
|
|
138
|
+
const hide = Keyboard.addListener("keyboardWillHide", () => {
|
|
139
139
|
runOnUI(handler)(0);
|
|
140
140
|
});
|
|
141
141
|
|
|
@@ -149,6 +149,6 @@ export const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
export const useGradualKeyboardAnimation =
|
|
152
|
-
Platform.OS ===
|
|
152
|
+
Platform.OS === "ios"
|
|
153
153
|
? useReanimatedKeyboardAnimationReplica
|
|
154
154
|
: useReanimatedKeyboardAnimation;
|