@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/context.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { createContext, useContext } from "react";
|
|
2
|
-
import { Animated } from "react-native";
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
FocusedInputHandlers,
|
|
6
|
-
FocusedInputLayoutChangedEvent,
|
|
7
|
-
KeyboardHandlers,
|
|
8
|
-
} from "./types";
|
|
9
|
-
import type React from "react";
|
|
10
|
-
import type { SharedValue } from "react-native-reanimated";
|
|
11
|
-
|
|
12
|
-
export type AnimatedContext = {
|
|
13
|
-
progress: Animated.Value;
|
|
14
|
-
height: Animated.AnimatedMultiplication<number>;
|
|
15
|
-
};
|
|
16
|
-
export type ReanimatedContext = {
|
|
17
|
-
progress: SharedValue<number>;
|
|
18
|
-
height: SharedValue<number>;
|
|
19
|
-
};
|
|
20
|
-
export type KeyboardAnimationContext = {
|
|
21
|
-
enabled: boolean;
|
|
22
|
-
animated: AnimatedContext;
|
|
23
|
-
reanimated: ReanimatedContext;
|
|
24
|
-
layout: SharedValue<FocusedInputLayoutChangedEvent | null>;
|
|
25
|
-
setKeyboardHandlers: (handlers: KeyboardHandlers) => void;
|
|
26
|
-
setInputHandlers: (handlers: FocusedInputHandlers) => void;
|
|
27
|
-
setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
|
|
28
|
-
};
|
|
29
|
-
const NOOP = () => {};
|
|
30
|
-
const withSharedValue = <T>(value: T): SharedValue<T> => ({
|
|
31
|
-
value,
|
|
32
|
-
addListener: NOOP,
|
|
33
|
-
removeListener: NOOP,
|
|
34
|
-
modify: NOOP,
|
|
35
|
-
});
|
|
36
|
-
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
37
|
-
const DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(
|
|
38
|
-
null,
|
|
39
|
-
);
|
|
40
|
-
const defaultContext: KeyboardAnimationContext = {
|
|
41
|
-
enabled: true,
|
|
42
|
-
animated: {
|
|
43
|
-
progress: new Animated.Value(0),
|
|
44
|
-
height: new Animated.Value(0),
|
|
45
|
-
},
|
|
46
|
-
reanimated: {
|
|
47
|
-
progress: DEFAULT_SHARED_VALUE,
|
|
48
|
-
height: DEFAULT_SHARED_VALUE,
|
|
49
|
-
},
|
|
50
|
-
layout: DEFAULT_LAYOUT,
|
|
51
|
-
setKeyboardHandlers: NOOP,
|
|
52
|
-
setInputHandlers: NOOP,
|
|
53
|
-
setEnabled: NOOP,
|
|
54
|
-
};
|
|
55
|
-
export const KeyboardContext = createContext(defaultContext);
|
|
56
|
-
export const useKeyboardContext = () => {
|
|
57
|
-
const context = useContext(KeyboardContext);
|
|
58
|
-
if (__DEV__ && context === defaultContext) {
|
|
59
|
-
console.warn(
|
|
60
|
-
"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.",
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return context;
|
|
65
|
-
};
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
FocusedInputHandlers,
|
|
6
|
+
FocusedInputLayoutChangedEvent,
|
|
7
|
+
KeyboardHandlers,
|
|
8
|
+
} from "./types";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
11
|
+
|
|
12
|
+
export type AnimatedContext = {
|
|
13
|
+
progress: Animated.Value;
|
|
14
|
+
height: Animated.AnimatedMultiplication<number>;
|
|
15
|
+
};
|
|
16
|
+
export type ReanimatedContext = {
|
|
17
|
+
progress: SharedValue<number>;
|
|
18
|
+
height: SharedValue<number>;
|
|
19
|
+
};
|
|
20
|
+
export type KeyboardAnimationContext = {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
animated: AnimatedContext;
|
|
23
|
+
reanimated: ReanimatedContext;
|
|
24
|
+
layout: SharedValue<FocusedInputLayoutChangedEvent | null>;
|
|
25
|
+
setKeyboardHandlers: (handlers: KeyboardHandlers) => void;
|
|
26
|
+
setInputHandlers: (handlers: FocusedInputHandlers) => void;
|
|
27
|
+
setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
|
|
28
|
+
};
|
|
29
|
+
const NOOP = () => {};
|
|
30
|
+
const withSharedValue = <T>(value: T): SharedValue<T> => ({
|
|
31
|
+
value,
|
|
32
|
+
addListener: NOOP,
|
|
33
|
+
removeListener: NOOP,
|
|
34
|
+
modify: NOOP,
|
|
35
|
+
});
|
|
36
|
+
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
37
|
+
const DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(
|
|
38
|
+
null,
|
|
39
|
+
);
|
|
40
|
+
const defaultContext: KeyboardAnimationContext = {
|
|
41
|
+
enabled: true,
|
|
42
|
+
animated: {
|
|
43
|
+
progress: new Animated.Value(0),
|
|
44
|
+
height: new Animated.Value(0),
|
|
45
|
+
},
|
|
46
|
+
reanimated: {
|
|
47
|
+
progress: DEFAULT_SHARED_VALUE,
|
|
48
|
+
height: DEFAULT_SHARED_VALUE,
|
|
49
|
+
},
|
|
50
|
+
layout: DEFAULT_LAYOUT,
|
|
51
|
+
setKeyboardHandlers: NOOP,
|
|
52
|
+
setInputHandlers: NOOP,
|
|
53
|
+
setEnabled: NOOP,
|
|
54
|
+
};
|
|
55
|
+
export const KeyboardContext = createContext(defaultContext);
|
|
56
|
+
export const useKeyboardContext = () => {
|
|
57
|
+
const context = useContext(KeyboardContext);
|
|
58
|
+
if (__DEV__ && context === defaultContext) {
|
|
59
|
+
console.warn(
|
|
60
|
+
"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.",
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return context;
|
|
65
|
+
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import { KeyboardController } from "../bindings";
|
|
4
|
-
import { AndroidSoftInputModes } from "../constants";
|
|
5
|
-
import { useKeyboardContext } from "../context";
|
|
6
|
-
import { uuid } from "../utils";
|
|
7
|
-
|
|
8
|
-
import type { AnimatedContext, ReanimatedContext } from "../context";
|
|
9
|
-
import type { FocusedInputHandler, KeyboardHandler } from "../types";
|
|
10
|
-
import type { DependencyList } from "react";
|
|
11
|
-
|
|
12
|
-
export const useResizeMode = () => {
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
KeyboardController.setInputMode(
|
|
15
|
-
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
return () => KeyboardController.setDefaultMode();
|
|
19
|
-
}, []);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const useKeyboardAnimation = (): AnimatedContext => {
|
|
23
|
-
useResizeMode();
|
|
24
|
-
const context = useKeyboardContext();
|
|
25
|
-
|
|
26
|
-
return context.animated;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
30
|
-
useResizeMode();
|
|
31
|
-
const context = useKeyboardContext();
|
|
32
|
-
|
|
33
|
-
return context.reanimated;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export function useGenericKeyboardHandler(
|
|
37
|
-
handler: KeyboardHandler,
|
|
38
|
-
deps?: DependencyList,
|
|
39
|
-
) {
|
|
40
|
-
const context = useKeyboardContext();
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const key = uuid();
|
|
44
|
-
|
|
45
|
-
context.setKeyboardHandlers({ [key]: handler });
|
|
46
|
-
|
|
47
|
-
return () => {
|
|
48
|
-
context.setKeyboardHandlers({ [key]: undefined });
|
|
49
|
-
};
|
|
50
|
-
}, deps);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function useKeyboardHandler(
|
|
54
|
-
handler: KeyboardHandler,
|
|
55
|
-
deps?: DependencyList,
|
|
56
|
-
) {
|
|
57
|
-
useResizeMode();
|
|
58
|
-
useGenericKeyboardHandler(handler, deps);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function useKeyboardController() {
|
|
62
|
-
const context = useKeyboardContext();
|
|
63
|
-
|
|
64
|
-
return { setEnabled: context.setEnabled, enabled: context.enabled };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function useReanimatedFocusedInput() {
|
|
68
|
-
const context = useKeyboardContext();
|
|
69
|
-
|
|
70
|
-
return { input: context.layout };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function useFocusedInputHandler(
|
|
74
|
-
handler?: FocusedInputHandler,
|
|
75
|
-
deps?: DependencyList,
|
|
76
|
-
) {
|
|
77
|
-
const context = useKeyboardContext();
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
const key = uuid();
|
|
81
|
-
|
|
82
|
-
context.setInputHandlers({ [key]: handler });
|
|
83
|
-
|
|
84
|
-
return () => {
|
|
85
|
-
context.setInputHandlers({ [key]: undefined });
|
|
86
|
-
};
|
|
87
|
-
}, deps);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export * from "./useWindowDimensions";
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { KeyboardController } from "../bindings";
|
|
4
|
+
import { AndroidSoftInputModes } from "../constants";
|
|
5
|
+
import { useKeyboardContext } from "../context";
|
|
6
|
+
import { uuid } from "../utils";
|
|
7
|
+
|
|
8
|
+
import type { AnimatedContext, ReanimatedContext } from "../context";
|
|
9
|
+
import type { FocusedInputHandler, KeyboardHandler } from "../types";
|
|
10
|
+
import type { DependencyList } from "react";
|
|
11
|
+
|
|
12
|
+
export const useResizeMode = () => {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
KeyboardController.setInputMode(
|
|
15
|
+
AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return () => KeyboardController.setDefaultMode();
|
|
19
|
+
}, []);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const useKeyboardAnimation = (): AnimatedContext => {
|
|
23
|
+
useResizeMode();
|
|
24
|
+
const context = useKeyboardContext();
|
|
25
|
+
|
|
26
|
+
return context.animated;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
30
|
+
useResizeMode();
|
|
31
|
+
const context = useKeyboardContext();
|
|
32
|
+
|
|
33
|
+
return context.reanimated;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function useGenericKeyboardHandler(
|
|
37
|
+
handler: KeyboardHandler,
|
|
38
|
+
deps?: DependencyList,
|
|
39
|
+
) {
|
|
40
|
+
const context = useKeyboardContext();
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const key = uuid();
|
|
44
|
+
|
|
45
|
+
context.setKeyboardHandlers({ [key]: handler });
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
context.setKeyboardHandlers({ [key]: undefined });
|
|
49
|
+
};
|
|
50
|
+
}, deps);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useKeyboardHandler(
|
|
54
|
+
handler: KeyboardHandler,
|
|
55
|
+
deps?: DependencyList,
|
|
56
|
+
) {
|
|
57
|
+
useResizeMode();
|
|
58
|
+
useGenericKeyboardHandler(handler, deps);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useKeyboardController() {
|
|
62
|
+
const context = useKeyboardContext();
|
|
63
|
+
|
|
64
|
+
return { setEnabled: context.setEnabled, enabled: context.enabled };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function useReanimatedFocusedInput() {
|
|
68
|
+
const context = useKeyboardContext();
|
|
69
|
+
|
|
70
|
+
return { input: context.layout };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function useFocusedInputHandler(
|
|
74
|
+
handler?: FocusedInputHandler,
|
|
75
|
+
deps?: DependencyList,
|
|
76
|
+
) {
|
|
77
|
+
const context = useKeyboardContext();
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const key = uuid();
|
|
81
|
+
|
|
82
|
+
context.setInputHandlers({ [key]: handler });
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
context.setInputHandlers({ [key]: undefined });
|
|
86
|
+
};
|
|
87
|
+
}, deps);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export * from "./useWindowDimensions";
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import { WindowDimensionsEvents } from "../../bindings";
|
|
4
|
-
|
|
5
|
-
import type { WindowDimensionsEventData } from "../../types";
|
|
6
|
-
|
|
7
|
-
let initialDimensions: WindowDimensionsEventData = {
|
|
8
|
-
width: 0,
|
|
9
|
-
height: 0,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
WindowDimensionsEvents.addListener("windowDidResize", (e) => {
|
|
13
|
-
initialDimensions = e;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const useWindowDimensions = () => {
|
|
17
|
-
const [dimensions, setDimensions] = useState(initialDimensions);
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const subscription = WindowDimensionsEvents.addListener(
|
|
21
|
-
"windowDidResize",
|
|
22
|
-
(e) => {
|
|
23
|
-
setDimensions(e);
|
|
24
|
-
},
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return () => {
|
|
28
|
-
subscription.remove();
|
|
29
|
-
};
|
|
30
|
-
}, []);
|
|
31
|
-
|
|
32
|
-
return dimensions;
|
|
33
|
-
};
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { WindowDimensionsEvents } from "../../bindings";
|
|
4
|
+
|
|
5
|
+
import type { WindowDimensionsEventData } from "../../types";
|
|
6
|
+
|
|
7
|
+
let initialDimensions: WindowDimensionsEventData = {
|
|
8
|
+
width: 0,
|
|
9
|
+
height: 0,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
WindowDimensionsEvents.addListener("windowDidResize", (e) => {
|
|
13
|
+
initialDimensions = e;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const useWindowDimensions = () => {
|
|
17
|
+
const [dimensions, setDimensions] = useState(initialDimensions);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const subscription = WindowDimensionsEvents.addListener(
|
|
21
|
+
"windowDidResize",
|
|
22
|
+
(e) => {
|
|
23
|
+
setDimensions(e);
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
subscription.remove();
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
return dimensions;
|
|
33
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useWindowDimensions } from "react-native";
|
|
1
|
+
export { useWindowDimensions } from "react-native";
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export * from "./bindings";
|
|
2
|
-
export * from "./animated";
|
|
3
|
-
export * from "./context";
|
|
4
|
-
export * from "./hooks";
|
|
5
|
-
export * from "./constants";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
KeyboardAvoidingView,
|
|
10
|
-
KeyboardStickyView,
|
|
11
|
-
KeyboardAwareScrollView,
|
|
12
|
-
// keyboard toolbar
|
|
13
|
-
KeyboardToolbar,
|
|
14
|
-
DefaultKeyboardToolbarTheme,
|
|
15
|
-
} from "./components";
|
|
16
|
-
export type {
|
|
17
|
-
KeyboardAvoidingViewProps,
|
|
18
|
-
KeyboardStickyViewProps,
|
|
19
|
-
KeyboardAwareScrollViewProps,
|
|
20
|
-
KeyboardToolbarProps,
|
|
21
|
-
} from "./components";
|
|
1
|
+
export * from "./bindings";
|
|
2
|
+
export * from "./animated";
|
|
3
|
+
export * from "./context";
|
|
4
|
+
export * from "./hooks";
|
|
5
|
+
export * from "./constants";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
KeyboardAvoidingView,
|
|
10
|
+
KeyboardStickyView,
|
|
11
|
+
KeyboardAwareScrollView,
|
|
12
|
+
// keyboard toolbar
|
|
13
|
+
KeyboardToolbar,
|
|
14
|
+
DefaultKeyboardToolbarTheme,
|
|
15
|
+
} from "./components";
|
|
16
|
+
export type {
|
|
17
|
+
KeyboardAvoidingViewProps,
|
|
18
|
+
KeyboardStickyViewProps,
|
|
19
|
+
KeyboardAwareScrollViewProps,
|
|
20
|
+
KeyboardToolbarProps,
|
|
21
|
+
} from "./components";
|
package/src/internal.ts
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { useCallback, useRef } from "react";
|
|
2
|
-
import { Animated } from "react-native";
|
|
3
|
-
import { useSharedValue } from "react-native-reanimated";
|
|
4
|
-
|
|
5
|
-
import type { Handlers } from "./types";
|
|
6
|
-
|
|
7
|
-
type UntypedHandler = Record<string, (event: never) => void>;
|
|
8
|
-
type SharedHandlersReturnType<T extends UntypedHandler> = [
|
|
9
|
-
(handler: Handlers<T>) => void,
|
|
10
|
-
<K extends keyof T>(type: K, event: Parameters<T[K]>[0]) => void,
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Hook for storing worklet handlers (objects with keys, where values are worklets).
|
|
15
|
-
* Returns methods for setting handlers and broadcasting events in them.
|
|
16
|
-
*
|
|
17
|
-
* T is a generic that looks like:
|
|
18
|
-
* @example
|
|
19
|
-
* {
|
|
20
|
-
* onEvent: () => {},
|
|
21
|
-
* onEvent2: () => {},
|
|
22
|
-
* }
|
|
23
|
-
*/
|
|
24
|
-
export function useSharedHandlers<
|
|
25
|
-
T extends UntypedHandler,
|
|
26
|
-
>(): SharedHandlersReturnType<T> {
|
|
27
|
-
const handlers = useSharedValue<Handlers<T>>({});
|
|
28
|
-
const jsHandlers = useRef<Handlers<T>>({});
|
|
29
|
-
|
|
30
|
-
// since js -> worklet -> js call is asynchronous, we can not write handlers
|
|
31
|
-
// straight into shared variable (using current shared value as a previous result),
|
|
32
|
-
// since there may be a race condition in a call, and closure may have out-of-dated
|
|
33
|
-
// values. As a result, some of handlers may be not written to "all handlers" object.
|
|
34
|
-
// Below we are writing all handlers to `ref` and afterwards synchronize them with
|
|
35
|
-
// shared value (since `refs` are not referring to actual value in worklets).
|
|
36
|
-
// This approach allow us to update synchronously handlers in js thread (and it assures,
|
|
37
|
-
// that it will have all of them) and then update them in worklet thread (calls are
|
|
38
|
-
// happening in FIFO order, so we will always have actual value).
|
|
39
|
-
const updateSharedHandlers = () => {
|
|
40
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
41
|
-
handlers.value = jsHandlers.current;
|
|
42
|
-
};
|
|
43
|
-
const setHandlers = useCallback((handler: Handlers<T>) => {
|
|
44
|
-
jsHandlers.current = {
|
|
45
|
-
...jsHandlers.current,
|
|
46
|
-
...handler,
|
|
47
|
-
};
|
|
48
|
-
updateSharedHandlers();
|
|
49
|
-
}, []);
|
|
50
|
-
const broadcast = <K extends keyof T>(
|
|
51
|
-
type: K,
|
|
52
|
-
event: Parameters<T[K]>[0],
|
|
53
|
-
) => {
|
|
54
|
-
"worklet";
|
|
55
|
-
|
|
56
|
-
Object.keys(handlers.value).forEach((key) => {
|
|
57
|
-
handlers.value[key]?.[type]?.(event);
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return [setHandlers, broadcast];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* TS variant of `useAnimatedValue` hook which is added in RN 0.71
|
|
66
|
-
* A better alternative of storing animated values in refs, since
|
|
67
|
-
* it doesn't recreate a new `Animated.Value` object on every re-render
|
|
68
|
-
* and therefore consumes less memory. We can not use a variant from
|
|
69
|
-
* RN, since this library supports earlier versions of RN.
|
|
70
|
-
*
|
|
71
|
-
* @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
|
|
72
|
-
*/
|
|
73
|
-
export function useAnimatedValue(
|
|
74
|
-
initialValue: number,
|
|
75
|
-
config?: Animated.AnimatedConfig,
|
|
76
|
-
): Animated.Value {
|
|
77
|
-
const ref = useRef<Animated.Value | null>(null);
|
|
78
|
-
|
|
79
|
-
if (ref.current == null) {
|
|
80
|
-
ref.current = new Animated.Value(initialValue, config);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return ref.current;
|
|
84
|
-
}
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import type { Handlers } from "./types";
|
|
6
|
+
|
|
7
|
+
type UntypedHandler = Record<string, (event: never) => void>;
|
|
8
|
+
type SharedHandlersReturnType<T extends UntypedHandler> = [
|
|
9
|
+
(handler: Handlers<T>) => void,
|
|
10
|
+
<K extends keyof T>(type: K, event: Parameters<T[K]>[0]) => void,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hook for storing worklet handlers (objects with keys, where values are worklets).
|
|
15
|
+
* Returns methods for setting handlers and broadcasting events in them.
|
|
16
|
+
*
|
|
17
|
+
* T is a generic that looks like:
|
|
18
|
+
* @example
|
|
19
|
+
* {
|
|
20
|
+
* onEvent: () => {},
|
|
21
|
+
* onEvent2: () => {},
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export function useSharedHandlers<
|
|
25
|
+
T extends UntypedHandler,
|
|
26
|
+
>(): SharedHandlersReturnType<T> {
|
|
27
|
+
const handlers = useSharedValue<Handlers<T>>({});
|
|
28
|
+
const jsHandlers = useRef<Handlers<T>>({});
|
|
29
|
+
|
|
30
|
+
// since js -> worklet -> js call is asynchronous, we can not write handlers
|
|
31
|
+
// straight into shared variable (using current shared value as a previous result),
|
|
32
|
+
// since there may be a race condition in a call, and closure may have out-of-dated
|
|
33
|
+
// values. As a result, some of handlers may be not written to "all handlers" object.
|
|
34
|
+
// Below we are writing all handlers to `ref` and afterwards synchronize them with
|
|
35
|
+
// shared value (since `refs` are not referring to actual value in worklets).
|
|
36
|
+
// This approach allow us to update synchronously handlers in js thread (and it assures,
|
|
37
|
+
// that it will have all of them) and then update them in worklet thread (calls are
|
|
38
|
+
// happening in FIFO order, so we will always have actual value).
|
|
39
|
+
const updateSharedHandlers = () => {
|
|
40
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
41
|
+
handlers.value = jsHandlers.current;
|
|
42
|
+
};
|
|
43
|
+
const setHandlers = useCallback((handler: Handlers<T>) => {
|
|
44
|
+
jsHandlers.current = {
|
|
45
|
+
...jsHandlers.current,
|
|
46
|
+
...handler,
|
|
47
|
+
};
|
|
48
|
+
updateSharedHandlers();
|
|
49
|
+
}, []);
|
|
50
|
+
const broadcast = <K extends keyof T>(
|
|
51
|
+
type: K,
|
|
52
|
+
event: Parameters<T[K]>[0],
|
|
53
|
+
) => {
|
|
54
|
+
"worklet";
|
|
55
|
+
|
|
56
|
+
Object.keys(handlers.value).forEach((key) => {
|
|
57
|
+
handlers.value[key]?.[type]?.(event);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return [setHandlers, broadcast];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* TS variant of `useAnimatedValue` hook which is added in RN 0.71
|
|
66
|
+
* A better alternative of storing animated values in refs, since
|
|
67
|
+
* it doesn't recreate a new `Animated.Value` object on every re-render
|
|
68
|
+
* and therefore consumes less memory. We can not use a variant from
|
|
69
|
+
* RN, since this library supports earlier versions of RN.
|
|
70
|
+
*
|
|
71
|
+
* @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
|
|
72
|
+
*/
|
|
73
|
+
export function useAnimatedValue(
|
|
74
|
+
initialValue: number,
|
|
75
|
+
config?: Animated.AnimatedConfig,
|
|
76
|
+
): Animated.Value {
|
|
77
|
+
const ref = useRef<Animated.Value | null>(null);
|
|
78
|
+
|
|
79
|
+
if (ref.current == null) {
|
|
80
|
+
ref.current = new Animated.Value(initialValue, config);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return ref.current;
|
|
84
|
+
}
|