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,4 +1,4 @@
|
|
|
1
|
-
import type { EmitterSubscription, NativeSyntheticEvent, ViewProps } from
|
|
1
|
+
import type { EmitterSubscription, NativeSyntheticEvent, ViewProps } from "react-native";
|
|
2
2
|
export type NativeEvent = {
|
|
3
3
|
progress: number;
|
|
4
4
|
height: number;
|
|
@@ -37,7 +37,7 @@ export type KeyboardControllerProps = {
|
|
|
37
37
|
enabled?: boolean;
|
|
38
38
|
} & ViewProps;
|
|
39
39
|
export type KeyboardGestureAreaProps = {
|
|
40
|
-
interpolator:
|
|
40
|
+
interpolator: "ios" | "linear";
|
|
41
41
|
/**
|
|
42
42
|
* Whether to allow to show a keyboard from dismissed state by swipe up.
|
|
43
43
|
* Default to `false`.
|
|
@@ -57,7 +57,7 @@ export type KeyboardControllerModule = {
|
|
|
57
57
|
addListener: (eventName: string) => void;
|
|
58
58
|
removeListeners: (count: number) => void;
|
|
59
59
|
};
|
|
60
|
-
export type KeyboardControllerEvents =
|
|
60
|
+
export type KeyboardControllerEvents = "keyboardWillShow" | "keyboardDidShow" | "keyboardWillHide" | "keyboardDidHide";
|
|
61
61
|
export type KeyboardEventData = {
|
|
62
62
|
height: number;
|
|
63
63
|
duration: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Keyboard manager which works in identical way on both iOS and Android",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"!**/__mocks__"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
+
"format": "prettier '**/*' --ignore-unknown --write",
|
|
30
31
|
"test": "jest",
|
|
31
32
|
"typescript": "tsc --noEmit --project tsconfig.build.json",
|
|
32
33
|
"lint": "eslint --quiet \"**/*.{js,ts,tsx}\"",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@commitlint/config-conventional": "^11.0.0",
|
|
65
|
-
"@react-native/eslint-config": "^0.
|
|
66
|
+
"@react-native/eslint-config": "^0.74.0",
|
|
66
67
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
67
68
|
"@types/jest": "^29.2.1",
|
|
68
69
|
"@types/react": "^18.0.24",
|
|
@@ -71,15 +72,15 @@
|
|
|
71
72
|
"clang-format": "^1.8.0",
|
|
72
73
|
"commitlint": "^11.0.0",
|
|
73
74
|
"eslint": "^8.19.0",
|
|
74
|
-
"eslint-config-prettier": "^
|
|
75
|
+
"eslint-config-prettier": "^8.5.0",
|
|
75
76
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
76
77
|
"eslint-plugin-import": "^2.28.1",
|
|
77
|
-
"eslint-plugin-jest": "^
|
|
78
|
-
"eslint-plugin-prettier": "^
|
|
78
|
+
"eslint-plugin-jest": "^26.5.3",
|
|
79
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
79
80
|
"husky": "^6.0.0",
|
|
80
81
|
"jest": "^29.2.1",
|
|
81
82
|
"pod-install": "^0.1.0",
|
|
82
|
-
"prettier": "^2.
|
|
83
|
+
"prettier": "^2.8.8",
|
|
83
84
|
"react": "18.2.0",
|
|
84
85
|
"react-native": "0.72.4",
|
|
85
86
|
"react-native-builder-bob": "^0.18.0",
|
|
@@ -123,10 +124,7 @@
|
|
|
123
124
|
},
|
|
124
125
|
"prettier": {
|
|
125
126
|
"quoteProps": "consistent",
|
|
126
|
-
"
|
|
127
|
-
"tabWidth": 2,
|
|
128
|
-
"trailingComma": "es5",
|
|
129
|
-
"useTabs": false
|
|
127
|
+
"trailingComma": "all"
|
|
130
128
|
},
|
|
131
129
|
"react-native-builder-bob": {
|
|
132
130
|
"source": "src",
|
package/src/animated.tsx
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from
|
|
2
|
-
import { Animated, Platform, StyleSheet } from
|
|
3
|
-
import Reanimated, { useSharedValue } from
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Animated, Platform, StyleSheet } from "react-native";
|
|
3
|
+
import Reanimated, { useSharedValue } from "react-native-reanimated";
|
|
4
4
|
|
|
5
|
-
import { KeyboardControllerView } from
|
|
6
|
-
import { KeyboardContext } from
|
|
7
|
-
import { useAnimatedValue, useSharedHandlers } from
|
|
8
|
-
import { applyMonkeyPatch, revertMonkeyPatch } from
|
|
5
|
+
import { KeyboardControllerView } from "./bindings";
|
|
6
|
+
import { KeyboardContext } from "./context";
|
|
7
|
+
import { useAnimatedValue, useSharedHandlers } from "./internal";
|
|
8
|
+
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
|
|
9
9
|
import {
|
|
10
10
|
useAnimatedKeyboardHandler,
|
|
11
11
|
useFocusedInputLayoutHandler,
|
|
12
12
|
useFocusedInputTextHandler,
|
|
13
|
-
} from
|
|
13
|
+
} from "./reanimated";
|
|
14
14
|
|
|
15
|
-
import type { KeyboardAnimationContext } from
|
|
15
|
+
import type { KeyboardAnimationContext } from "./context";
|
|
16
16
|
import type {
|
|
17
17
|
FocusedInputHandler,
|
|
18
18
|
FocusedInputLayoutChangedEvent,
|
|
19
19
|
KeyboardControllerProps,
|
|
20
20
|
KeyboardHandler,
|
|
21
21
|
NativeEvent,
|
|
22
|
-
} from
|
|
23
|
-
import type { ViewStyle } from
|
|
22
|
+
} from "./types";
|
|
23
|
+
import type { ViewStyle } from "react-native";
|
|
24
24
|
|
|
25
25
|
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
26
26
|
Animated.createAnimatedComponent(
|
|
27
|
-
KeyboardControllerView
|
|
28
|
-
) as React.FC<KeyboardControllerProps
|
|
27
|
+
KeyboardControllerView,
|
|
28
|
+
) as React.FC<KeyboardControllerProps>,
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
type Styles = {
|
|
@@ -38,8 +38,8 @@ const styles = StyleSheet.create<Styles>({
|
|
|
38
38
|
flex: 1,
|
|
39
39
|
},
|
|
40
40
|
hidden: {
|
|
41
|
-
display:
|
|
42
|
-
position:
|
|
41
|
+
display: "none",
|
|
42
|
+
position: "absolute",
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -102,14 +102,14 @@ export const KeyboardProvider = ({
|
|
|
102
102
|
setInputHandlers,
|
|
103
103
|
setEnabled,
|
|
104
104
|
}),
|
|
105
|
-
[enabled]
|
|
105
|
+
[enabled],
|
|
106
106
|
);
|
|
107
107
|
const style = useMemo(
|
|
108
108
|
() => [
|
|
109
109
|
styles.hidden,
|
|
110
110
|
{ transform: [{ translateX: height }, { translateY: progress }] },
|
|
111
111
|
],
|
|
112
|
-
[]
|
|
112
|
+
[],
|
|
113
113
|
);
|
|
114
114
|
const onKeyboardMove = useMemo(
|
|
115
115
|
() =>
|
|
@@ -122,13 +122,13 @@ export const KeyboardProvider = ({
|
|
|
122
122
|
},
|
|
123
123
|
},
|
|
124
124
|
],
|
|
125
|
-
{ useNativeDriver: true }
|
|
125
|
+
{ useNativeDriver: true },
|
|
126
126
|
),
|
|
127
|
-
[]
|
|
127
|
+
[],
|
|
128
128
|
);
|
|
129
129
|
// handlers
|
|
130
130
|
const updateSharedValues = (event: NativeEvent, platforms: string[]) => {
|
|
131
|
-
|
|
131
|
+
"worklet";
|
|
132
132
|
|
|
133
133
|
if (platforms.includes(Platform.OS)) {
|
|
134
134
|
progressSV.value = event.progress;
|
|
@@ -138,35 +138,35 @@ export const KeyboardProvider = ({
|
|
|
138
138
|
const keyboardHandler = useAnimatedKeyboardHandler(
|
|
139
139
|
{
|
|
140
140
|
onKeyboardMoveStart: (event: NativeEvent) => {
|
|
141
|
-
|
|
141
|
+
"worklet";
|
|
142
142
|
|
|
143
|
-
broadcastKeyboardEvents(
|
|
144
|
-
updateSharedValues(event, [
|
|
143
|
+
broadcastKeyboardEvents("onStart", event);
|
|
144
|
+
updateSharedValues(event, ["ios"]);
|
|
145
145
|
},
|
|
146
146
|
onKeyboardMove: (event: NativeEvent) => {
|
|
147
|
-
|
|
147
|
+
"worklet";
|
|
148
148
|
|
|
149
|
-
broadcastKeyboardEvents(
|
|
150
|
-
updateSharedValues(event, [
|
|
149
|
+
broadcastKeyboardEvents("onMove", event);
|
|
150
|
+
updateSharedValues(event, ["android"]);
|
|
151
151
|
},
|
|
152
152
|
onKeyboardMoveEnd: (event: NativeEvent) => {
|
|
153
|
-
|
|
153
|
+
"worklet";
|
|
154
154
|
|
|
155
|
-
broadcastKeyboardEvents(
|
|
155
|
+
broadcastKeyboardEvents("onEnd", event);
|
|
156
156
|
},
|
|
157
157
|
onKeyboardMoveInteractive: (event: NativeEvent) => {
|
|
158
|
-
|
|
158
|
+
"worklet";
|
|
159
159
|
|
|
160
|
-
updateSharedValues(event, [
|
|
161
|
-
broadcastKeyboardEvents(
|
|
160
|
+
updateSharedValues(event, ["android", "ios"]);
|
|
161
|
+
broadcastKeyboardEvents("onInteractive", event);
|
|
162
162
|
},
|
|
163
163
|
},
|
|
164
|
-
[]
|
|
164
|
+
[],
|
|
165
165
|
);
|
|
166
166
|
const inputLayoutHandler = useFocusedInputLayoutHandler(
|
|
167
167
|
{
|
|
168
168
|
onFocusedInputLayoutChanged: (e) => {
|
|
169
|
-
|
|
169
|
+
"worklet";
|
|
170
170
|
|
|
171
171
|
if (e.target !== -1) {
|
|
172
172
|
layout.value = e;
|
|
@@ -175,17 +175,17 @@ export const KeyboardProvider = ({
|
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
177
|
},
|
|
178
|
-
[]
|
|
178
|
+
[],
|
|
179
179
|
);
|
|
180
180
|
const inputTextHandler = useFocusedInputTextHandler(
|
|
181
181
|
{
|
|
182
182
|
onFocusedInputTextChanged: (e) => {
|
|
183
|
-
|
|
183
|
+
"worklet";
|
|
184
184
|
|
|
185
|
-
broadcastInputEvents(
|
|
185
|
+
broadcastInputEvents("onChangeText", e);
|
|
186
186
|
},
|
|
187
187
|
},
|
|
188
|
-
[]
|
|
188
|
+
[],
|
|
189
189
|
);
|
|
190
190
|
// effects
|
|
191
191
|
useEffect(() => {
|
|
@@ -201,8 +201,8 @@ export const KeyboardProvider = ({
|
|
|
201
201
|
<KeyboardControllerViewAnimated
|
|
202
202
|
enabled={enabled}
|
|
203
203
|
onKeyboardMoveReanimated={keyboardHandler}
|
|
204
|
-
onKeyboardMoveStart={Platform.OS ===
|
|
205
|
-
onKeyboardMove={Platform.OS ===
|
|
204
|
+
onKeyboardMoveStart={Platform.OS === "ios" ? onKeyboardMove : undefined}
|
|
205
|
+
onKeyboardMove={Platform.OS === "android" ? onKeyboardMove : undefined}
|
|
206
206
|
onKeyboardMoveInteractive={onKeyboardMove}
|
|
207
207
|
onFocusedInputLayoutChangedReanimated={inputLayoutHandler}
|
|
208
208
|
onFocusedInputTextChangedReanimated={inputTextHandler}
|
package/src/bindings.native.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { NativeEventEmitter, Platform } from
|
|
1
|
+
import { NativeEventEmitter, Platform } from "react-native";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
KeyboardControllerModule,
|
|
5
5
|
KeyboardControllerProps,
|
|
6
6
|
KeyboardEventsModule,
|
|
7
7
|
KeyboardGestureAreaProps,
|
|
8
|
-
} from
|
|
8
|
+
} from "./types";
|
|
9
9
|
|
|
10
10
|
const LINKING_ERROR =
|
|
11
11
|
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
12
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default:
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
13
|
+
"- You rebuilt the app after installing the package\n" +
|
|
14
|
+
"- You are not using Expo Go\n";
|
|
15
15
|
|
|
16
16
|
const RCTKeyboardController =
|
|
17
|
-
require(
|
|
17
|
+
require("./specs/NativeKeyboardController").default;
|
|
18
18
|
export const KeyboardController = (
|
|
19
19
|
RCTKeyboardController
|
|
20
20
|
? RCTKeyboardController
|
|
@@ -24,7 +24,7 @@ export const KeyboardController = (
|
|
|
24
24
|
get() {
|
|
25
25
|
throw new Error(LINKING_ERROR);
|
|
26
26
|
},
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
28
|
)
|
|
29
29
|
) as KeyboardControllerModule;
|
|
30
30
|
|
|
@@ -32,11 +32,11 @@ const eventEmitter = new NativeEventEmitter(KeyboardController);
|
|
|
32
32
|
|
|
33
33
|
export const KeyboardEvents: KeyboardEventsModule = {
|
|
34
34
|
addListener: (name, cb) =>
|
|
35
|
-
eventEmitter.addListener(
|
|
35
|
+
eventEmitter.addListener("KeyboardController::" + name, cb),
|
|
36
36
|
};
|
|
37
37
|
export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
|
|
38
|
-
require(
|
|
38
|
+
require("./specs/KeyboardControllerViewNativeComponent").default;
|
|
39
39
|
export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
|
|
40
|
-
Platform.OS ===
|
|
41
|
-
? require(
|
|
40
|
+
Platform.OS === "android" && Platform.Version >= 30
|
|
41
|
+
? require("./specs/KeyboardGestureAreaNativeComponent").default
|
|
42
42
|
: ({ children }: KeyboardGestureAreaProps) => children;
|
package/src/bindings.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { View } from
|
|
1
|
+
import { View } from "react-native";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
KeyboardControllerModule,
|
|
5
5
|
KeyboardControllerProps,
|
|
6
6
|
KeyboardEventsModule,
|
|
7
7
|
KeyboardGestureAreaProps,
|
|
8
|
-
} from
|
|
9
|
-
import type { EmitterSubscription } from
|
|
8
|
+
} from "./types";
|
|
9
|
+
import type { EmitterSubscription } from "react-native";
|
|
10
10
|
|
|
11
11
|
const NOOP = () => {};
|
|
12
12
|
export const KeyboardController: KeyboardControllerModule = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useSharedValue } from
|
|
1
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
2
2
|
|
|
3
|
-
import { useKeyboardHandler } from
|
|
3
|
+
import { useKeyboardHandler } from "../../hooks";
|
|
4
4
|
|
|
5
5
|
export const useKeyboardAnimation = () => {
|
|
6
6
|
const heightWhenOpened = useSharedValue(0);
|
|
@@ -11,7 +11,7 @@ export const useKeyboardAnimation = () => {
|
|
|
11
11
|
useKeyboardHandler(
|
|
12
12
|
{
|
|
13
13
|
onStart: (e) => {
|
|
14
|
-
|
|
14
|
+
"worklet";
|
|
15
15
|
|
|
16
16
|
if (e.height > 0) {
|
|
17
17
|
isClosed.value = false;
|
|
@@ -19,18 +19,21 @@ export const useKeyboardAnimation = () => {
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
onMove: (e) => {
|
|
22
|
-
|
|
22
|
+
"worklet";
|
|
23
23
|
|
|
24
24
|
progress.value = e.progress;
|
|
25
25
|
height.value = e.height;
|
|
26
26
|
},
|
|
27
27
|
onEnd: (e) => {
|
|
28
|
-
|
|
28
|
+
"worklet";
|
|
29
29
|
|
|
30
30
|
isClosed.value = e.height === 0;
|
|
31
|
+
|
|
32
|
+
progress.value = e.progress;
|
|
33
|
+
height.value = e.height;
|
|
31
34
|
},
|
|
32
35
|
},
|
|
33
|
-
[]
|
|
36
|
+
[],
|
|
34
37
|
);
|
|
35
38
|
|
|
36
39
|
return { height, progress, heightWhenOpened, isClosed };
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import React, { forwardRef, useCallback, useMemo } from
|
|
2
|
-
import { View, useWindowDimensions } from
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo } from "react";
|
|
2
|
+
import { View, useWindowDimensions } from "react-native";
|
|
3
3
|
import Reanimated, {
|
|
4
|
-
interpolate,
|
|
5
4
|
runOnUI,
|
|
6
5
|
useAnimatedStyle,
|
|
7
6
|
useDerivedValue,
|
|
8
7
|
useSharedValue,
|
|
9
|
-
} from
|
|
8
|
+
} from "react-native-reanimated";
|
|
10
9
|
|
|
11
|
-
import
|
|
10
|
+
import useKeyboardInterpolation from "../hooks/useKeyboardInterpolation";
|
|
12
11
|
|
|
13
|
-
import
|
|
12
|
+
import { useKeyboardAnimation } from "./hooks";
|
|
13
|
+
|
|
14
|
+
import type { LayoutRectangle, ViewProps } from "react-native";
|
|
14
15
|
|
|
15
16
|
type Props = {
|
|
16
17
|
/**
|
|
17
18
|
* Specify how to react to the presence of the keyboard.
|
|
18
19
|
*/
|
|
19
|
-
behavior?:
|
|
20
|
+
behavior?: "height" | "position" | "padding";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Style of the content container when `behavior` is 'position'.
|
|
23
24
|
*/
|
|
24
|
-
contentContainerStyle?: ViewProps[
|
|
25
|
+
contentContainerStyle?: ViewProps["style"];
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Controls whether this `KeyboardAvoidingView` instance should take effect.
|
|
@@ -59,7 +60,7 @@ const KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(
|
|
|
59
60
|
onLayout: onLayoutProps,
|
|
60
61
|
...props
|
|
61
62
|
},
|
|
62
|
-
ref
|
|
63
|
+
ref,
|
|
63
64
|
) => {
|
|
64
65
|
const initialFrame = useSharedValue<LayoutRectangle | null>(null);
|
|
65
66
|
const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
|
|
@@ -68,39 +69,39 @@ const KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(
|
|
|
68
69
|
const { height: screenHeight } = useWindowDimensions();
|
|
69
70
|
|
|
70
71
|
const relativeKeyboardHeight = useCallback(() => {
|
|
71
|
-
|
|
72
|
+
"worklet";
|
|
72
73
|
|
|
73
74
|
const keyboardY =
|
|
74
75
|
screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
|
|
75
76
|
|
|
76
77
|
return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
|
|
77
78
|
}, [screenHeight, keyboardVerticalOffset]);
|
|
79
|
+
const { interpolate } = useKeyboardInterpolation();
|
|
78
80
|
|
|
79
81
|
const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {
|
|
80
|
-
|
|
82
|
+
"worklet";
|
|
81
83
|
|
|
82
84
|
if (keyboard.isClosed.value) {
|
|
83
85
|
initialFrame.value = layout;
|
|
84
86
|
}
|
|
85
87
|
}, []);
|
|
86
|
-
const onLayout = useCallback<NonNullable<ViewProps[
|
|
88
|
+
const onLayout = useCallback<NonNullable<ViewProps["onLayout"]>>(
|
|
87
89
|
(e) => {
|
|
88
90
|
runOnUI(onLayoutWorklet)(e.nativeEvent.layout);
|
|
89
91
|
onLayoutProps?.(e);
|
|
90
92
|
},
|
|
91
|
-
[onLayoutProps]
|
|
93
|
+
[onLayoutProps],
|
|
92
94
|
);
|
|
93
95
|
|
|
94
96
|
const animatedStyle = useAnimatedStyle(() => {
|
|
95
|
-
const bottom = interpolate(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
97
|
+
const bottom = interpolate(keyboard.height.value, [
|
|
98
|
+
0,
|
|
99
|
+
relativeKeyboardHeight(),
|
|
100
|
+
]);
|
|
100
101
|
const bottomHeight = enabled ? bottom : 0;
|
|
101
102
|
|
|
102
103
|
switch (behavior) {
|
|
103
|
-
case
|
|
104
|
+
case "height":
|
|
104
105
|
if (!keyboard.isClosed.value) {
|
|
105
106
|
return {
|
|
106
107
|
height: frame.value.height - bottomHeight,
|
|
@@ -110,21 +111,21 @@ const KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(
|
|
|
110
111
|
|
|
111
112
|
return {};
|
|
112
113
|
|
|
113
|
-
case
|
|
114
|
+
case "position":
|
|
114
115
|
return { bottom: bottomHeight };
|
|
115
116
|
|
|
116
|
-
case
|
|
117
|
+
case "padding":
|
|
117
118
|
return { paddingBottom: bottomHeight };
|
|
118
119
|
|
|
119
120
|
default:
|
|
120
121
|
return {};
|
|
121
122
|
}
|
|
122
123
|
}, [behavior, enabled, relativeKeyboardHeight]);
|
|
123
|
-
const isPositionBehavior = behavior ===
|
|
124
|
+
const isPositionBehavior = behavior === "position";
|
|
124
125
|
const containerStyle = isPositionBehavior ? contentContainerStyle : style;
|
|
125
126
|
const combinedStyles = useMemo(
|
|
126
127
|
() => [containerStyle, animatedStyle],
|
|
127
|
-
[containerStyle, animatedStyle]
|
|
128
|
+
[containerStyle, animatedStyle],
|
|
128
129
|
);
|
|
129
130
|
|
|
130
131
|
if (isPositionBehavior) {
|
|
@@ -145,7 +146,7 @@ const KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(
|
|
|
145
146
|
{children}
|
|
146
147
|
</Reanimated.View>
|
|
147
148
|
);
|
|
148
|
-
}
|
|
149
|
+
},
|
|
149
150
|
);
|
|
150
151
|
|
|
151
152
|
export default KeyboardAvoidingView;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useCallback, useMemo } from
|
|
2
|
-
import { useWindowDimensions } from
|
|
1
|
+
import React, { useCallback, useMemo } from "react";
|
|
2
|
+
import { useWindowDimensions } from "react-native";
|
|
3
3
|
import Reanimated, {
|
|
4
4
|
interpolate,
|
|
5
5
|
scrollTo,
|
|
@@ -8,19 +8,19 @@ import Reanimated, {
|
|
|
8
8
|
useAnimatedScrollHandler,
|
|
9
9
|
useAnimatedStyle,
|
|
10
10
|
useSharedValue,
|
|
11
|
-
} from
|
|
11
|
+
} from "react-native-reanimated";
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
useFocusedInputHandler,
|
|
15
15
|
useReanimatedFocusedInput,
|
|
16
|
-
} from
|
|
16
|
+
} from "react-native-keyboard-controller";
|
|
17
17
|
|
|
18
|
-
import { useSmoothKeyboardHandler } from
|
|
19
|
-
import { debounce } from
|
|
18
|
+
import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
|
|
19
|
+
import { debounce } from "./utils";
|
|
20
20
|
|
|
21
|
-
import type { FC } from
|
|
22
|
-
import type { ScrollViewProps } from
|
|
23
|
-
import type { FocusedInputLayoutChangedEvent } from
|
|
21
|
+
import type { FC } from "react";
|
|
22
|
+
import type { ScrollViewProps } from "react-native";
|
|
23
|
+
import type { FocusedInputLayoutChangedEvent } from "react-native-keyboard-controller";
|
|
24
24
|
|
|
25
25
|
type KeyboardAwareScrollViewProps = {
|
|
26
26
|
bottomOffset?: number;
|
|
@@ -87,7 +87,7 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
87
87
|
position.value = e.contentOffset.y;
|
|
88
88
|
},
|
|
89
89
|
},
|
|
90
|
-
[]
|
|
90
|
+
[],
|
|
91
91
|
);
|
|
92
92
|
|
|
93
93
|
/**
|
|
@@ -95,7 +95,7 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
95
95
|
*/
|
|
96
96
|
const maybeScroll = useCallback(
|
|
97
97
|
(e: number, animated: boolean = false) => {
|
|
98
|
-
|
|
98
|
+
"worklet";
|
|
99
99
|
|
|
100
100
|
const visibleRect = height - keyboardHeight.value;
|
|
101
101
|
const absoluteY = layout.value?.layout.absoluteY || 0;
|
|
@@ -106,7 +106,7 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
106
106
|
const interpolatedScrollTo = interpolate(
|
|
107
107
|
e,
|
|
108
108
|
[initialKeyboardSize.value, keyboardHeight.value],
|
|
109
|
-
[0, keyboardHeight.value - (height - point) + bottomOffset]
|
|
109
|
+
[0, keyboardHeight.value - (height - point) + bottomOffset],
|
|
110
110
|
);
|
|
111
111
|
const targetScrollY =
|
|
112
112
|
Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
|
|
@@ -123,17 +123,17 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
123
123
|
scrollViewAnimatedRef,
|
|
124
124
|
0,
|
|
125
125
|
topOfScreen - positionOnScreen,
|
|
126
|
-
animated
|
|
126
|
+
animated,
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
return 0;
|
|
131
131
|
},
|
|
132
|
-
[bottomOffset]
|
|
132
|
+
[bottomOffset],
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
const onChangeText = useCallback(() => {
|
|
136
|
-
|
|
136
|
+
"worklet";
|
|
137
137
|
|
|
138
138
|
// if typing a text caused layout shift, then we need to ignore this handler
|
|
139
139
|
// because this event will be handled in `useAnimatedReaction` below
|
|
@@ -152,20 +152,20 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
152
152
|
}, [maybeScroll]);
|
|
153
153
|
const onChangeTextHandler = useMemo(
|
|
154
154
|
() => debounce(onChangeText, 200),
|
|
155
|
-
[onChangeText]
|
|
155
|
+
[onChangeText],
|
|
156
156
|
);
|
|
157
157
|
|
|
158
158
|
useFocusedInputHandler(
|
|
159
159
|
{
|
|
160
160
|
onChangeText: onChangeTextHandler,
|
|
161
161
|
},
|
|
162
|
-
[onChangeTextHandler]
|
|
162
|
+
[onChangeTextHandler],
|
|
163
163
|
);
|
|
164
164
|
|
|
165
165
|
useSmoothKeyboardHandler(
|
|
166
166
|
{
|
|
167
167
|
onStart: (e) => {
|
|
168
|
-
|
|
168
|
+
"worklet";
|
|
169
169
|
|
|
170
170
|
const keyboardWillChangeSize =
|
|
171
171
|
keyboardHeight.value !== e.height && e.height > 0;
|
|
@@ -209,18 +209,18 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
209
209
|
}
|
|
210
210
|
},
|
|
211
211
|
onMove: (e) => {
|
|
212
|
-
|
|
212
|
+
"worklet";
|
|
213
213
|
|
|
214
214
|
maybeScroll(e.height);
|
|
215
215
|
},
|
|
216
216
|
onEnd: (e) => {
|
|
217
|
-
|
|
217
|
+
"worklet";
|
|
218
218
|
|
|
219
219
|
keyboardHeight.value = e.height;
|
|
220
220
|
scrollPosition.value = position.value;
|
|
221
221
|
},
|
|
222
222
|
},
|
|
223
|
-
[height, maybeScroll]
|
|
223
|
+
[height, maybeScroll],
|
|
224
224
|
);
|
|
225
225
|
|
|
226
226
|
useAnimatedReaction(
|
|
@@ -237,14 +237,14 @@ const KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({
|
|
|
237
237
|
layout.value = prevLayout;
|
|
238
238
|
}
|
|
239
239
|
},
|
|
240
|
-
[]
|
|
240
|
+
[],
|
|
241
241
|
);
|
|
242
242
|
|
|
243
243
|
const view = useAnimatedStyle(
|
|
244
244
|
() => ({
|
|
245
245
|
paddingBottom: keyboardHeight.value,
|
|
246
246
|
}),
|
|
247
|
-
[]
|
|
247
|
+
[],
|
|
248
248
|
);
|
|
249
249
|
|
|
250
250
|
return (
|