@react-native-ohos/react-native-keyboard-controller 1.12.8-beta.9
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/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +19 -0
- package/harmony/keyboard_controller/BuildProfile.ets +17 -0
- package/harmony/keyboard_controller/Index.ets +30 -0
- package/harmony/keyboard_controller/ResourceTable.txt +9 -0
- package/harmony/keyboard_controller/build-profile.json5 +31 -0
- package/harmony/keyboard_controller/consumer-rules.txt +0 -0
- package/harmony/keyboard_controller/hvigorfile.ts +6 -0
- package/harmony/keyboard_controller/obfuscation-rules.txt +18 -0
- package/harmony/keyboard_controller/oh-package-lock.json5 +19 -0
- package/harmony/keyboard_controller/oh-package.json5 +11 -0
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +111 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +98 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +274 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +101 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +64 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +85 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +110 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +84 -0
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +60 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +46 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +48 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +64 -0
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +77 -0
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +45 -0
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +49 -0
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -0
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -0
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +64 -0
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +77 -0
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +67 -0
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +70 -0
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +245 -0
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +119 -0
- package/harmony/keyboard_controller/src/main/ets/Type.ts +62 -0
- package/harmony/keyboard_controller/src/main/module.json +29 -0
- package/harmony/keyboard_controller/src/main/module.json5 +11 -0
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/keyboard_controller/ts.ets +30 -0
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +188 -0
- package/lib/commonjs/animated.js.map +1 -0
- package/lib/commonjs/bindings.js +38 -0
- package/lib/commonjs/bindings.js.map +1 -0
- package/lib/commonjs/bindings.native.js +37 -0
- package/lib/commonjs/bindings.native.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +66 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +102 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +255 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js +40 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js +152 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
- package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
- package/lib/commonjs/components/index.js +42 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/constants.js +27 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/context.js +42 -0
- package/lib/commonjs/context.js.map +1 -0
- package/lib/commonjs/hooks/index.js +104 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js +29 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
- package/lib/commonjs/index.js +116 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal.js +73 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/monkey-patch.android.js +57 -0
- package/lib/commonjs/monkey-patch.android.js.map +1 -0
- package/lib/commonjs/monkey-patch.js +11 -0
- package/lib/commonjs/monkey-patch.js.map +1 -0
- package/lib/commonjs/reanimated.js +12 -0
- package/lib/commonjs/reanimated.js.map +1 -0
- package/lib/commonjs/reanimated.native.js +88 -0
- package/lib/commonjs/reanimated.native.js.map +1 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils.js +9 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/animated.js +180 -0
- package/lib/module/animated.js.map +1 -0
- package/lib/module/bindings.js +32 -0
- package/lib/module/bindings.js.map +1 -0
- package/lib/module/bindings.native.js +31 -0
- package/lib/module/bindings.native.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js +59 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/index.js +95 -0
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js +248 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
- package/lib/module/components/KeyboardStickyView/index.js +33 -0
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/Button.js +62 -0
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/colors.js +15 -0
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/index.js +140 -0
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/types.js +2 -0
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
- package/lib/module/components/hooks/useColorScheme.js +4 -0
- package/lib/module/components/hooks/useColorScheme.js.map +1 -0
- package/lib/module/components/index.js +5 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/constants.js +21 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/context.js +35 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/hooks/index.js +68 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useWindowDimensions/index.android.js +22 -0
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
- package/lib/module/hooks/useWindowDimensions/index.js +2 -0
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
- package/lib/module/index.js +10 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal.js +66 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/monkey-patch.android.js +47 -0
- package/lib/module/monkey-patch.android.js.map +1 -0
- package/lib/module/monkey-patch.js +5 -0
- package/lib/module/monkey-patch.js.map +1 -0
- package/lib/module/reanimated.js +6 -0
- package/lib/module/reanimated.js.map +1 -0
- package/lib/module/reanimated.native.js +78 -0
- package/lib/module/reanimated.native.js.map +1 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeKeyboardController.js +3 -0
- package/lib/module/specs/NativeKeyboardController.js.map +1 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils.js +2 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/animated.d.ts +31 -0
- package/lib/typescript/bindings.d.ts +12 -0
- package/lib/typescript/bindings.native.d.ts +12 -0
- package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +6 -0
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +50 -0
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +25 -0
- package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
- package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
- package/lib/typescript/components/KeyboardStickyView/index.d.ts +35 -0
- package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
- package/lib/typescript/components/KeyboardToolbar/Button.d.ts +15 -0
- package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
- package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +50 -0
- package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
- package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
- package/lib/typescript/components/index.d.ts +8 -0
- package/lib/typescript/constants.d.ts +16 -0
- package/lib/typescript/context.d.ts +23 -0
- package/lib/typescript/hooks/index.d.ts +17 -0
- package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
- package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/internal.d.ts +30 -0
- package/lib/typescript/monkey-patch.android.d.ts +2 -0
- package/lib/typescript/monkey-patch.d.ts +2 -0
- package/lib/typescript/reanimated.d.ts +5 -0
- package/lib/typescript/reanimated.native.d.ts +7 -0
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +53 -0
- package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
- package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
- package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
- package/lib/typescript/types.d.ts +133 -0
- package/lib/typescript/utils.d.ts +1 -0
- package/package.json +178 -0
- package/react-native-keyboard-controller.podspec +61 -0
- package/src/animated.tsx +253 -0
- package/src/bindings.native.ts +57 -0
- package/src/bindings.ts +38 -0
- package/src/components/KeyboardAvoidingView/hooks.ts +58 -0
- package/src/components/KeyboardAvoidingView/index.tsx +156 -0
- package/src/components/KeyboardAwareScrollView/index.tsx +373 -0
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
- package/src/components/KeyboardStickyView/index.tsx +57 -0
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
- package/src/components/KeyboardToolbar/Button.tsx +98 -0
- package/src/components/KeyboardToolbar/colors.native.ts +37 -0
- package/src/components/KeyboardToolbar/colors.ts +16 -0
- package/src/components/KeyboardToolbar/index.tsx +211 -0
- package/src/components/KeyboardToolbar/types.ts +40 -0
- package/src/components/hooks/useColorScheme.ts +5 -0
- package/src/components/index.ts +11 -0
- package/src/constants.ts +19 -0
- package/src/context.ts +65 -0
- package/src/hooks/index.ts +90 -0
- package/src/hooks/useWindowDimensions/index.android.ts +33 -0
- package/src/hooks/useWindowDimensions/index.ts +1 -0
- package/src/index.ts +21 -0
- package/src/internal.ts +84 -0
- package/src/monkey-patch.android.ts +44 -0
- package/src/monkey-patch.ts +4 -0
- package/src/reanimated.native.ts +132 -0
- package/src/reanimated.ts +29 -0
- package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -0
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -0
- package/src/specs/NativeKeyboardController.ts +19 -0
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
- package/src/types.ts +211 -0
- package/src/utils.ts +1 -0
package/src/animated.tsx
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Animated, Platform, StyleSheet } from "react-native";
|
|
3
|
+
import Reanimated, { useSharedValue, Easing, withTiming } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import { KeyboardControllerView } from "./bindings";
|
|
6
|
+
import { KeyboardContext } from "./context";
|
|
7
|
+
import { useAnimatedValue, useSharedHandlers } from "./internal";
|
|
8
|
+
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
|
|
9
|
+
import {
|
|
10
|
+
useAnimatedKeyboardHandler,
|
|
11
|
+
useFocusedInputLayoutHandler,
|
|
12
|
+
useFocusedInputSelectionHandler,
|
|
13
|
+
useFocusedInputTextHandler,
|
|
14
|
+
} from "./reanimated";
|
|
15
|
+
|
|
16
|
+
import type { KeyboardAnimationContext } from "./context";
|
|
17
|
+
import type {
|
|
18
|
+
FocusedInputHandler,
|
|
19
|
+
FocusedInputLayoutChangedEvent,
|
|
20
|
+
KeyboardControllerProps,
|
|
21
|
+
KeyboardHandler,
|
|
22
|
+
NativeEvent,
|
|
23
|
+
} from "./types";
|
|
24
|
+
import type { ViewStyle } from "react-native";
|
|
25
|
+
|
|
26
|
+
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
27
|
+
Animated.createAnimatedComponent(
|
|
28
|
+
KeyboardControllerView,
|
|
29
|
+
) as React.FC<KeyboardControllerProps>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
type Styles = {
|
|
33
|
+
container: ViewStyle;
|
|
34
|
+
hidden: ViewStyle;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create<Styles>({
|
|
38
|
+
container: {
|
|
39
|
+
flex: 1,
|
|
40
|
+
},
|
|
41
|
+
hidden: {
|
|
42
|
+
display: "none",
|
|
43
|
+
position: "absolute",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
type KeyboardProviderProps = {
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Set the value to `true`, if you use translucent status bar on Android.
|
|
51
|
+
* If you already control status bar translucency via `react-native-screens`
|
|
52
|
+
* or `StatusBar` component from `react-native`, you can ignore it.
|
|
53
|
+
* Defaults to `false`.
|
|
54
|
+
*
|
|
55
|
+
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
|
|
56
|
+
* @platform android
|
|
57
|
+
*/
|
|
58
|
+
statusBarTranslucent?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Set the value to `true`, if you use translucent navigation bar on Android.
|
|
61
|
+
* Defaults to `false`.
|
|
62
|
+
*
|
|
63
|
+
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
|
|
64
|
+
* @platform android
|
|
65
|
+
*/
|
|
66
|
+
navigationBarTranslucent?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* A boolean prop indicating whether the module is enabled. It indicate only initial state,
|
|
69
|
+
* i. e. if you try to change this prop after component mount it will not have any effect.
|
|
70
|
+
* To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.
|
|
71
|
+
* Defaults to `true`.
|
|
72
|
+
*/
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package
|
|
77
|
+
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details
|
|
78
|
+
const OS = Platform.OS;
|
|
79
|
+
|
|
80
|
+
export const KeyboardProvider = ({
|
|
81
|
+
children,
|
|
82
|
+
statusBarTranslucent,
|
|
83
|
+
navigationBarTranslucent,
|
|
84
|
+
enabled: initiallyEnabled = true,
|
|
85
|
+
}: KeyboardProviderProps) => {
|
|
86
|
+
// state
|
|
87
|
+
const [enabled, setEnabled] = useState(initiallyEnabled);
|
|
88
|
+
// animated values
|
|
89
|
+
const progress = useAnimatedValue(0);
|
|
90
|
+
const height = useAnimatedValue(0);
|
|
91
|
+
// shared values
|
|
92
|
+
const progressSV = useSharedValue(0);
|
|
93
|
+
const heightSV = useSharedValue(0);
|
|
94
|
+
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
|
|
95
|
+
const [setKeyboardHandlers, broadcastKeyboardEvents] =
|
|
96
|
+
useSharedHandlers<KeyboardHandler>();
|
|
97
|
+
const [setInputHandlers, broadcastInputEvents] =
|
|
98
|
+
useSharedHandlers<FocusedInputHandler>();
|
|
99
|
+
// memo
|
|
100
|
+
const context = useMemo<KeyboardAnimationContext>(
|
|
101
|
+
() => ({
|
|
102
|
+
enabled,
|
|
103
|
+
animated: { progress: progress, height: Animated.multiply(height, -1) },
|
|
104
|
+
reanimated: { progress: progressSV, height: heightSV },
|
|
105
|
+
layout,
|
|
106
|
+
setKeyboardHandlers,
|
|
107
|
+
setInputHandlers,
|
|
108
|
+
setEnabled,
|
|
109
|
+
}),
|
|
110
|
+
[enabled],
|
|
111
|
+
);
|
|
112
|
+
const style = useMemo(
|
|
113
|
+
() => [
|
|
114
|
+
styles.hidden,
|
|
115
|
+
{ transform: [{ translateX: height }, { translateY: progress }] },
|
|
116
|
+
],
|
|
117
|
+
[],
|
|
118
|
+
);
|
|
119
|
+
const onKeyboardMove = useMemo(
|
|
120
|
+
() =>
|
|
121
|
+
Animated.event(
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
nativeEvent: {
|
|
125
|
+
progress,
|
|
126
|
+
height,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
{ useNativeDriver: Platform.OS as string == 'harmony' ? false : true },
|
|
131
|
+
),
|
|
132
|
+
[],
|
|
133
|
+
);
|
|
134
|
+
// handlers
|
|
135
|
+
const updateSharedValues = (event: NativeEvent, platforms: string[]) => {
|
|
136
|
+
"worklet";
|
|
137
|
+
|
|
138
|
+
if (platforms.includes(OS)) {
|
|
139
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
140
|
+
if (Platform.OS as string == 'harmony') {
|
|
141
|
+
const dur = 460
|
|
142
|
+
progressSV.value = withTiming(event.progress, { duration: dur, easing: Easing.out(Easing.exp) });
|
|
143
|
+
heightSV.value = withTiming(-event.height, { duration: dur, easing: Easing.out(Easing.exp) });
|
|
144
|
+
} else {
|
|
145
|
+
progressSV.value = event.progress;
|
|
146
|
+
heightSV.value = -event.height;
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const keyboardHandler = useAnimatedKeyboardHandler(
|
|
152
|
+
{
|
|
153
|
+
onKeyboardMoveStart: (event: NativeEvent) => {
|
|
154
|
+
"worklet";
|
|
155
|
+
|
|
156
|
+
broadcastKeyboardEvents("onStart", event);
|
|
157
|
+
updateSharedValues(event, ["ios"]);
|
|
158
|
+
},
|
|
159
|
+
onKeyboardMove: (event: NativeEvent) => {
|
|
160
|
+
"worklet";
|
|
161
|
+
|
|
162
|
+
broadcastKeyboardEvents("onMove", event);
|
|
163
|
+
updateSharedValues(event, ["android"]);
|
|
164
|
+
},
|
|
165
|
+
onKeyboardMoveEnd: (event: NativeEvent) => {
|
|
166
|
+
"worklet";
|
|
167
|
+
broadcastKeyboardEvents("onEnd", event);
|
|
168
|
+
updateSharedValues(event, ['harmony']);
|
|
169
|
+
},
|
|
170
|
+
onKeyboardMoveInteractive: (event: NativeEvent) => {
|
|
171
|
+
"worklet";
|
|
172
|
+
|
|
173
|
+
updateSharedValues(event, ["android", "ios"]);
|
|
174
|
+
broadcastKeyboardEvents("onInteractive", event);
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
[],
|
|
178
|
+
);
|
|
179
|
+
const inputLayoutHandler = useFocusedInputLayoutHandler(
|
|
180
|
+
{
|
|
181
|
+
onFocusedInputLayoutChanged: (e) => {
|
|
182
|
+
"worklet";
|
|
183
|
+
|
|
184
|
+
if (e.target !== -1) {
|
|
185
|
+
layout.value = e;
|
|
186
|
+
} else {
|
|
187
|
+
layout.value = null;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
[],
|
|
192
|
+
);
|
|
193
|
+
const inputTextHandler = useFocusedInputTextHandler(
|
|
194
|
+
{
|
|
195
|
+
onFocusedInputTextChanged: (e) => {
|
|
196
|
+
"worklet";
|
|
197
|
+
|
|
198
|
+
broadcastInputEvents("onChangeText", e);
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
[],
|
|
202
|
+
);
|
|
203
|
+
const inputSelectionHandler = useFocusedInputSelectionHandler(
|
|
204
|
+
{
|
|
205
|
+
onFocusedInputSelectionChanged: (e) => {
|
|
206
|
+
"worklet";
|
|
207
|
+
broadcastInputEvents("onSelectionChange", e);
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
[],
|
|
211
|
+
);
|
|
212
|
+
// effects
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (enabled) {
|
|
215
|
+
applyMonkeyPatch();
|
|
216
|
+
} else {
|
|
217
|
+
revertMonkeyPatch();
|
|
218
|
+
}
|
|
219
|
+
}, [enabled]);
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<KeyboardContext.Provider value={context}>
|
|
223
|
+
<KeyboardControllerViewAnimated
|
|
224
|
+
enabled={enabled}
|
|
225
|
+
onKeyboardMoveReanimated={keyboardHandler}
|
|
226
|
+
onKeyboardMoveStart={OS === "ios" ? onKeyboardMove : undefined}
|
|
227
|
+
onKeyboardMove={OS === "android" ? onKeyboardMove : undefined}
|
|
228
|
+
onKeyboardMoveInteractive={onKeyboardMove}
|
|
229
|
+
onKeyboardMoveEnd={OS as string === "harmony" ? onKeyboardMove : undefined}
|
|
230
|
+
onFocusedInputLayoutChangedReanimated={inputLayoutHandler}
|
|
231
|
+
onFocusedInputTextChangedReanimated={inputTextHandler}
|
|
232
|
+
onFocusedInputSelectionChangedReanimated={inputSelectionHandler}
|
|
233
|
+
navigationBarTranslucent={navigationBarTranslucent}
|
|
234
|
+
statusBarTranslucent={statusBarTranslucent}
|
|
235
|
+
style={styles.container}
|
|
236
|
+
>
|
|
237
|
+
<Reanimated.View style={styles.container}>{children}</Reanimated.View>
|
|
238
|
+
{/* {children} */}
|
|
239
|
+
</KeyboardControllerViewAnimated>
|
|
240
|
+
<Animated.View
|
|
241
|
+
// we are using this small hack, because if the component (where
|
|
242
|
+
// animated value has been used) is unmounted, then animation will
|
|
243
|
+
// stop receiving events (seems like it's react-native optimization).
|
|
244
|
+
// So we need to keep a reference to the animated value, to keep it's
|
|
245
|
+
// always mounted (keep a reference to an animated value).
|
|
246
|
+
//
|
|
247
|
+
// To test why it's needed, try to open screen which consumes Animated.Value
|
|
248
|
+
// then close it and open it again (for example 'Animated transition').
|
|
249
|
+
style={style}
|
|
250
|
+
/>
|
|
251
|
+
</KeyboardContext.Provider>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { NativeEventEmitter, Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FocusedInputEventsModule,
|
|
5
|
+
KeyboardControllerModule,
|
|
6
|
+
KeyboardControllerProps,
|
|
7
|
+
KeyboardEventsModule,
|
|
8
|
+
KeyboardGestureAreaProps,
|
|
9
|
+
WindowDimensionsEventsModule,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
const LINKING_ERROR =
|
|
13
|
+
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
14
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
15
|
+
"- You rebuilt the app after installing the package\n" +
|
|
16
|
+
"- You are not using Expo Go\n";
|
|
17
|
+
|
|
18
|
+
const RCTKeyboardController =
|
|
19
|
+
require("./specs/NativeKeyboardController").default;
|
|
20
|
+
export const KeyboardController = (
|
|
21
|
+
RCTKeyboardController
|
|
22
|
+
? RCTKeyboardController
|
|
23
|
+
: new Proxy(
|
|
24
|
+
{},
|
|
25
|
+
{
|
|
26
|
+
get() {
|
|
27
|
+
throw new Error(LINKING_ERROR);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
)
|
|
31
|
+
) as KeyboardControllerModule;
|
|
32
|
+
|
|
33
|
+
const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
|
|
34
|
+
const eventEmitter = new NativeEventEmitter(KeyboardController);
|
|
35
|
+
|
|
36
|
+
export const KeyboardEvents: KeyboardEventsModule = {
|
|
37
|
+
addListener: (name, cb) =>
|
|
38
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
|
|
42
|
+
* Use it with cautious.
|
|
43
|
+
*/
|
|
44
|
+
export const FocusedInputEvents: FocusedInputEventsModule = {
|
|
45
|
+
addListener: (name, cb) =>
|
|
46
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
47
|
+
};
|
|
48
|
+
export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
|
|
49
|
+
addListener: (name, cb) =>
|
|
50
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
51
|
+
};
|
|
52
|
+
export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
|
|
53
|
+
require("./specs/KeyboardControllerViewNativeComponent").default;
|
|
54
|
+
export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
|
|
55
|
+
Platform.OS === "android" && Platform.Version >= 30
|
|
56
|
+
? require("./specs/KeyboardGestureAreaNativeComponent").default
|
|
57
|
+
: ({ children }: KeyboardGestureAreaProps) => children;
|
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { View } from "react-native";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FocusedInputEventsModule,
|
|
5
|
+
KeyboardControllerModule,
|
|
6
|
+
KeyboardControllerProps,
|
|
7
|
+
KeyboardEventsModule,
|
|
8
|
+
KeyboardGestureAreaProps,
|
|
9
|
+
WindowDimensionsEventsModule,
|
|
10
|
+
} from "./types";
|
|
11
|
+
import type { EmitterSubscription } from "react-native";
|
|
12
|
+
|
|
13
|
+
const NOOP = () => {};
|
|
14
|
+
export const KeyboardController: KeyboardControllerModule = {
|
|
15
|
+
setDefaultMode: NOOP,
|
|
16
|
+
setInputMode: NOOP,
|
|
17
|
+
dismiss: NOOP,
|
|
18
|
+
setFocusTo: NOOP,
|
|
19
|
+
addListener: NOOP,
|
|
20
|
+
removeListeners: NOOP,
|
|
21
|
+
};
|
|
22
|
+
export const KeyboardEvents: KeyboardEventsModule = {
|
|
23
|
+
addListener: () => ({ remove: NOOP } as EmitterSubscription),
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
|
|
27
|
+
* Use it with cautious.
|
|
28
|
+
*/
|
|
29
|
+
export const FocusedInputEvents: FocusedInputEventsModule = {
|
|
30
|
+
addListener: () => ({ remove: NOOP } as EmitterSubscription),
|
|
31
|
+
};
|
|
32
|
+
export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
|
|
33
|
+
addListener: () => ({ remove: NOOP } as EmitterSubscription),
|
|
34
|
+
};
|
|
35
|
+
export const KeyboardControllerView =
|
|
36
|
+
View as unknown as React.FC<KeyboardControllerProps>;
|
|
37
|
+
export const KeyboardGestureArea =
|
|
38
|
+
View as unknown as React.FC<KeyboardGestureAreaProps>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
2
|
+
|
|
3
|
+
import {useKeyboardHandler} from "../../hooks";
|
|
4
|
+
import {useKeyboardContext} from "../../context";
|
|
5
|
+
import { Platform } from "react-native";
|
|
6
|
+
|
|
7
|
+
export const useKeyboardAnimation = () => {
|
|
8
|
+
const { reanimated } = useKeyboardContext();
|
|
9
|
+
const heightWhenOpened = useSharedValue(-reanimated.height.value);
|
|
10
|
+
const height = useSharedValue(-reanimated.height.value);
|
|
11
|
+
const progress = useSharedValue(reanimated.progress.value);
|
|
12
|
+
const isClosed = useSharedValue(reanimated.progress.value === 0);
|
|
13
|
+
|
|
14
|
+
useKeyboardHandler(
|
|
15
|
+
{
|
|
16
|
+
onStart: (e) => {
|
|
17
|
+
"worklet";
|
|
18
|
+
|
|
19
|
+
if (e.height > 0) {
|
|
20
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
21
|
+
isClosed.value = false;
|
|
22
|
+
heightWhenOpened.value = e.height;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
onMove: (e) => {
|
|
26
|
+
"worklet";
|
|
27
|
+
|
|
28
|
+
progress.value = e.progress;
|
|
29
|
+
height.value = e.height;
|
|
30
|
+
},
|
|
31
|
+
onEnd: (e) => {
|
|
32
|
+
"worklet";
|
|
33
|
+
if(Platform.OS as string === 'harmony'){
|
|
34
|
+
heightWhenOpened.value = e.height;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isClosed.value = e.height === 0;
|
|
38
|
+
|
|
39
|
+
// `height` update happens in `onMove` handler
|
|
40
|
+
// in `onEnd` we need to update only if `onMove`
|
|
41
|
+
// wasn't called (i. e. duration === 0)
|
|
42
|
+
//
|
|
43
|
+
// we can not call this code without condition below
|
|
44
|
+
// because in some corner cases (iOS with `secureTextEntry`)
|
|
45
|
+
// `onEnd` can be emitted before `onMove` and in this case
|
|
46
|
+
// it may lead to choppy/glitchy/jumpy UI
|
|
47
|
+
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
|
|
48
|
+
if (e.duration === 0) {
|
|
49
|
+
progress.value = e.progress;
|
|
50
|
+
height.value = e.height;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
[],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return { height, progress, heightWhenOpened, isClosed };
|
|
58
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import Reanimated, {
|
|
4
|
+
interpolate,
|
|
5
|
+
runOnUI,
|
|
6
|
+
useAnimatedStyle,
|
|
7
|
+
useDerivedValue,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
} from "react-native-reanimated";
|
|
10
|
+
|
|
11
|
+
import { useWindowDimensions } from "../../hooks";
|
|
12
|
+
|
|
13
|
+
import { useKeyboardAnimation } from "./hooks";
|
|
14
|
+
|
|
15
|
+
import type { LayoutRectangle, ViewProps } from "react-native";
|
|
16
|
+
|
|
17
|
+
export type KeyboardAvoidingViewProps = {
|
|
18
|
+
/**
|
|
19
|
+
* Specify how to react to the presence of the keyboard.
|
|
20
|
+
*/
|
|
21
|
+
behavior?: "height" | "position" | "padding";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Style of the content container when `behavior` is 'position'.
|
|
25
|
+
*/
|
|
26
|
+
contentContainerStyle?: ViewProps["style"];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Controls whether this `KeyboardAvoidingView` instance should take effect.
|
|
30
|
+
* This is useful when more than one is on the screen. Defaults to true.
|
|
31
|
+
*/
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Distance between the top of the user screen and the React Native view. This
|
|
36
|
+
* may be non-zero in some cases. Defaults to 0.
|
|
37
|
+
*/
|
|
38
|
+
keyboardVerticalOffset?: number;
|
|
39
|
+
} & ViewProps;
|
|
40
|
+
|
|
41
|
+
const defaultLayout: LayoutRectangle = {
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0,
|
|
44
|
+
width: 0,
|
|
45
|
+
height: 0,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* View that moves out of the way when the keyboard appears by automatically
|
|
50
|
+
* adjusting its height, position, or bottom padding.
|
|
51
|
+
*/
|
|
52
|
+
const KeyboardAvoidingView = forwardRef<
|
|
53
|
+
View,
|
|
54
|
+
React.PropsWithChildren<KeyboardAvoidingViewProps>
|
|
55
|
+
>(
|
|
56
|
+
(
|
|
57
|
+
{
|
|
58
|
+
behavior,
|
|
59
|
+
children,
|
|
60
|
+
contentContainerStyle,
|
|
61
|
+
enabled = true,
|
|
62
|
+
keyboardVerticalOffset = 0,
|
|
63
|
+
style,
|
|
64
|
+
onLayout: onLayoutProps,
|
|
65
|
+
...props
|
|
66
|
+
},
|
|
67
|
+
ref,
|
|
68
|
+
) => {
|
|
69
|
+
const initialFrame = useSharedValue<LayoutRectangle | null>(null);
|
|
70
|
+
const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
|
|
71
|
+
|
|
72
|
+
const keyboard = useKeyboardAnimation();
|
|
73
|
+
const { height: screenHeight } = useWindowDimensions();
|
|
74
|
+
|
|
75
|
+
const relativeKeyboardHeight = useCallback(() => {
|
|
76
|
+
"worklet";
|
|
77
|
+
|
|
78
|
+
const keyboardY =
|
|
79
|
+
screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
|
|
80
|
+
|
|
81
|
+
return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
|
|
82
|
+
}, [screenHeight, keyboardVerticalOffset]);
|
|
83
|
+
|
|
84
|
+
const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {
|
|
85
|
+
"worklet";
|
|
86
|
+
|
|
87
|
+
if (keyboard.isClosed.value || initialFrame.value === null) {
|
|
88
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
89
|
+
initialFrame.value = layout;
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
const onLayout = useCallback<NonNullable<ViewProps["onLayout"]>>(
|
|
93
|
+
(e) => {
|
|
94
|
+
runOnUI(onLayoutWorklet)(e.nativeEvent.layout);
|
|
95
|
+
onLayoutProps?.(e);
|
|
96
|
+
},
|
|
97
|
+
[onLayoutProps],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
101
|
+
const bottom = interpolate(
|
|
102
|
+
keyboard.progress.value,
|
|
103
|
+
[0, 1],
|
|
104
|
+
[0, relativeKeyboardHeight()],
|
|
105
|
+
);
|
|
106
|
+
const bottomHeight = enabled ? bottom : 0;
|
|
107
|
+
|
|
108
|
+
switch (behavior) {
|
|
109
|
+
case "height":
|
|
110
|
+
if (!keyboard.isClosed.value) {
|
|
111
|
+
return {
|
|
112
|
+
height: frame.value.height - bottomHeight,
|
|
113
|
+
flex: 0,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {};
|
|
118
|
+
|
|
119
|
+
case "position":
|
|
120
|
+
return { bottom: bottomHeight };
|
|
121
|
+
|
|
122
|
+
case "padding":
|
|
123
|
+
return { paddingBottom: bottomHeight };
|
|
124
|
+
default:
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
}, [behavior, enabled, relativeKeyboardHeight]);
|
|
128
|
+
const isPositionBehavior = behavior === "position";
|
|
129
|
+
const containerStyle = isPositionBehavior ? contentContainerStyle : style;
|
|
130
|
+
const combinedStyles = useMemo(
|
|
131
|
+
() => [containerStyle, animatedStyle],
|
|
132
|
+
[containerStyle, animatedStyle],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (isPositionBehavior) {
|
|
136
|
+
return (
|
|
137
|
+
<View ref={ref} style={style} onLayout={onLayout} {...props}>
|
|
138
|
+
<Reanimated.View style={combinedStyles}>{children}</Reanimated.View>
|
|
139
|
+
</View>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Reanimated.View
|
|
145
|
+
ref={ref}
|
|
146
|
+
onLayout={onLayout}
|
|
147
|
+
style={combinedStyles}
|
|
148
|
+
{...props}
|
|
149
|
+
>
|
|
150
|
+
{children}
|
|
151
|
+
</Reanimated.View>
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
export default KeyboardAvoidingView;
|