react-native-keyboard-controller 1.2.0 → 1.3.0
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/build.gradle +0 -40
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +44 -8
- package/ios/KeyboardController.xcodeproj/project.pbxproj +2 -2
- package/ios/KeyboardControllerModule.mm +1 -1
- package/ios/KeyboardControllerView.mm +4 -4
- package/lib/commonjs/animated.js +14 -59
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/context.js +28 -0
- package/lib/commonjs/context.js.map +1 -0
- package/lib/commonjs/hooks.js +39 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +39 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +27 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/monkey-patch.js +3 -3
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/native.js +24 -21
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/replicas.js +2 -2
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/commonjs/{KeyboardControllerViewNativeComponent.js → specs/KeyboardControllerViewNativeComponent.js} +0 -0
- package/lib/commonjs/{KeyboardControllerViewNativeComponent.js.map → specs/KeyboardControllerViewNativeComponent.js.map} +0 -0
- package/lib/commonjs/{NativeKeyboardController.js → specs/NativeKeyboardController.js} +0 -0
- package/lib/commonjs/{NativeKeyboardController.js.map → specs/NativeKeyboardController.js.map} +0 -0
- package/lib/commonjs/{NativeStatusBarManagerCompat.js → specs/NativeStatusBarManagerCompat.js} +0 -0
- package/lib/commonjs/{NativeStatusBarManagerCompat.js.map → specs/NativeStatusBarManagerCompat.js.map} +0 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/animated.js +12 -50
- package/lib/module/animated.js.map +1 -1
- package/lib/module/context.js +18 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/hooks.js +20 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +19 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/monkey-patch.js +4 -3
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/native.js +23 -17
- package/lib/module/native.js.map +1 -1
- package/lib/module/replicas.js +1 -1
- package/lib/module/replicas.js.map +1 -1
- package/lib/module/{KeyboardControllerViewNativeComponent.js → specs/KeyboardControllerViewNativeComponent.js} +0 -0
- package/lib/module/{KeyboardControllerViewNativeComponent.js.map → specs/KeyboardControllerViewNativeComponent.js.map} +0 -0
- package/lib/module/{NativeKeyboardController.js → specs/NativeKeyboardController.js} +0 -0
- package/lib/module/{NativeKeyboardController.js.map → specs/NativeKeyboardController.js.map} +0 -0
- package/lib/module/{NativeStatusBarManagerCompat.js → specs/NativeStatusBarManagerCompat.js} +0 -0
- package/lib/module/{NativeStatusBarManagerCompat.js.map → specs/NativeStatusBarManagerCompat.js.map} +0 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/animated.d.ts +1 -17
- package/lib/typescript/context.d.ts +16 -0
- package/lib/typescript/hooks.d.ts +4 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/internal.d.ts +4 -0
- package/lib/typescript/native.d.ts +14 -26
- package/lib/typescript/{KeyboardControllerViewNativeComponent.d.ts → specs/KeyboardControllerViewNativeComponent.d.ts} +0 -0
- package/lib/typescript/{NativeKeyboardController.d.ts → specs/NativeKeyboardController.d.ts} +0 -0
- package/lib/typescript/{NativeStatusBarManagerCompat.d.ts → specs/NativeStatusBarManagerCompat.d.ts} +0 -0
- package/lib/typescript/types.d.ts +23 -0
- package/package.json +17 -20
- package/react-native-keyboard-controller.podspec +2 -1
- package/src/animated.tsx +12 -75
- package/src/context.ts +28 -0
- package/src/hooks.ts +28 -0
- package/src/index.ts +3 -0
- package/src/internal.ts +27 -0
- package/src/{monkey-patch.tsx → monkey-patch.ts} +3 -6
- package/src/native.ts +37 -66
- package/src/replicas.ts +1 -1
- package/src/{KeyboardControllerViewNativeComponent.ts → specs/KeyboardControllerViewNativeComponent.ts} +0 -0
- package/src/{NativeKeyboardController.ts → specs/NativeKeyboardController.ts} +0 -0
- package/src/{NativeStatusBarManagerCompat.ts → specs/NativeStatusBarManagerCompat.ts} +0 -0
- package/src/types.ts +42 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +0 -31
- package/android/src/main/jni/Android.mk +0 -42
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +0 -71
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +0 -35
- package/android/src/main/jni/OnLoad.cpp +0 -9
- package/lib/commonjs/architecture.js +0 -13
- package/lib/commonjs/architecture.js.map +0 -1
- package/lib/module/architecture.js +0 -5
- package/lib/module/architecture.js.map +0 -1
- package/lib/typescript/architecture.d.ts +0 -2
- package/src/architecture.ts +0 -4
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { KeyboardControllerEvents, KeyboardControllerModule, KeyboardEventData } from './types';
|
|
2
2
|
export declare enum AndroidSoftInputModes {
|
|
3
3
|
SOFT_INPUT_ADJUST_NOTHING = 48,
|
|
4
4
|
SOFT_INPUT_ADJUST_PAN = 32,
|
|
5
5
|
SOFT_INPUT_ADJUST_RESIZE = 16,
|
|
6
|
-
SOFT_INPUT_ADJUST_UNSPECIFIED = 0
|
|
6
|
+
SOFT_INPUT_ADJUST_UNSPECIFIED = 0,
|
|
7
|
+
SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,
|
|
8
|
+
SOFT_INPUT_MASK_ADJUST = 240,
|
|
9
|
+
SOFT_INPUT_MASK_STATE = 15,
|
|
10
|
+
SOFT_INPUT_MODE_CHANGED = 512,
|
|
11
|
+
SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,
|
|
12
|
+
SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,
|
|
13
|
+
SOFT_INPUT_STATE_HIDDEN = 2,
|
|
14
|
+
SOFT_INPUT_STATE_UNCHANGED = 1,
|
|
15
|
+
SOFT_INPUT_STATE_UNSPECIFIED = 0,
|
|
16
|
+
SOFT_INPUT_STATE_VISIBLE = 4
|
|
7
17
|
}
|
|
8
|
-
export declare
|
|
9
|
-
progress: number;
|
|
10
|
-
height: number;
|
|
11
|
-
};
|
|
12
|
-
export declare type EventWithName<T> = {
|
|
13
|
-
eventName: string;
|
|
14
|
-
} & T;
|
|
15
|
-
export declare type KeyboardControllerProps = {
|
|
16
|
-
onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
17
|
-
onKeyboardMoveReanimated: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
18
|
-
statusBarTranslucent?: boolean;
|
|
19
|
-
} & ViewProps;
|
|
20
|
-
declare type KeyboardController = {
|
|
21
|
-
setDefaultMode: () => void;
|
|
22
|
-
setInputMode: (mode: AndroidSoftInputModes) => void;
|
|
23
|
-
};
|
|
24
|
-
export declare const KeyboardController: KeyboardController;
|
|
25
|
-
declare type KeyboardControllerEvents = 'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide';
|
|
26
|
-
declare type KeyboardEvent = {
|
|
27
|
-
height: number;
|
|
28
|
-
};
|
|
18
|
+
export declare const KeyboardController: KeyboardControllerModule;
|
|
29
19
|
export declare const KeyboardEvents: {
|
|
30
|
-
addListener: (name: KeyboardControllerEvents, cb: (e:
|
|
20
|
+
addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => import("react-native").EmitterSubscription;
|
|
31
21
|
};
|
|
32
22
|
export declare const KeyboardControllerView: any;
|
|
33
|
-
export declare const useResizeMode: () => void;
|
|
34
|
-
export {};
|
|
File without changes
|
package/lib/typescript/{NativeKeyboardController.d.ts → specs/NativeKeyboardController.d.ts}
RENAMED
|
File without changes
|
package/lib/typescript/{NativeStatusBarManagerCompat.d.ts → specs/NativeStatusBarManagerCompat.d.ts}
RENAMED
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
2
|
+
export declare type NativeEvent = {
|
|
3
|
+
progress: number;
|
|
4
|
+
height: number;
|
|
5
|
+
};
|
|
6
|
+
export declare type EventWithName<T> = {
|
|
7
|
+
eventName: string;
|
|
8
|
+
} & T;
|
|
9
|
+
export declare type KeyboardControllerProps = {
|
|
10
|
+
onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
11
|
+
onKeyboardMoveReanimated: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
12
|
+
statusBarTranslucent?: boolean;
|
|
13
|
+
} & ViewProps;
|
|
14
|
+
export declare type KeyboardControllerModule = {
|
|
15
|
+
setDefaultMode: () => void;
|
|
16
|
+
setInputMode: (mode: number) => void;
|
|
17
|
+
addListener: (eventName: string) => void;
|
|
18
|
+
removeListeners: (count: number) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare type KeyboardControllerEvents = 'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide';
|
|
21
|
+
export declare type KeyboardEventData = {
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
19
|
"!android/.gradle",
|
|
20
|
+
"!android/gradle",
|
|
21
|
+
"!android/gradlew",
|
|
22
|
+
"!android/gradlew.bat",
|
|
20
23
|
"!ios/build",
|
|
21
24
|
"!**/__tests__",
|
|
22
25
|
"!**/__fixtures__",
|
|
@@ -55,8 +58,8 @@
|
|
|
55
58
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
56
59
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
57
60
|
"@types/jest": "^27.4.1",
|
|
58
|
-
"@types/react": "^18.0.
|
|
59
|
-
"@types/react-native": "0.
|
|
61
|
+
"@types/react": "^18.0.21",
|
|
62
|
+
"@types/react-native": "0.70.4",
|
|
60
63
|
"commitlint": "^11.0.0",
|
|
61
64
|
"clang-format": "^1.8.0",
|
|
62
65
|
"eslint": "^7.2.0",
|
|
@@ -66,17 +69,17 @@
|
|
|
66
69
|
"jest": "^27.5.1",
|
|
67
70
|
"pod-install": "^0.1.0",
|
|
68
71
|
"prettier": "^2.6.2",
|
|
69
|
-
"react": "18.
|
|
70
|
-
"react-native": "0.
|
|
72
|
+
"react": "18.1.0",
|
|
73
|
+
"react-native": "0.70.2",
|
|
71
74
|
"react-native-builder-bob": "^0.18.0",
|
|
72
|
-
"react-native-reanimated": "2.
|
|
75
|
+
"react-native-reanimated": "2.10.0",
|
|
73
76
|
"release-it": "^14.2.2",
|
|
74
|
-
"typescript": "^4.
|
|
77
|
+
"typescript": "^4.8.4"
|
|
75
78
|
},
|
|
76
79
|
"peerDependencies": {
|
|
77
80
|
"react": "*",
|
|
78
81
|
"react-native": "*",
|
|
79
|
-
"react-native-reanimated": "
|
|
82
|
+
"react-native-reanimated": ">=2.3.0"
|
|
80
83
|
},
|
|
81
84
|
"jest": {
|
|
82
85
|
"preset": "react-native",
|
|
@@ -153,17 +156,11 @@
|
|
|
153
156
|
]
|
|
154
157
|
},
|
|
155
158
|
"codegenConfig": {
|
|
156
|
-
"
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
{
|
|
163
|
-
"name": "RNKeyboardControllerViewSpec",
|
|
164
|
-
"type": "components",
|
|
165
|
-
"jsSrcsDir": "src"
|
|
166
|
-
}
|
|
167
|
-
]
|
|
159
|
+
"name": "reactnativekeyboardcontroller",
|
|
160
|
+
"type": "all",
|
|
161
|
+
"jsSrcsDir": "./src/specs",
|
|
162
|
+
"android": {
|
|
163
|
+
"javaPackageName": "com.reactnativekeyboardcontroller"
|
|
164
|
+
}
|
|
168
165
|
}
|
|
169
166
|
}
|
|
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
|
|
|
12
12
|
s.license = package["license"]
|
|
13
13
|
s.authors = package["author"]
|
|
14
14
|
|
|
15
|
-
s.platforms = { :ios => "
|
|
15
|
+
s.platforms = { :ios => "11.0" }
|
|
16
16
|
s.source = { :git => "https://github.com/kirillzyusko/react-native-keyboard-controller.git", :tag => "#{s.version}" }
|
|
17
17
|
|
|
18
18
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
@@ -25,6 +25,7 @@ Pod::Spec.new do |s|
|
|
|
25
25
|
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
26
26
|
s.pod_target_xcconfig = {
|
|
27
27
|
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
28
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
28
29
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
29
30
|
}
|
|
30
31
|
|
package/src/animated.tsx
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo, useRef } from 'react';
|
|
2
2
|
import { Animated, StyleSheet, ViewStyle } from 'react-native';
|
|
3
|
-
import Reanimated, {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
KeyboardControllerProps,
|
|
11
|
-
KeyboardControllerView,
|
|
12
|
-
NativeEvent,
|
|
13
|
-
useResizeMode,
|
|
14
|
-
} from './native';
|
|
3
|
+
import Reanimated, { useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
|
|
5
|
+
import { KeyboardContext } from './context';
|
|
6
|
+
import { useAnimatedKeyboardHandler } from './internal';
|
|
7
|
+
import { KeyboardControllerView } from './native';
|
|
8
|
+
|
|
9
|
+
import type { KeyboardControllerProps, NativeEvent } from './types';
|
|
15
10
|
|
|
16
11
|
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
17
12
|
Animated.createAnimatedComponent(
|
|
@@ -19,66 +14,6 @@ const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
|
19
14
|
) as React.FC<KeyboardControllerProps>
|
|
20
15
|
);
|
|
21
16
|
|
|
22
|
-
type AnimatedContext = {
|
|
23
|
-
progress: Animated.Value;
|
|
24
|
-
height: Animated.Value;
|
|
25
|
-
};
|
|
26
|
-
type ReanimatedContext = {
|
|
27
|
-
progress: Reanimated.SharedValue<number>;
|
|
28
|
-
height: Reanimated.SharedValue<number>;
|
|
29
|
-
};
|
|
30
|
-
type KeyboardAnimationContext = {
|
|
31
|
-
animated: AnimatedContext;
|
|
32
|
-
reanimated: ReanimatedContext;
|
|
33
|
-
};
|
|
34
|
-
const defaultContext: KeyboardAnimationContext = {
|
|
35
|
-
animated: {
|
|
36
|
-
progress: new Animated.Value(0),
|
|
37
|
-
height: new Animated.Value(0),
|
|
38
|
-
},
|
|
39
|
-
reanimated: {
|
|
40
|
-
progress: { value: 0 },
|
|
41
|
-
height: { value: 0 },
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
export const KeyboardContext = React.createContext(defaultContext);
|
|
45
|
-
|
|
46
|
-
export const useKeyboardAnimation = (): AnimatedContext => {
|
|
47
|
-
useResizeMode();
|
|
48
|
-
const context = useContext(KeyboardContext);
|
|
49
|
-
|
|
50
|
-
return context.animated;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
54
|
-
useResizeMode();
|
|
55
|
-
const context = useContext(KeyboardContext);
|
|
56
|
-
|
|
57
|
-
return context.reanimated;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(
|
|
61
|
-
handlers: {
|
|
62
|
-
onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
|
|
63
|
-
},
|
|
64
|
-
dependencies?: ReadonlyArray<unknown>
|
|
65
|
-
) {
|
|
66
|
-
const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
|
|
67
|
-
|
|
68
|
-
return useEvent(
|
|
69
|
-
(event: EventWithName<NativeEvent>) => {
|
|
70
|
-
'worklet';
|
|
71
|
-
const { onKeyboardMove } = handlers;
|
|
72
|
-
|
|
73
|
-
if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
|
|
74
|
-
onKeyboardMove(event, context);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
['onKeyboardMove'],
|
|
78
|
-
doDependenciesDiffer
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
17
|
type Styles = {
|
|
83
18
|
container: ViewStyle;
|
|
84
19
|
hidden: ViewStyle;
|
|
@@ -112,10 +47,13 @@ export const KeyboardProvider = ({
|
|
|
112
47
|
children,
|
|
113
48
|
statusBarTranslucent,
|
|
114
49
|
}: KeyboardProviderProps) => {
|
|
50
|
+
// animated values
|
|
115
51
|
const progress = useRef(new Animated.Value(0)).current;
|
|
116
52
|
const height = useRef(new Animated.Value(0)).current;
|
|
53
|
+
// shared values
|
|
117
54
|
const progressSV = useSharedValue(0);
|
|
118
55
|
const heightSV = useSharedValue(0);
|
|
56
|
+
// memo
|
|
119
57
|
const context = useMemo(
|
|
120
58
|
() => ({
|
|
121
59
|
animated: { progress: progress, height: height },
|
|
@@ -130,7 +68,6 @@ export const KeyboardProvider = ({
|
|
|
130
68
|
],
|
|
131
69
|
[]
|
|
132
70
|
);
|
|
133
|
-
|
|
134
71
|
const onKeyboardMove = useMemo(
|
|
135
72
|
() =>
|
|
136
73
|
Animated.event(
|
|
@@ -146,7 +83,7 @@ export const KeyboardProvider = ({
|
|
|
146
83
|
),
|
|
147
84
|
[]
|
|
148
85
|
);
|
|
149
|
-
|
|
86
|
+
// handlers
|
|
150
87
|
const handler = useAnimatedKeyboardHandler(
|
|
151
88
|
{
|
|
152
89
|
onKeyboardMove: (event: NativeEvent) => {
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
5
|
+
|
|
6
|
+
export type AnimatedContext = {
|
|
7
|
+
progress: Animated.Value;
|
|
8
|
+
height: Animated.Value;
|
|
9
|
+
};
|
|
10
|
+
export type ReanimatedContext = {
|
|
11
|
+
progress: SharedValue<number>;
|
|
12
|
+
height: SharedValue<number>;
|
|
13
|
+
};
|
|
14
|
+
export type KeyboardAnimationContext = {
|
|
15
|
+
animated: AnimatedContext;
|
|
16
|
+
reanimated: ReanimatedContext;
|
|
17
|
+
};
|
|
18
|
+
const defaultContext: KeyboardAnimationContext = {
|
|
19
|
+
animated: {
|
|
20
|
+
progress: new Animated.Value(0),
|
|
21
|
+
height: new Animated.Value(0),
|
|
22
|
+
},
|
|
23
|
+
reanimated: {
|
|
24
|
+
progress: { value: 0 },
|
|
25
|
+
height: { value: 0 },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const KeyboardContext = createContext(defaultContext);
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { AnimatedContext, KeyboardContext, ReanimatedContext } from './context';
|
|
4
|
+
import { AndroidSoftInputModes, KeyboardController } from './native';
|
|
5
|
+
|
|
6
|
+
export const useResizeMode = () => {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
KeyboardController.setInputMode(
|
|
9
|
+
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
return () => KeyboardController.setDefaultMode();
|
|
13
|
+
}, []);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const useKeyboardAnimation = (): AnimatedContext => {
|
|
17
|
+
useResizeMode();
|
|
18
|
+
const context = useContext(KeyboardContext);
|
|
19
|
+
|
|
20
|
+
return context.animated;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
24
|
+
useResizeMode();
|
|
25
|
+
const context = useContext(KeyboardContext);
|
|
26
|
+
|
|
27
|
+
return context.reanimated;
|
|
28
|
+
};
|
package/src/index.ts
CHANGED
package/src/internal.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEvent, useHandler } from 'react-native-reanimated';
|
|
2
|
+
|
|
3
|
+
import type { EventWithName, NativeEvent } from './types';
|
|
4
|
+
|
|
5
|
+
export function useAnimatedKeyboardHandler<
|
|
6
|
+
TContext extends Record<string, unknown>
|
|
7
|
+
>(
|
|
8
|
+
handlers: {
|
|
9
|
+
onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
|
|
10
|
+
},
|
|
11
|
+
dependencies?: ReadonlyArray<unknown>
|
|
12
|
+
) {
|
|
13
|
+
const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
|
|
14
|
+
|
|
15
|
+
return useEvent(
|
|
16
|
+
(event: EventWithName<NativeEvent>) => {
|
|
17
|
+
'worklet';
|
|
18
|
+
const { onKeyboardMove } = handlers;
|
|
19
|
+
|
|
20
|
+
if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
|
|
21
|
+
onKeyboardMove(event, context);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
['onKeyboardMove'],
|
|
25
|
+
doDependenciesDiffer
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
2
|
// @ts-expect-error because there is no corresponding type definition
|
|
3
3
|
import * as NativeAndroidManager from 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid';
|
|
4
4
|
|
|
5
|
-
import { isTurboModuleEnabled } from './architecture';
|
|
6
|
-
|
|
7
5
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
8
6
|
|
|
9
|
-
const RCTStatusBarManagerCompat =
|
|
10
|
-
|
|
11
|
-
: NativeModules.StatusBarManagerCompat;
|
|
7
|
+
const RCTStatusBarManagerCompat =
|
|
8
|
+
require('./specs/NativeStatusBarManagerCompat').default;
|
|
12
9
|
|
|
13
10
|
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
14
11
|
// in order to use library on all available platforms we have to monkey patch
|
package/src/native.ts
CHANGED
|
@@ -1,86 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
requireNativeComponent,
|
|
4
|
-
UIManager,
|
|
5
|
-
Platform,
|
|
6
|
-
NativeModules,
|
|
7
|
-
NativeEventEmitter,
|
|
8
|
-
NativeSyntheticEvent,
|
|
9
|
-
ViewProps,
|
|
10
|
-
} from 'react-native';
|
|
1
|
+
import { Platform, NativeEventEmitter } from 'react-native';
|
|
11
2
|
|
|
12
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
KeyboardControllerEvents,
|
|
5
|
+
KeyboardControllerModule,
|
|
6
|
+
KeyboardEventData,
|
|
7
|
+
} from './types';
|
|
13
8
|
|
|
14
9
|
const LINKING_ERROR =
|
|
15
10
|
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
16
11
|
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
17
12
|
'- You rebuilt the app after installing the package\n' +
|
|
18
|
-
'- You are not using Expo
|
|
13
|
+
'- You are not using Expo Go\n';
|
|
19
14
|
|
|
15
|
+
// copied from `android.view.WindowManager.LayoutParams`
|
|
20
16
|
export enum AndroidSoftInputModes {
|
|
21
17
|
SOFT_INPUT_ADJUST_NOTHING = 48,
|
|
22
18
|
SOFT_INPUT_ADJUST_PAN = 32,
|
|
23
19
|
SOFT_INPUT_ADJUST_RESIZE = 16,
|
|
24
20
|
SOFT_INPUT_ADJUST_UNSPECIFIED = 0,
|
|
21
|
+
SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,
|
|
22
|
+
SOFT_INPUT_MASK_ADJUST = 240,
|
|
23
|
+
SOFT_INPUT_MASK_STATE = 15,
|
|
24
|
+
SOFT_INPUT_MODE_CHANGED = 512,
|
|
25
|
+
SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,
|
|
26
|
+
SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,
|
|
27
|
+
SOFT_INPUT_STATE_HIDDEN = 2,
|
|
28
|
+
SOFT_INPUT_STATE_UNCHANGED = 1,
|
|
29
|
+
SOFT_INPUT_STATE_UNSPECIFIED = 0,
|
|
30
|
+
SOFT_INPUT_STATE_VISIBLE = 4,
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// android only
|
|
44
|
-
setDefaultMode: () => void;
|
|
45
|
-
setInputMode: (mode: AndroidSoftInputModes) => void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const ComponentName = 'KeyboardControllerView';
|
|
49
|
-
|
|
50
|
-
const RCTKeyboardController = isTurboModuleEnabled
|
|
51
|
-
? require('./NativeKeyboardController').default
|
|
52
|
-
: NativeModules.KeyboardController;
|
|
53
|
-
export const KeyboardController = RCTKeyboardController as KeyboardController;
|
|
33
|
+
const RCTKeyboardController =
|
|
34
|
+
require('./specs/NativeKeyboardController').default;
|
|
35
|
+
export const KeyboardController = (
|
|
36
|
+
RCTKeyboardController
|
|
37
|
+
? RCTKeyboardController
|
|
38
|
+
: new Proxy(
|
|
39
|
+
{},
|
|
40
|
+
{
|
|
41
|
+
get() {
|
|
42
|
+
throw new Error(LINKING_ERROR);
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
) as KeyboardControllerModule;
|
|
47
|
+
|
|
48
|
+
const eventEmitter = new NativeEventEmitter(KeyboardController);
|
|
54
49
|
|
|
55
|
-
const eventEmitter = new NativeEventEmitter(RCTKeyboardController);
|
|
56
|
-
type KeyboardControllerEvents =
|
|
57
|
-
| 'keyboardWillShow'
|
|
58
|
-
| 'keyboardDidShow'
|
|
59
|
-
| 'keyboardWillHide'
|
|
60
|
-
| 'keyboardDidHide';
|
|
61
|
-
type KeyboardEvent = {
|
|
62
|
-
height: number;
|
|
63
|
-
};
|
|
64
50
|
export const KeyboardEvents = {
|
|
65
51
|
addListener: (
|
|
66
52
|
name: KeyboardControllerEvents,
|
|
67
|
-
cb: (e:
|
|
53
|
+
cb: (e: KeyboardEventData) => void
|
|
68
54
|
) => eventEmitter.addListener('KeyboardController::' + name, cb),
|
|
69
55
|
};
|
|
70
|
-
export const KeyboardControllerView =
|
|
71
|
-
|
|
72
|
-
: UIManager.getViewManagerConfig(ComponentName) != null
|
|
73
|
-
? requireNativeComponent<KeyboardControllerProps>(ComponentName)
|
|
74
|
-
: () => {
|
|
75
|
-
throw new Error(LINKING_ERROR);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const useResizeMode = () => {
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
KeyboardController.setInputMode(
|
|
81
|
-
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return () => KeyboardController.setDefaultMode();
|
|
85
|
-
}, []);
|
|
86
|
-
};
|
|
56
|
+
export const KeyboardControllerView =
|
|
57
|
+
require('./specs/KeyboardControllerViewNativeComponent').default;
|
package/src/replicas.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useWorkletCallback,
|
|
9
9
|
withSpring,
|
|
10
10
|
} from 'react-native-reanimated';
|
|
11
|
-
import { useReanimatedKeyboardAnimation } from './
|
|
11
|
+
import { useReanimatedKeyboardAnimation } from './hooks';
|
|
12
12
|
|
|
13
13
|
import { AndroidSoftInputModes, KeyboardController } from './native';
|
|
14
14
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
// DirectEventHandler events declaration
|
|
4
|
+
|
|
5
|
+
export type NativeEvent = {
|
|
6
|
+
progress: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
export type EventWithName<T> = {
|
|
10
|
+
eventName: string;
|
|
11
|
+
} & T;
|
|
12
|
+
|
|
13
|
+
// native View/Module declarations
|
|
14
|
+
|
|
15
|
+
export type KeyboardControllerProps = {
|
|
16
|
+
onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
17
|
+
// fake prop used to activate reanimated bindings
|
|
18
|
+
onKeyboardMoveReanimated: (
|
|
19
|
+
e: NativeSyntheticEvent<EventWithName<NativeEvent>>
|
|
20
|
+
) => void;
|
|
21
|
+
statusBarTranslucent?: boolean;
|
|
22
|
+
} & ViewProps;
|
|
23
|
+
|
|
24
|
+
export type KeyboardControllerModule = {
|
|
25
|
+
// android only
|
|
26
|
+
setDefaultMode: () => void;
|
|
27
|
+
setInputMode: (mode: number) => void;
|
|
28
|
+
// native event module stuff
|
|
29
|
+
addListener: (eventName: string) => void;
|
|
30
|
+
removeListeners: (count: number) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Event module declarations
|
|
34
|
+
|
|
35
|
+
export type KeyboardControllerEvents =
|
|
36
|
+
| 'keyboardWillShow'
|
|
37
|
+
| 'keyboardDidShow'
|
|
38
|
+
| 'keyboardWillHide'
|
|
39
|
+
| 'keyboardDidHide';
|
|
40
|
+
export type KeyboardEventData = {
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
Binary file
|