@react-native-ohos/react-native-keyboard-controller 1.16.7 → 1.16.9-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 +610 -19
- package/harmony/keyboard_controller/BuildProfile.ets +16 -16
- package/harmony/keyboard_controller/Index.ets +28 -28
- 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 -19
- package/harmony/keyboard_controller/oh-package.json5 +10 -10
- 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 +111 -111
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +94 -94
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +845 -287
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +170 -103
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +65 -65
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +79 -79
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +107 -107
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +83 -83
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +60 -60
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +46 -46
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +48 -48
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +45 -45
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +49 -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 +64 -64
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +77 -77
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +66 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ts +66 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +441 -273
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +128 -119
- package/harmony/keyboard_controller/src/main/ets/Type.ts +62 -62
- 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.ts +29 -29
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +2 -2
- 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 +0 -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/module.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/specs/OverKeyboardViewNativeComponent.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/module/animated.js +2 -2
- 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 +0 -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/module.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/specs/OverKeyboardViewNativeComponent.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/OverKeyboardView/index.js.map +1 -1
- package/lib/module/views/index.js.map +1 -1
- package/lib/typescript/bindings.d.ts +3 -4
- package/lib/typescript/bindings.native.d.ts +0 -1
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +6 -6
- package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +1 -1
- package/lib/typescript/components/KeyboardStickyView/index.d.ts +5 -5
- package/lib/typescript/components/KeyboardToolbar/Button.d.ts +2 -1
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +177 -174
- package/src/animated.tsx +255 -255
- package/src/bindings.native.ts +62 -62
- package/src/bindings.ts +42 -42
- package/src/components/KeyboardAvoidingView/hooks.ts +123 -123
- package/src/components/KeyboardAvoidingView/index.tsx +188 -188
- package/src/components/KeyboardAwareScrollView/index.tsx +389 -389
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
- package/src/components/KeyboardStickyView/index.tsx +66 -66
- 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 +223 -223
- 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 +68 -69
- package/src/hooks/index.ts +90 -90
- package/src/hooks/useWindowDimensions/index.android.ts +38 -38
- package/src/hooks/useWindowDimensions/index.ts +1 -1
- package/src/index.ts +23 -23
- package/src/internal.ts +84 -84
- package/src/module.ts +52 -52
- 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 +71 -71
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +20 -20
- package/src/specs/NativeKeyboardController.ts +19 -19
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
- package/src/specs/OverKeyboardViewNativeComponent.ts +12 -12
- package/src/types.ts +244 -243
- package/src/utils.ts +1 -1
- package/src/views/OverKeyboardView/index.tsx +43 -43
- package/src/views/index.ts +1 -1
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
FocusedInputEvents,
|
|
6
|
-
} from "../../bindings";
|
|
7
|
-
import KeyboardStickyView from "../KeyboardStickyView"
|
|
8
|
-
import { KeyboardControllerNative } from "../../bindings";
|
|
9
|
-
import useColorScheme from "../hooks/useColorScheme";
|
|
10
|
-
|
|
11
|
-
import Arrow from "./Arrow";
|
|
12
|
-
import Button from "./Button";
|
|
13
|
-
import { colors } from "./colors";
|
|
14
|
-
|
|
15
|
-
import type { HEX, KeyboardToolbarTheme } from "./types";
|
|
16
|
-
import type { KeyboardStickyViewProps } from "../KeyboardStickyView";
|
|
17
|
-
import type { ReactNode } from "react";
|
|
18
|
-
import type { ViewProps } from "react-native";
|
|
19
|
-
|
|
20
|
-
export type KeyboardToolbarProps = Omit<
|
|
21
|
-
ViewProps,
|
|
22
|
-
"style" | "testID" | "children"
|
|
23
|
-
> & {
|
|
24
|
-
/** An element that is shown in the middle of the toolbar. */
|
|
25
|
-
content?: JSX.Element | null;
|
|
26
|
-
/** A set of dark/light colors consumed by toolbar component. */
|
|
27
|
-
theme?: KeyboardToolbarTheme;
|
|
28
|
-
/** Custom text for done button. */
|
|
29
|
-
doneText?: ReactNode;
|
|
30
|
-
/** Custom touchable component for toolbar (used for prev/next/done buttons). */
|
|
31
|
-
button?: typeof Button;
|
|
32
|
-
/** Custom icon component used to display next/prev buttons. */
|
|
33
|
-
icon?: typeof Arrow;
|
|
34
|
-
/**
|
|
35
|
-
* Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
|
|
36
|
-
* and want to show only `Done` button. Default to `true`.
|
|
37
|
-
*/
|
|
38
|
-
showArrows?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* A callback that is called when the user presses the next button along with the default action.
|
|
41
|
-
*/
|
|
42
|
-
onNextCallback?: () => void;
|
|
43
|
-
/**
|
|
44
|
-
* A callback that is called when the user presses the previous button along with the default action.
|
|
45
|
-
*/
|
|
46
|
-
onPrevCallback?: () => void;
|
|
47
|
-
/**
|
|
48
|
-
* A callback that is called when the user presses the done button along with the default action.
|
|
49
|
-
*/
|
|
50
|
-
onDoneCallback?: () => void;
|
|
51
|
-
/**
|
|
52
|
-
* A component that applies blur effect to the toolbar.
|
|
53
|
-
*/
|
|
54
|
-
blur?: JSX.Element | null;
|
|
55
|
-
/**
|
|
56
|
-
* A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
|
|
57
|
-
*/
|
|
58
|
-
opacity?: HEX;
|
|
59
|
-
} & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
|
|
60
|
-
|
|
61
|
-
const TEST_ID_KEYBOARD_TOOLBAR = "keyboard.toolbar";
|
|
62
|
-
const TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;
|
|
63
|
-
const TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;
|
|
64
|
-
const TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;
|
|
65
|
-
const TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;
|
|
66
|
-
|
|
67
|
-
const KEYBOARD_TOOLBAR_HEIGHT = 42;
|
|
68
|
-
const DEFAULT_OPACITY: HEX = "FF";
|
|
69
|
-
|
|
70
|
-
const dismissKeyboard = () => KeyboardControllerNative.dismiss(false);
|
|
71
|
-
const goToNextField = () => KeyboardControllerNative.setFocusTo("next");
|
|
72
|
-
const goToPrevField = () => KeyboardControllerNative.setFocusTo("prev");
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
|
|
76
|
-
* `Done` buttons.
|
|
77
|
-
*/
|
|
78
|
-
const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
|
|
79
|
-
content,
|
|
80
|
-
theme = colors,
|
|
81
|
-
doneText,
|
|
82
|
-
button,
|
|
83
|
-
icon,
|
|
84
|
-
showArrows = true,
|
|
85
|
-
onNextCallback,
|
|
86
|
-
onPrevCallback,
|
|
87
|
-
onDoneCallback,
|
|
88
|
-
blur = null,
|
|
89
|
-
opacity = DEFAULT_OPACITY,
|
|
90
|
-
offset: { closed = 0, opened = 0 } = {},
|
|
91
|
-
enabled = true,
|
|
92
|
-
...rest
|
|
93
|
-
}) => {
|
|
94
|
-
const colorScheme = useColorScheme();
|
|
95
|
-
const [inputs, setInputs] = useState({
|
|
96
|
-
current: 0,
|
|
97
|
-
count: 0,
|
|
98
|
-
});
|
|
99
|
-
const isPrevDisabled = inputs.current === 0;
|
|
100
|
-
const isNextDisabled = inputs.current === inputs.count - 1;
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
const subscription = FocusedInputEvents.addListener("focusDidSet", (e) => {
|
|
104
|
-
setInputs(e);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return subscription.remove;
|
|
108
|
-
}, []);
|
|
109
|
-
const doneStyle = useMemo(
|
|
110
|
-
() => [styles.doneButton, { color: theme[colorScheme].primary }],
|
|
111
|
-
[colorScheme, theme],
|
|
112
|
-
);
|
|
113
|
-
const toolbarStyle = useMemo(
|
|
114
|
-
() => [
|
|
115
|
-
styles.toolbar,
|
|
116
|
-
{
|
|
117
|
-
backgroundColor: `${theme[colorScheme].background}${opacity}`,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
[colorScheme, opacity, theme],
|
|
121
|
-
);
|
|
122
|
-
const offset = useMemo(
|
|
123
|
-
() => ({ closed: closed + KEYBOARD_TOOLBAR_HEIGHT, opened }),
|
|
124
|
-
[closed, opened],
|
|
125
|
-
);
|
|
126
|
-
const ButtonContainer = button || Button;
|
|
127
|
-
const IconContainer = icon || Arrow;
|
|
128
|
-
|
|
129
|
-
const onPressNext = useCallback(() => {
|
|
130
|
-
goToNextField();
|
|
131
|
-
onNextCallback?.();
|
|
132
|
-
}, [onNextCallback]);
|
|
133
|
-
const onPressPrev = useCallback(() => {
|
|
134
|
-
goToPrevField();
|
|
135
|
-
onPrevCallback?.();
|
|
136
|
-
}, [onPrevCallback]);
|
|
137
|
-
const onPressDone = useCallback(() => {
|
|
138
|
-
dismissKeyboard();
|
|
139
|
-
onDoneCallback?.();
|
|
140
|
-
}, [onDoneCallback]);
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<KeyboardStickyView enabled={enabled} offset={offset}>
|
|
144
|
-
<View {...rest} style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
|
|
145
|
-
{blur}
|
|
146
|
-
{showArrows && (
|
|
147
|
-
<>
|
|
148
|
-
<ButtonContainer
|
|
149
|
-
accessibilityLabel="Previous"
|
|
150
|
-
accessibilityHint="Will move focus to previous field"
|
|
151
|
-
disabled={isPrevDisabled}
|
|
152
|
-
onPress={onPressPrev}
|
|
153
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}
|
|
154
|
-
theme={theme}
|
|
155
|
-
>
|
|
156
|
-
<IconContainer
|
|
157
|
-
disabled={isPrevDisabled}
|
|
158
|
-
type="prev"
|
|
159
|
-
theme={theme}
|
|
160
|
-
/>
|
|
161
|
-
</ButtonContainer>
|
|
162
|
-
<ButtonContainer
|
|
163
|
-
accessibilityLabel="Next"
|
|
164
|
-
accessibilityHint="Will move focus to next field"
|
|
165
|
-
disabled={isNextDisabled}
|
|
166
|
-
onPress={onPressNext}
|
|
167
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}
|
|
168
|
-
theme={theme}
|
|
169
|
-
>
|
|
170
|
-
<IconContainer
|
|
171
|
-
disabled={isNextDisabled}
|
|
172
|
-
type="next"
|
|
173
|
-
theme={theme}
|
|
174
|
-
/>
|
|
175
|
-
</ButtonContainer>
|
|
176
|
-
</>
|
|
177
|
-
)}
|
|
178
|
-
|
|
179
|
-
<View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>
|
|
180
|
-
{content}
|
|
181
|
-
</View>
|
|
182
|
-
<ButtonContainer
|
|
183
|
-
accessibilityLabel="Done"
|
|
184
|
-
accessibilityHint="Will close the keyboard"
|
|
185
|
-
onPress={onPressDone}
|
|
186
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}
|
|
187
|
-
rippleRadius={28}
|
|
188
|
-
style={styles.doneButtonContainer}
|
|
189
|
-
theme={theme}
|
|
190
|
-
>
|
|
191
|
-
<Text style={doneStyle} maxFontSizeMultiplier={1.3}>
|
|
192
|
-
{doneText || "Done"}
|
|
193
|
-
</Text>
|
|
194
|
-
</ButtonContainer>
|
|
195
|
-
</View>
|
|
196
|
-
</KeyboardStickyView>
|
|
197
|
-
);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const styles = StyleSheet.create({
|
|
201
|
-
flex: {
|
|
202
|
-
flex: 1,
|
|
203
|
-
},
|
|
204
|
-
toolbar: {
|
|
205
|
-
position: "absolute",
|
|
206
|
-
bottom: 0,
|
|
207
|
-
alignItems: "center",
|
|
208
|
-
width: "100%",
|
|
209
|
-
flexDirection: "row",
|
|
210
|
-
height: KEYBOARD_TOOLBAR_HEIGHT,
|
|
211
|
-
paddingHorizontal: 8,
|
|
212
|
-
},
|
|
213
|
-
doneButton: {
|
|
214
|
-
fontWeight: "600",
|
|
215
|
-
fontSize: 15,
|
|
216
|
-
},
|
|
217
|
-
doneButtonContainer: {
|
|
218
|
-
marginRight: 8,
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
export { colors as DefaultKeyboardToolbarTheme };
|
|
223
|
-
export default KeyboardToolbar;
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
FocusedInputEvents,
|
|
6
|
+
} from "../../bindings";
|
|
7
|
+
import KeyboardStickyView from "../KeyboardStickyView"
|
|
8
|
+
import { KeyboardControllerNative } from "../../bindings";
|
|
9
|
+
import useColorScheme from "../hooks/useColorScheme";
|
|
10
|
+
|
|
11
|
+
import Arrow from "./Arrow";
|
|
12
|
+
import Button from "./Button";
|
|
13
|
+
import { colors } from "./colors";
|
|
14
|
+
|
|
15
|
+
import type { HEX, KeyboardToolbarTheme } from "./types";
|
|
16
|
+
import type { KeyboardStickyViewProps } from "../KeyboardStickyView";
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import type { ViewProps } from "react-native";
|
|
19
|
+
|
|
20
|
+
export type KeyboardToolbarProps = Omit<
|
|
21
|
+
ViewProps,
|
|
22
|
+
"style" | "testID" | "children"
|
|
23
|
+
> & {
|
|
24
|
+
/** An element that is shown in the middle of the toolbar. */
|
|
25
|
+
content?: JSX.Element | null;
|
|
26
|
+
/** A set of dark/light colors consumed by toolbar component. */
|
|
27
|
+
theme?: KeyboardToolbarTheme;
|
|
28
|
+
/** Custom text for done button. */
|
|
29
|
+
doneText?: ReactNode;
|
|
30
|
+
/** Custom touchable component for toolbar (used for prev/next/done buttons). */
|
|
31
|
+
button?: typeof Button;
|
|
32
|
+
/** Custom icon component used to display next/prev buttons. */
|
|
33
|
+
icon?: typeof Arrow;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
|
|
36
|
+
* and want to show only `Done` button. Default to `true`.
|
|
37
|
+
*/
|
|
38
|
+
showArrows?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* A callback that is called when the user presses the next button along with the default action.
|
|
41
|
+
*/
|
|
42
|
+
onNextCallback?: () => void;
|
|
43
|
+
/**
|
|
44
|
+
* A callback that is called when the user presses the previous button along with the default action.
|
|
45
|
+
*/
|
|
46
|
+
onPrevCallback?: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* A callback that is called when the user presses the done button along with the default action.
|
|
49
|
+
*/
|
|
50
|
+
onDoneCallback?: () => void;
|
|
51
|
+
/**
|
|
52
|
+
* A component that applies blur effect to the toolbar.
|
|
53
|
+
*/
|
|
54
|
+
blur?: JSX.Element | null;
|
|
55
|
+
/**
|
|
56
|
+
* A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
|
|
57
|
+
*/
|
|
58
|
+
opacity?: HEX;
|
|
59
|
+
} & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
|
|
60
|
+
|
|
61
|
+
const TEST_ID_KEYBOARD_TOOLBAR = "keyboard.toolbar";
|
|
62
|
+
const TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;
|
|
63
|
+
const TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;
|
|
64
|
+
const TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;
|
|
65
|
+
const TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;
|
|
66
|
+
|
|
67
|
+
const KEYBOARD_TOOLBAR_HEIGHT = 42;
|
|
68
|
+
const DEFAULT_OPACITY: HEX = "FF";
|
|
69
|
+
|
|
70
|
+
const dismissKeyboard = () => KeyboardControllerNative.dismiss(false);
|
|
71
|
+
const goToNextField = () => KeyboardControllerNative.setFocusTo("next");
|
|
72
|
+
const goToPrevField = () => KeyboardControllerNative.setFocusTo("prev");
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
|
|
76
|
+
* `Done` buttons.
|
|
77
|
+
*/
|
|
78
|
+
const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
|
|
79
|
+
content,
|
|
80
|
+
theme = colors,
|
|
81
|
+
doneText,
|
|
82
|
+
button,
|
|
83
|
+
icon,
|
|
84
|
+
showArrows = true,
|
|
85
|
+
onNextCallback,
|
|
86
|
+
onPrevCallback,
|
|
87
|
+
onDoneCallback,
|
|
88
|
+
blur = null,
|
|
89
|
+
opacity = DEFAULT_OPACITY,
|
|
90
|
+
offset: { closed = 0, opened = 0 } = {},
|
|
91
|
+
enabled = true,
|
|
92
|
+
...rest
|
|
93
|
+
}) => {
|
|
94
|
+
const colorScheme = useColorScheme();
|
|
95
|
+
const [inputs, setInputs] = useState({
|
|
96
|
+
current: 0,
|
|
97
|
+
count: 0,
|
|
98
|
+
});
|
|
99
|
+
const isPrevDisabled = inputs.current === 0;
|
|
100
|
+
const isNextDisabled = inputs.current === inputs.count - 1;
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const subscription = FocusedInputEvents.addListener("focusDidSet", (e) => {
|
|
104
|
+
setInputs(e);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return subscription.remove;
|
|
108
|
+
}, []);
|
|
109
|
+
const doneStyle = useMemo(
|
|
110
|
+
() => [styles.doneButton, { color: theme[colorScheme].primary }],
|
|
111
|
+
[colorScheme, theme],
|
|
112
|
+
);
|
|
113
|
+
const toolbarStyle = useMemo(
|
|
114
|
+
() => [
|
|
115
|
+
styles.toolbar,
|
|
116
|
+
{
|
|
117
|
+
backgroundColor: `${theme[colorScheme].background}${opacity}`,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
[colorScheme, opacity, theme],
|
|
121
|
+
);
|
|
122
|
+
const offset = useMemo(
|
|
123
|
+
() => ({ closed: closed + KEYBOARD_TOOLBAR_HEIGHT, opened }),
|
|
124
|
+
[closed, opened],
|
|
125
|
+
);
|
|
126
|
+
const ButtonContainer = button || Button;
|
|
127
|
+
const IconContainer = icon || Arrow;
|
|
128
|
+
|
|
129
|
+
const onPressNext = useCallback(() => {
|
|
130
|
+
goToNextField();
|
|
131
|
+
onNextCallback?.();
|
|
132
|
+
}, [onNextCallback]);
|
|
133
|
+
const onPressPrev = useCallback(() => {
|
|
134
|
+
goToPrevField();
|
|
135
|
+
onPrevCallback?.();
|
|
136
|
+
}, [onPrevCallback]);
|
|
137
|
+
const onPressDone = useCallback(() => {
|
|
138
|
+
dismissKeyboard();
|
|
139
|
+
onDoneCallback?.();
|
|
140
|
+
}, [onDoneCallback]);
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<KeyboardStickyView enabled={enabled} offset={offset}>
|
|
144
|
+
<View {...rest} style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
|
|
145
|
+
{blur}
|
|
146
|
+
{showArrows && (
|
|
147
|
+
<>
|
|
148
|
+
<ButtonContainer
|
|
149
|
+
accessibilityLabel="Previous"
|
|
150
|
+
accessibilityHint="Will move focus to previous field"
|
|
151
|
+
disabled={isPrevDisabled}
|
|
152
|
+
onPress={onPressPrev}
|
|
153
|
+
testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}
|
|
154
|
+
theme={theme}
|
|
155
|
+
>
|
|
156
|
+
<IconContainer
|
|
157
|
+
disabled={isPrevDisabled}
|
|
158
|
+
type="prev"
|
|
159
|
+
theme={theme}
|
|
160
|
+
/>
|
|
161
|
+
</ButtonContainer>
|
|
162
|
+
<ButtonContainer
|
|
163
|
+
accessibilityLabel="Next"
|
|
164
|
+
accessibilityHint="Will move focus to next field"
|
|
165
|
+
disabled={isNextDisabled}
|
|
166
|
+
onPress={onPressNext}
|
|
167
|
+
testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}
|
|
168
|
+
theme={theme}
|
|
169
|
+
>
|
|
170
|
+
<IconContainer
|
|
171
|
+
disabled={isNextDisabled}
|
|
172
|
+
type="next"
|
|
173
|
+
theme={theme}
|
|
174
|
+
/>
|
|
175
|
+
</ButtonContainer>
|
|
176
|
+
</>
|
|
177
|
+
)}
|
|
178
|
+
|
|
179
|
+
<View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>
|
|
180
|
+
{content}
|
|
181
|
+
</View>
|
|
182
|
+
<ButtonContainer
|
|
183
|
+
accessibilityLabel="Done"
|
|
184
|
+
accessibilityHint="Will close the keyboard"
|
|
185
|
+
onPress={onPressDone}
|
|
186
|
+
testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}
|
|
187
|
+
rippleRadius={28}
|
|
188
|
+
style={styles.doneButtonContainer}
|
|
189
|
+
theme={theme}
|
|
190
|
+
>
|
|
191
|
+
<Text style={doneStyle} maxFontSizeMultiplier={1.3}>
|
|
192
|
+
{doneText || "Done"}
|
|
193
|
+
</Text>
|
|
194
|
+
</ButtonContainer>
|
|
195
|
+
</View>
|
|
196
|
+
</KeyboardStickyView>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const styles = StyleSheet.create({
|
|
201
|
+
flex: {
|
|
202
|
+
flex: 1,
|
|
203
|
+
},
|
|
204
|
+
toolbar: {
|
|
205
|
+
position: "absolute",
|
|
206
|
+
bottom: 0,
|
|
207
|
+
alignItems: "center",
|
|
208
|
+
width: "100%",
|
|
209
|
+
flexDirection: "row",
|
|
210
|
+
height: KEYBOARD_TOOLBAR_HEIGHT,
|
|
211
|
+
paddingHorizontal: 8,
|
|
212
|
+
},
|
|
213
|
+
doneButton: {
|
|
214
|
+
fontWeight: "600",
|
|
215
|
+
fontSize: 15,
|
|
216
|
+
},
|
|
217
|
+
doneButtonContainer: {
|
|
218
|
+
marginRight: 8,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
export { colors as DefaultKeyboardToolbarTheme };
|
|
223
|
+
export default KeyboardToolbar;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type { ColorValue } from "react-native";
|
|
2
|
-
|
|
3
|
-
type Theme = {
|
|
4
|
-
/** Color for arrow when it's enabled */
|
|
5
|
-
primary: ColorValue;
|
|
6
|
-
/** Color for arrow when it's disabled */
|
|
7
|
-
disabled: ColorValue;
|
|
8
|
-
/** Keyboard toolbar background color */
|
|
9
|
-
background: string;
|
|
10
|
-
/** Color for ripple effect (on button touch) on Android */
|
|
11
|
-
ripple: ColorValue;
|
|
12
|
-
};
|
|
13
|
-
export type KeyboardToolbarTheme = {
|
|
14
|
-
light: Theme;
|
|
15
|
-
dark: Theme;
|
|
16
|
-
};
|
|
17
|
-
type HexSymbol =
|
|
18
|
-
| "0"
|
|
19
|
-
| "1"
|
|
20
|
-
| "2"
|
|
21
|
-
| "3"
|
|
22
|
-
| "4"
|
|
23
|
-
| "5"
|
|
24
|
-
| "6"
|
|
25
|
-
| "7"
|
|
26
|
-
| "8"
|
|
27
|
-
| "9"
|
|
28
|
-
| "A"
|
|
29
|
-
| "B"
|
|
30
|
-
| "C"
|
|
31
|
-
| "D"
|
|
32
|
-
| "E"
|
|
33
|
-
| "F"
|
|
34
|
-
| "a"
|
|
35
|
-
| "b"
|
|
36
|
-
| "c"
|
|
37
|
-
| "d"
|
|
38
|
-
| "e"
|
|
39
|
-
| "f";
|
|
40
|
-
export type HEX = `${HexSymbol}${HexSymbol}`;
|
|
1
|
+
import type { ColorValue } from "react-native";
|
|
2
|
+
|
|
3
|
+
type Theme = {
|
|
4
|
+
/** Color for arrow when it's enabled */
|
|
5
|
+
primary: ColorValue;
|
|
6
|
+
/** Color for arrow when it's disabled */
|
|
7
|
+
disabled: ColorValue;
|
|
8
|
+
/** Keyboard toolbar background color */
|
|
9
|
+
background: string;
|
|
10
|
+
/** Color for ripple effect (on button touch) on Android */
|
|
11
|
+
ripple: ColorValue;
|
|
12
|
+
};
|
|
13
|
+
export type KeyboardToolbarTheme = {
|
|
14
|
+
light: Theme;
|
|
15
|
+
dark: Theme;
|
|
16
|
+
};
|
|
17
|
+
type HexSymbol =
|
|
18
|
+
| "0"
|
|
19
|
+
| "1"
|
|
20
|
+
| "2"
|
|
21
|
+
| "3"
|
|
22
|
+
| "4"
|
|
23
|
+
| "5"
|
|
24
|
+
| "6"
|
|
25
|
+
| "7"
|
|
26
|
+
| "8"
|
|
27
|
+
| "9"
|
|
28
|
+
| "A"
|
|
29
|
+
| "B"
|
|
30
|
+
| "C"
|
|
31
|
+
| "D"
|
|
32
|
+
| "E"
|
|
33
|
+
| "F"
|
|
34
|
+
| "a"
|
|
35
|
+
| "b"
|
|
36
|
+
| "c"
|
|
37
|
+
| "d"
|
|
38
|
+
| "e"
|
|
39
|
+
| "f";
|
|
40
|
+
export type HEX = `${HexSymbol}${HexSymbol}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useColorScheme as useColorSchemeRN } from "react-native";
|
|
2
|
-
|
|
3
|
-
const useColorScheme = () => useColorSchemeRN() || "light";
|
|
4
|
-
|
|
5
|
-
export default useColorScheme;
|
|
1
|
+
import { useColorScheme as useColorSchemeRN } from "react-native";
|
|
2
|
+
|
|
3
|
+
const useColorScheme = () => useColorSchemeRN() || "light";
|
|
4
|
+
|
|
5
|
+
export default useColorScheme;
|
package/src/components/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { default as KeyboardAvoidingView } from "./KeyboardAvoidingView";
|
|
2
|
-
export { default as KeyboardStickyView } from "./KeyboardStickyView";
|
|
3
|
-
export { default as KeyboardAwareScrollView } from "./KeyboardAwareScrollView";
|
|
4
|
-
export {
|
|
5
|
-
default as KeyboardToolbar,
|
|
6
|
-
DefaultKeyboardToolbarTheme,
|
|
7
|
-
} from "./KeyboardToolbar";
|
|
8
|
-
export type { KeyboardAvoidingViewProps } from "./KeyboardAvoidingView";
|
|
9
|
-
export type { KeyboardStickyViewProps } from "./KeyboardStickyView";
|
|
10
|
-
export type { KeyboardAwareScrollViewProps } from "./KeyboardAwareScrollView";
|
|
11
|
-
export type { KeyboardToolbarProps } from "./KeyboardToolbar";
|
|
1
|
+
export { default as KeyboardAvoidingView } from "./KeyboardAvoidingView";
|
|
2
|
+
export { default as KeyboardStickyView } from "./KeyboardStickyView";
|
|
3
|
+
export { default as KeyboardAwareScrollView } from "./KeyboardAwareScrollView";
|
|
4
|
+
export {
|
|
5
|
+
default as KeyboardToolbar,
|
|
6
|
+
DefaultKeyboardToolbarTheme,
|
|
7
|
+
} from "./KeyboardToolbar";
|
|
8
|
+
export type { KeyboardAvoidingViewProps } from "./KeyboardAvoidingView";
|
|
9
|
+
export type { KeyboardStickyViewProps } from "./KeyboardStickyView";
|
|
10
|
+
export type { KeyboardAwareScrollViewProps } from "./KeyboardAwareScrollView";
|
|
11
|
+
export type { KeyboardToolbarProps } from "./KeyboardToolbar";
|
package/src/constants.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// copied from `android.view.WindowManager.LayoutParams`
|
|
2
|
-
export enum AndroidSoftInputModes {
|
|
3
|
-
SOFT_INPUT_ADJUST_NOTHING = 48,
|
|
4
|
-
SOFT_INPUT_ADJUST_PAN = 32,
|
|
5
|
-
SOFT_INPUT_ADJUST_RESIZE = 16,
|
|
6
|
-
SOFT_INPUT_ADJUST_UNSPECIFIED = 0,
|
|
7
|
-
SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,
|
|
8
|
-
SOFT_INPUT_MASK_ADJUST = 240,
|
|
9
|
-
SOFT_INPUT_MASK_STATE = 15,
|
|
10
|
-
SOFT_INPUT_MODE_CHANGED = 512,
|
|
11
|
-
SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,
|
|
12
|
-
SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,
|
|
13
|
-
SOFT_INPUT_STATE_HIDDEN = 2,
|
|
14
|
-
SOFT_INPUT_STATE_UNCHANGED = 1,
|
|
15
|
-
// temporarily disable this rule to avoid breaking changes.
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
17
|
-
SOFT_INPUT_STATE_UNSPECIFIED = 0,
|
|
18
|
-
SOFT_INPUT_STATE_VISIBLE = 4,
|
|
19
|
-
}
|
|
1
|
+
// copied from `android.view.WindowManager.LayoutParams`
|
|
2
|
+
export enum AndroidSoftInputModes {
|
|
3
|
+
SOFT_INPUT_ADJUST_NOTHING = 48,
|
|
4
|
+
SOFT_INPUT_ADJUST_PAN = 32,
|
|
5
|
+
SOFT_INPUT_ADJUST_RESIZE = 16,
|
|
6
|
+
SOFT_INPUT_ADJUST_UNSPECIFIED = 0,
|
|
7
|
+
SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,
|
|
8
|
+
SOFT_INPUT_MASK_ADJUST = 240,
|
|
9
|
+
SOFT_INPUT_MASK_STATE = 15,
|
|
10
|
+
SOFT_INPUT_MODE_CHANGED = 512,
|
|
11
|
+
SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,
|
|
12
|
+
SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,
|
|
13
|
+
SOFT_INPUT_STATE_HIDDEN = 2,
|
|
14
|
+
SOFT_INPUT_STATE_UNCHANGED = 1,
|
|
15
|
+
// temporarily disable this rule to avoid breaking changes.
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
17
|
+
SOFT_INPUT_STATE_UNSPECIFIED = 0,
|
|
18
|
+
SOFT_INPUT_STATE_VISIBLE = 4,
|
|
19
|
+
}
|