react-native-keyboard-controller 1.11.2 → 1.11.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/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt +52 -60
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +1 -6
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +4 -3
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +3 -7
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +4 -3
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/index.js +0 -6
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +1 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +36 -24
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +2 -6
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +5 -4
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js +4 -7
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +4 -3
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/index.js +1 -1
- 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/monkey-patch.android.js +36 -24
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +5 -0
- package/lib/typescript/components/index.d.ts +2 -1
- package/lib/typescript/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/KeyboardAvoidingView/index.tsx +6 -7
- package/src/components/KeyboardAwareScrollView/index.tsx +4 -4
- package/src/components/KeyboardStickyView/index.tsx +6 -6
- package/src/components/KeyboardToolbar/index.tsx +38 -20
- package/src/components/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/monkey-patch.android.ts +31 -26
- package/lib/commonjs/components/hooks/useKeyboardInterpolation.js +0 -89
- package/lib/commonjs/components/hooks/useKeyboardInterpolation.js.map +0 -1
- package/lib/module/components/hooks/useKeyboardInterpolation.js +0 -82
- package/lib/module/components/hooks/useKeyboardInterpolation.js.map +0 -1
- package/lib/typescript/components/hooks/useKeyboardInterpolation.d.ts +0 -20
- package/src/components/hooks/useKeyboardInterpolation.ts +0 -109
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { Platform } from "react-native";
|
|
2
|
-
import {
|
|
3
|
-
interpolate as interpolateREA,
|
|
4
|
-
useSharedValue,
|
|
5
|
-
} from "react-native-reanimated";
|
|
6
|
-
|
|
7
|
-
import { useKeyboardHandler } from "react-native-keyboard-controller";
|
|
8
|
-
|
|
9
|
-
type KeyboardInterpolationOutput = [number, number];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Hook that can be used for interpolation keyboard movement. The main concern is the thing
|
|
13
|
-
* when keyboard is opened and gets resized on Android. Let's say we are interpolating from
|
|
14
|
-
* closed to open [0, 200] and we want to interpolate it to [0, 230] (to achieve nice parallax effect).
|
|
15
|
-
* Then let's say keyboard changes its height to 220 (and we want to interpolate the value to 250, +30
|
|
16
|
-
* to keyboard height). If we interpolate based on `progress` value, then we will have a jump on first frame:
|
|
17
|
-
* the last interpolated position was 230, now we will interpolate to 250, but first frame will be calculated
|
|
18
|
-
* as 200 / 220 * 250 = 227 (and last interpolated position was 230) so we will have a jump.
|
|
19
|
-
*
|
|
20
|
-
* This hook handles it, and when keyboard changes its size it does an interpolation as:
|
|
21
|
-
* [200, 220] -> [230, 250], i. e. we preserve last interpolated value and use it as initial value for interpolation
|
|
22
|
-
* and because of that we will not have a jump and animation will start from the last frame and will be smooth.
|
|
23
|
-
*
|
|
24
|
-
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/315
|
|
25
|
-
*/
|
|
26
|
-
const useKeyboardInterpolation = () => {
|
|
27
|
-
// keyboard heights
|
|
28
|
-
const nextKeyboardHeight = useSharedValue(0);
|
|
29
|
-
const prevKeyboardHeight = useSharedValue(0);
|
|
30
|
-
// save latest interpolated position
|
|
31
|
-
const lastInterpolation = useSharedValue(0);
|
|
32
|
-
// boolean flag indicating which output range should be used
|
|
33
|
-
const shouldUseInternalInterpolation = useSharedValue(false);
|
|
34
|
-
|
|
35
|
-
const interpolate = (
|
|
36
|
-
keyboardPosition: number,
|
|
37
|
-
output: KeyboardInterpolationOutput,
|
|
38
|
-
) => {
|
|
39
|
-
"worklet";
|
|
40
|
-
|
|
41
|
-
// on iOS it's safe to interpolate between 0 and `fullKeyboardSize` because when
|
|
42
|
-
// keyboard resized we will not have intermediate values and transition will be instant
|
|
43
|
-
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
|
|
44
|
-
if (Platform.OS === "ios") {
|
|
45
|
-
return interpolateREA(
|
|
46
|
-
keyboardPosition,
|
|
47
|
-
[0, nextKeyboardHeight.value],
|
|
48
|
-
output,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const interpolation = interpolateREA(
|
|
53
|
-
keyboardPosition,
|
|
54
|
-
[prevKeyboardHeight.value, nextKeyboardHeight.value],
|
|
55
|
-
shouldUseInternalInterpolation.value
|
|
56
|
-
? [lastInterpolation.value, output[1]]
|
|
57
|
-
: output,
|
|
58
|
-
);
|
|
59
|
-
lastInterpolation.value = interpolation;
|
|
60
|
-
|
|
61
|
-
return interpolation;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
useKeyboardHandler(
|
|
65
|
-
{
|
|
66
|
-
onStart: (e) => {
|
|
67
|
-
"worklet";
|
|
68
|
-
|
|
69
|
-
const keyboardWillBeHidden = e.height === 0;
|
|
70
|
-
|
|
71
|
-
// keyboard will be hidden
|
|
72
|
-
if (keyboardWillBeHidden) {
|
|
73
|
-
shouldUseInternalInterpolation.value = false;
|
|
74
|
-
prevKeyboardHeight.value = 0;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// keyboard will change its size
|
|
78
|
-
if (
|
|
79
|
-
// keyboard is shown on screen
|
|
80
|
-
nextKeyboardHeight.value !== 0 &&
|
|
81
|
-
// it really changes size (handles iOS case when after interactive keyboard gets shown again)
|
|
82
|
-
nextKeyboardHeight.value !== e.height &&
|
|
83
|
-
// keyboard is not hiding
|
|
84
|
-
!keyboardWillBeHidden
|
|
85
|
-
) {
|
|
86
|
-
prevKeyboardHeight.value = nextKeyboardHeight.value;
|
|
87
|
-
shouldUseInternalInterpolation.value = true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// keyboard will show or change size
|
|
91
|
-
if (!keyboardWillBeHidden) {
|
|
92
|
-
nextKeyboardHeight.value = e.height;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
onEnd: (e) => {
|
|
96
|
-
"worklet";
|
|
97
|
-
|
|
98
|
-
// handles case show -> resize -> hide -> show
|
|
99
|
-
// here we reset value to 0 when keyboard is hidden
|
|
100
|
-
nextKeyboardHeight.value = e.height;
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
[],
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return { interpolate };
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export default useKeyboardInterpolation;
|