@react-native-ohos/react-native-keyboard-controller 1.12.8 → 1.12.10-rc.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/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +603 -19
- package/harmony/keyboard_controller/BuildProfile.ets +16 -16
- package/harmony/keyboard_controller/Index.ets +8 -29
- package/harmony/keyboard_controller/ResourceTable.txt +8 -8
- package/harmony/keyboard_controller/build-profile.json5 +31 -31
- package/harmony/keyboard_controller/hvigorfile.ts +6 -6
- package/harmony/keyboard_controller/obfuscation-rules.txt +17 -17
- package/harmony/keyboard_controller/oh-package-lock.json5 +28 -18
- package/harmony/keyboard_controller/oh-package.json5 +11 -11
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +119 -96
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -111
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -98
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +837 -274
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +152 -101
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -64
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -85
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +88 -109
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -84
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -60
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -46
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -48
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -45
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -49
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -186
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -112
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +45 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +49 -70
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +405 -245
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +107 -119
- package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -62
- package/harmony/keyboard_controller/src/main/module.json +29 -29
- package/harmony/keyboard_controller/src/main/module.json5 +11 -11
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/keyboard_controller/ts.ets +8 -29
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +4 -16
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/bindings.js +3 -3
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/bindings.native.js +3 -3
- package/lib/commonjs/bindings.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +39 -39
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -1
- 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/index.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +18 -18
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +4 -4
- 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.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js.map +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 +5 -17
- package/lib/module/animated.js.map +1 -1
- package/lib/module/bindings.js +3 -3
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/bindings.native.js +3 -3
- package/lib/module/bindings.native.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +39 -39
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +3 -3
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/module/components/hooks/useColorScheme.js.map +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +18 -18
- package/lib/module/internal.js.map +1 -1
- package/lib/module/monkey-patch.android.js +4 -4
- 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.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- 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/types.d.ts +1 -0
- package/package.json +181 -178
- package/src/animated.tsx +246 -253
- package/src/bindings.native.ts +57 -57
- package/src/bindings.ts +38 -38
- package/src/components/KeyboardAvoidingView/hooks.ts +58 -58
- package/src/components/KeyboardAvoidingView/index.tsx +156 -156
- package/src/components/KeyboardAwareScrollView/index.tsx +373 -373
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
- package/src/components/KeyboardStickyView/index.tsx +57 -57
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -80
- package/src/components/KeyboardToolbar/Button.tsx +98 -98
- package/src/components/KeyboardToolbar/colors.native.ts +37 -37
- package/src/components/KeyboardToolbar/colors.ts +16 -16
- package/src/components/KeyboardToolbar/index.tsx +211 -211
- package/src/components/KeyboardToolbar/types.ts +40 -40
- package/src/components/hooks/useColorScheme.ts +5 -5
- package/src/components/index.ts +11 -11
- package/src/constants.ts +19 -19
- package/src/context.ts +65 -65
- package/src/hooks/index.ts +90 -90
- package/src/hooks/useWindowDimensions/index.android.ts +33 -33
- package/src/hooks/useWindowDimensions/index.ts +1 -1
- package/src/index.ts +21 -21
- package/src/internal.ts +84 -84
- package/src/monkey-patch.android.ts +44 -44
- package/src/monkey-patch.ts +4 -4
- package/src/reanimated.native.ts +132 -132
- package/src/reanimated.ts +29 -29
- package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -70
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -15
- package/src/specs/NativeKeyboardController.ts +19 -19
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
- package/src/types.ts +212 -211
- package/src/utils.ts +1 -1
package/src/bindings.ts
CHANGED
|
@@ -1,38 +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>;
|
|
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>;
|
|
@@ -1,58 +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
|
-
};
|
|
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
|
+
};
|
|
@@ -1,156 +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;
|
|
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;
|