react-native-keyboard-controller 1.18.5 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +5 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/EditText.kt +8 -1
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +52 -8
- package/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt +25 -5
- package/android/src/main/java/com/reactnativekeyboardcontroller/modules/statusbar/StatusBarManagerCompatModuleImpl.kt +31 -29
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt +5 -8
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/KeyboardGestureAreaReactViewGroup.kt +6 -7
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +5 -2
- package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +0 -3
- package/ios/KeyboardControllerModule.mm +3 -3
- package/ios/KeyboardControllerModuleImpl.swift +26 -16
- package/ios/views/KeyboardControllerView.mm +6 -1
- package/ios/views/KeyboardControllerViewManager.swift +2 -1
- package/ios/views/KeyboardExtenderManager.mm +1 -2
- package/jest/index.js +17 -0
- package/lib/commonjs/animated.js +1 -2
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +1 -2
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +1 -2
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +1 -2
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js +1 -2
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Button.js +1 -2
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Background.js +13 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Background.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Content.js +25 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Content.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Done.js +61 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Done.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Next.js +52 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Next.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Prev.js +52 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/Prev.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/index.js +42 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/types.js +6 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/components/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/context.js +17 -0
- package/lib/commonjs/components/KeyboardToolbar/compound/context.js.map +1 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js +76 -78
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/commonjs/components/index.js +1 -2
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.js +3 -3
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/commonjs/module.js +2 -1
- package/lib/commonjs/module.js.map +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/types/module.js.map +1 -1
- package/lib/commonjs/views/OverKeyboardView/index.js +1 -2
- package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/compound/components/Background.js +6 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Background.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Content.js +18 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Content.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Done.js +54 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Done.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Next.js +44 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Next.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Prev.js +45 -0
- package/lib/module/components/KeyboardToolbar/compound/components/Prev.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/index.js +6 -0
- package/lib/module/components/KeyboardToolbar/compound/components/index.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/components/types.js +2 -0
- package/lib/module/components/KeyboardToolbar/compound/components/types.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/compound/context.js +10 -0
- package/lib/module/components/KeyboardToolbar/compound/context.js.map +1 -0
- package/lib/module/components/KeyboardToolbar/index.js +78 -79
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.js +3 -3
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/module/module.js +2 -1
- package/lib/module/module.js.map +1 -1
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/types/module.js.map +1 -1
- package/lib/typescript/components/KeyboardToolbar/compound/components/Background.d.ts +6 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Content.d.ts +7 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Done.d.ts +7 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Next.d.ts +4 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/Prev.d.ts +4 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/index.d.ts +5 -0
- package/lib/typescript/components/KeyboardToolbar/compound/components/types.d.ts +14 -0
- package/lib/typescript/components/KeyboardToolbar/compound/context.d.ts +9 -0
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +13 -54
- package/lib/typescript/components/KeyboardToolbar/types.d.ts +92 -5
- package/lib/typescript/specs/NativeKeyboardController.d.ts +1 -1
- package/lib/typescript/types/module.d.ts +5 -1
- package/package.json +5 -5
- package/src/components/KeyboardToolbar/compound/components/Background.tsx +9 -0
- package/src/components/KeyboardToolbar/compound/components/Content.tsx +25 -0
- package/src/components/KeyboardToolbar/compound/components/Done.tsx +70 -0
- package/src/components/KeyboardToolbar/compound/components/Next.tsx +55 -0
- package/src/components/KeyboardToolbar/compound/components/Prev.tsx +56 -0
- package/src/components/KeyboardToolbar/compound/components/index.ts +5 -0
- package/src/components/KeyboardToolbar/compound/components/types.ts +15 -0
- package/src/components/KeyboardToolbar/compound/context.ts +25 -0
- package/src/components/KeyboardToolbar/index.tsx +105 -165
- package/src/components/KeyboardToolbar/types.ts +101 -5
- package/src/hooks/useWindowDimensions/index.ts +3 -3
- package/src/module.ts +3 -2
- package/src/specs/NativeKeyboardController.ts +1 -1
- package/src/types/module.ts +5 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import type { KeyboardToolbarTheme } from "../types";
|
|
4
|
+
|
|
5
|
+
type ToolbarContextType = {
|
|
6
|
+
theme: KeyboardToolbarTheme;
|
|
7
|
+
isPrevDisabled: boolean;
|
|
8
|
+
isNextDisabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const ToolbarContext = createContext<ToolbarContextType | undefined>(
|
|
12
|
+
undefined,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const useToolbarContext = () => {
|
|
16
|
+
const context = useContext(ToolbarContext);
|
|
17
|
+
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"KeyboardToolbar.* component must be used inside <KeyboardToolbar>",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return context;
|
|
25
|
+
};
|
|
@@ -1,80 +1,25 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { StyleSheet,
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { FocusedInputEvents } from "../../bindings";
|
|
5
5
|
import { useKeyboardState } from "../../hooks";
|
|
6
|
-
import { KeyboardController } from "../../module";
|
|
7
6
|
import KeyboardStickyView from "../KeyboardStickyView";
|
|
8
7
|
|
|
9
8
|
import Arrow from "./Arrow";
|
|
10
9
|
import Button from "./Button";
|
|
11
10
|
import { colors } from "./colors";
|
|
11
|
+
import { Background, Content, Done, Next, Prev } from "./compound/components";
|
|
12
|
+
import { ToolbarContext } from "./compound/context";
|
|
12
13
|
import {
|
|
13
14
|
DEFAULT_OPACITY,
|
|
14
15
|
KEYBOARD_HAS_ROUNDED_CORNERS,
|
|
15
16
|
KEYBOARD_TOOLBAR_HEIGHT,
|
|
16
17
|
OPENED_OFFSET,
|
|
17
18
|
TEST_ID_KEYBOARD_TOOLBAR,
|
|
18
|
-
TEST_ID_KEYBOARD_TOOLBAR_CONTENT,
|
|
19
|
-
TEST_ID_KEYBOARD_TOOLBAR_DONE,
|
|
20
|
-
TEST_ID_KEYBOARD_TOOLBAR_NEXT,
|
|
21
|
-
TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS,
|
|
22
19
|
} from "./constants";
|
|
23
20
|
|
|
24
|
-
import type {
|
|
25
|
-
import type { KeyboardStickyViewProps } from "../KeyboardStickyView";
|
|
21
|
+
import type { KeyboardToolbarProps } from "./types";
|
|
26
22
|
import type { ReactNode } from "react";
|
|
27
|
-
import type { GestureResponderEvent, ViewProps } from "react-native";
|
|
28
|
-
|
|
29
|
-
type SafeAreaInsets = {
|
|
30
|
-
left: number;
|
|
31
|
-
right: number;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type KeyboardToolbarProps = Omit<
|
|
35
|
-
ViewProps,
|
|
36
|
-
"style" | "testID" | "children"
|
|
37
|
-
> & {
|
|
38
|
-
/** An element that is shown in the middle of the toolbar. */
|
|
39
|
-
content?: React.JSX.Element | null;
|
|
40
|
-
/** A set of dark/light colors consumed by toolbar component. */
|
|
41
|
-
theme?: KeyboardToolbarTheme;
|
|
42
|
-
/** Custom text for done button. */
|
|
43
|
-
doneText?: ReactNode;
|
|
44
|
-
/** Custom touchable component for toolbar (used for prev/next/done buttons). */
|
|
45
|
-
button?: typeof Button;
|
|
46
|
-
/** Custom icon component used to display next/prev buttons. */
|
|
47
|
-
icon?: typeof Arrow;
|
|
48
|
-
/**
|
|
49
|
-
* Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
|
|
50
|
-
* and want to show only `Done` button. Default to `true`.
|
|
51
|
-
*/
|
|
52
|
-
showArrows?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* A callback that is called when the user presses the next button along with the default action.
|
|
55
|
-
*/
|
|
56
|
-
onNextCallback?: (event: GestureResponderEvent) => void;
|
|
57
|
-
/**
|
|
58
|
-
* A callback that is called when the user presses the previous button along with the default action.
|
|
59
|
-
*/
|
|
60
|
-
onPrevCallback?: (event: GestureResponderEvent) => void;
|
|
61
|
-
/**
|
|
62
|
-
* A callback that is called when the user presses the done button along with the default action.
|
|
63
|
-
*/
|
|
64
|
-
onDoneCallback?: (event: GestureResponderEvent) => void;
|
|
65
|
-
/**
|
|
66
|
-
* A component that applies blur effect to the toolbar.
|
|
67
|
-
*/
|
|
68
|
-
blur?: React.JSX.Element | null;
|
|
69
|
-
/**
|
|
70
|
-
* A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
|
|
71
|
-
*/
|
|
72
|
-
opacity?: HEX;
|
|
73
|
-
/**
|
|
74
|
-
* A object containing `left`/`right` properties. Used to specify proper container padding in landscape mode.
|
|
75
|
-
*/
|
|
76
|
-
insets?: SafeAreaInsets;
|
|
77
|
-
} & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
|
|
78
23
|
|
|
79
24
|
/**
|
|
80
25
|
* `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` buttons from left and
|
|
@@ -85,11 +30,20 @@ export type KeyboardToolbarProps = Omit<
|
|
|
85
30
|
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-toolbar|Documentation} page for more details.
|
|
86
31
|
* @example
|
|
87
32
|
* ```tsx
|
|
88
|
-
* <KeyboardToolbar
|
|
33
|
+
* <KeyboardToolbar>
|
|
34
|
+
* <KeyboardToolbar.Done text="Close" />
|
|
35
|
+
* </KeyboardToolbar>
|
|
89
36
|
* ```
|
|
90
37
|
*/
|
|
91
|
-
const KeyboardToolbar: React.FC<KeyboardToolbarProps>
|
|
38
|
+
const KeyboardToolbar: React.FC<KeyboardToolbarProps> & {
|
|
39
|
+
Background: typeof Background;
|
|
40
|
+
Content: typeof Content;
|
|
41
|
+
Prev: typeof Prev;
|
|
42
|
+
Next: typeof Next;
|
|
43
|
+
Done: typeof Done;
|
|
44
|
+
} = (props) => {
|
|
92
45
|
const {
|
|
46
|
+
children,
|
|
93
47
|
content,
|
|
94
48
|
theme = colors,
|
|
95
49
|
doneText = "Done",
|
|
@@ -113,6 +67,8 @@ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = (props) => {
|
|
|
113
67
|
});
|
|
114
68
|
const isPrevDisabled = inputs.current === 0;
|
|
115
69
|
const isNextDisabled = inputs.current === inputs.count - 1;
|
|
70
|
+
const buttonContainer = button ?? Button;
|
|
71
|
+
const iconContainer = icon ?? Arrow;
|
|
116
72
|
|
|
117
73
|
useEffect(() => {
|
|
118
74
|
const subscription = FocusedInputEvents.addListener("focusDidSet", (e) => {
|
|
@@ -121,10 +77,6 @@ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = (props) => {
|
|
|
121
77
|
|
|
122
78
|
return subscription.remove;
|
|
123
79
|
}, []);
|
|
124
|
-
const doneStyle = useMemo(
|
|
125
|
-
() => [styles.doneButton, { color: theme[colorScheme].primary }],
|
|
126
|
-
[colorScheme, theme],
|
|
127
|
-
);
|
|
128
80
|
const toolbarStyle = useMemo(
|
|
129
81
|
() => [
|
|
130
82
|
styles.toolbar,
|
|
@@ -159,108 +111,98 @@ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = (props) => {
|
|
|
159
111
|
}),
|
|
160
112
|
[closed, opened],
|
|
161
113
|
);
|
|
162
|
-
const ButtonContainer = button || Button;
|
|
163
|
-
const IconContainer = icon || Arrow;
|
|
164
|
-
|
|
165
|
-
const onPressNext = useCallback(
|
|
166
|
-
(event: GestureResponderEvent) => {
|
|
167
|
-
onNextCallback?.(event);
|
|
168
114
|
|
|
169
|
-
|
|
170
|
-
|
|
115
|
+
let backgroundElement: ReactNode = null;
|
|
116
|
+
let arrowsElement: ReactNode = null;
|
|
117
|
+
let contentContainer: ReactNode = null;
|
|
118
|
+
let doneElement: ReactNode = null;
|
|
119
|
+
|
|
120
|
+
if (children) {
|
|
121
|
+
let prevChild: ReactNode = null;
|
|
122
|
+
let nextChild: ReactNode = null;
|
|
123
|
+
let contentChild: ReactNode = null;
|
|
124
|
+
let doneChild: ReactNode = null;
|
|
125
|
+
let backgroundChild: ReactNode = null;
|
|
126
|
+
|
|
127
|
+
React.Children.forEach(children, (child) => {
|
|
128
|
+
if (!React.isValidElement(child)) {
|
|
129
|
+
return;
|
|
171
130
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
131
|
+
const type = child.type;
|
|
132
|
+
|
|
133
|
+
if (type === Background) {
|
|
134
|
+
backgroundChild = child;
|
|
135
|
+
} else if (type === Content) {
|
|
136
|
+
contentChild = child;
|
|
137
|
+
} else if (type === Prev) {
|
|
138
|
+
prevChild = child;
|
|
139
|
+
} else if (type === Next) {
|
|
140
|
+
nextChild = child;
|
|
141
|
+
} else if (type === Done) {
|
|
142
|
+
doneChild = child;
|
|
181
143
|
}
|
|
182
|
-
}
|
|
183
|
-
[onPrevCallback],
|
|
184
|
-
);
|
|
185
|
-
const onPressDone = useCallback(
|
|
186
|
-
(event: GestureResponderEvent) => {
|
|
187
|
-
onDoneCallback?.(event);
|
|
144
|
+
});
|
|
188
145
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
146
|
+
backgroundElement = backgroundChild;
|
|
147
|
+
doneElement = doneChild;
|
|
148
|
+
arrowsElement =
|
|
149
|
+
prevChild || nextChild ? (
|
|
150
|
+
<View style={styles.arrows}>
|
|
151
|
+
{prevChild}
|
|
152
|
+
{nextChild}
|
|
153
|
+
</View>
|
|
154
|
+
) : null;
|
|
155
|
+
contentContainer = contentChild ?? <Content>{contentChild}</Content>;
|
|
156
|
+
} else {
|
|
157
|
+
backgroundElement = blur;
|
|
158
|
+
arrowsElement = showArrows ? (
|
|
159
|
+
<View style={styles.arrows}>
|
|
160
|
+
<Prev
|
|
161
|
+
button={buttonContainer}
|
|
162
|
+
icon={iconContainer}
|
|
163
|
+
onPress={onPrevCallback}
|
|
164
|
+
/>
|
|
165
|
+
<Next
|
|
166
|
+
button={buttonContainer}
|
|
167
|
+
icon={iconContainer}
|
|
168
|
+
onPress={onNextCallback}
|
|
169
|
+
/>
|
|
170
|
+
</View>
|
|
171
|
+
) : null;
|
|
172
|
+
contentContainer = <Content>{content}</Content>;
|
|
173
|
+
doneElement = doneText ? (
|
|
174
|
+
<Done button={buttonContainer} text={doneText} onPress={onDoneCallback} />
|
|
175
|
+
) : null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const contextValue = useMemo(
|
|
179
|
+
() => ({
|
|
180
|
+
theme,
|
|
181
|
+
isPrevDisabled,
|
|
182
|
+
isNextDisabled,
|
|
183
|
+
}),
|
|
184
|
+
[theme, isPrevDisabled, isNextDisabled],
|
|
194
185
|
);
|
|
195
186
|
|
|
196
187
|
return (
|
|
197
|
-
<
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
{
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
accessibilityLabel="Previous"
|
|
209
|
-
disabled={isPrevDisabled}
|
|
210
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}
|
|
211
|
-
theme={theme}
|
|
212
|
-
onPress={onPressPrev}
|
|
213
|
-
>
|
|
214
|
-
<IconContainer
|
|
215
|
-
disabled={isPrevDisabled}
|
|
216
|
-
theme={theme}
|
|
217
|
-
type="prev"
|
|
218
|
-
/>
|
|
219
|
-
</ButtonContainer>
|
|
220
|
-
<ButtonContainer
|
|
221
|
-
accessibilityHint="Moves focus to the next field"
|
|
222
|
-
accessibilityLabel="Next"
|
|
223
|
-
disabled={isNextDisabled}
|
|
224
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}
|
|
225
|
-
theme={theme}
|
|
226
|
-
onPress={onPressNext}
|
|
227
|
-
>
|
|
228
|
-
<IconContainer
|
|
229
|
-
disabled={isNextDisabled}
|
|
230
|
-
theme={theme}
|
|
231
|
-
type="next"
|
|
232
|
-
/>
|
|
233
|
-
</ButtonContainer>
|
|
234
|
-
</View>
|
|
235
|
-
)}
|
|
236
|
-
|
|
237
|
-
<View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>
|
|
238
|
-
{content}
|
|
188
|
+
<ToolbarContext.Provider value={contextValue}>
|
|
189
|
+
<KeyboardStickyView
|
|
190
|
+
enabled={enabled}
|
|
191
|
+
offset={offset}
|
|
192
|
+
style={containerStyle}
|
|
193
|
+
>
|
|
194
|
+
<View {...rest} style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
|
|
195
|
+
{backgroundElement}
|
|
196
|
+
{arrowsElement}
|
|
197
|
+
{contentContainer}
|
|
198
|
+
{doneElement}
|
|
239
199
|
</View>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
accessibilityHint="Closes the keyboard"
|
|
243
|
-
accessibilityLabel="Done"
|
|
244
|
-
rippleRadius={28}
|
|
245
|
-
style={styles.doneButtonContainer}
|
|
246
|
-
testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}
|
|
247
|
-
theme={theme}
|
|
248
|
-
onPress={onPressDone}
|
|
249
|
-
>
|
|
250
|
-
<Text maxFontSizeMultiplier={1.3} style={doneStyle}>
|
|
251
|
-
{doneText}
|
|
252
|
-
</Text>
|
|
253
|
-
</ButtonContainer>
|
|
254
|
-
)}
|
|
255
|
-
</View>
|
|
256
|
-
</KeyboardStickyView>
|
|
200
|
+
</KeyboardStickyView>
|
|
201
|
+
</ToolbarContext.Provider>
|
|
257
202
|
);
|
|
258
203
|
};
|
|
259
204
|
|
|
260
205
|
const styles = StyleSheet.create({
|
|
261
|
-
flex: {
|
|
262
|
-
flex: 1,
|
|
263
|
-
},
|
|
264
206
|
toolbar: {
|
|
265
207
|
position: "absolute",
|
|
266
208
|
bottom: 0,
|
|
@@ -273,14 +215,6 @@ const styles = StyleSheet.create({
|
|
|
273
215
|
flexDirection: "row",
|
|
274
216
|
paddingLeft: 8,
|
|
275
217
|
},
|
|
276
|
-
doneButton: {
|
|
277
|
-
fontWeight: "600",
|
|
278
|
-
fontSize: 15,
|
|
279
|
-
},
|
|
280
|
-
doneButtonContainer: {
|
|
281
|
-
marginRight: 16,
|
|
282
|
-
marginLeft: 8,
|
|
283
|
-
},
|
|
284
218
|
floating: {
|
|
285
219
|
alignSelf: "center",
|
|
286
220
|
borderRadius: 20,
|
|
@@ -288,5 +222,11 @@ const styles = StyleSheet.create({
|
|
|
288
222
|
},
|
|
289
223
|
});
|
|
290
224
|
|
|
291
|
-
|
|
225
|
+
KeyboardToolbar.Background = Background;
|
|
226
|
+
KeyboardToolbar.Content = Content;
|
|
227
|
+
KeyboardToolbar.Prev = Prev;
|
|
228
|
+
KeyboardToolbar.Next = Next;
|
|
229
|
+
KeyboardToolbar.Done = Done;
|
|
230
|
+
|
|
231
|
+
export { colors as DefaultKeyboardToolbarTheme, KeyboardToolbarProps };
|
|
292
232
|
export default KeyboardToolbar;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Arrow from "./Arrow";
|
|
2
|
+
import type Button from "./Button";
|
|
3
|
+
import type { KeyboardStickyViewProps } from "../KeyboardStickyView";
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import type {
|
|
6
|
+
ColorValue,
|
|
7
|
+
GestureResponderEvent,
|
|
8
|
+
ViewProps,
|
|
9
|
+
} from "react-native";
|
|
2
10
|
|
|
3
11
|
type Theme = {
|
|
4
|
-
/** Color for arrow when it's enabled */
|
|
12
|
+
/** Color for arrow when it's enabled. */
|
|
5
13
|
primary: ColorValue;
|
|
6
|
-
/** Color for arrow when it's disabled */
|
|
14
|
+
/** Color for arrow when it's disabled. */
|
|
7
15
|
disabled: ColorValue;
|
|
8
|
-
/** Keyboard toolbar background color */
|
|
16
|
+
/** Keyboard toolbar background color. */
|
|
9
17
|
background: string;
|
|
10
|
-
/** Color for ripple effect (on button touch) on Android */
|
|
18
|
+
/** Color for ripple effect (on button touch) on Android. */
|
|
11
19
|
ripple: ColorValue;
|
|
12
20
|
};
|
|
13
21
|
export type KeyboardToolbarTheme = {
|
|
@@ -38,3 +46,91 @@ type HexSymbol =
|
|
|
38
46
|
| "e"
|
|
39
47
|
| "f";
|
|
40
48
|
export type HEX = `${HexSymbol}${HexSymbol}`;
|
|
49
|
+
|
|
50
|
+
type SafeAreaInsets = {
|
|
51
|
+
left: number;
|
|
52
|
+
right: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type KeyboardToolbarProps = Omit<
|
|
56
|
+
ViewProps,
|
|
57
|
+
"style" | "testID" | "children"
|
|
58
|
+
> & {
|
|
59
|
+
/**
|
|
60
|
+
* An element that is shown in the middle of the toolbar.
|
|
61
|
+
*
|
|
62
|
+
* @deprecated Use compound API with `<KeyboardToolbar.Content />` component instead.
|
|
63
|
+
*/
|
|
64
|
+
content?: React.JSX.Element | null;
|
|
65
|
+
/** A set of dark/light colors consumed by toolbar component. */
|
|
66
|
+
theme?: KeyboardToolbarTheme;
|
|
67
|
+
/**
|
|
68
|
+
* Custom text for done button.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated Use compound API with `<KeyboardToolbar.Done />` component and `text` prop instead.
|
|
71
|
+
*/
|
|
72
|
+
doneText?: ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* Custom touchable component for toolbar (used for prev/next/done buttons).
|
|
75
|
+
*
|
|
76
|
+
* @deprecated Use `button` property for corresponding element instead:
|
|
77
|
+
* ```tsx
|
|
78
|
+
* <KeyboardToolbar>
|
|
79
|
+
* <KeyboardToolbar.Prev button={MyCustomButton} />
|
|
80
|
+
* </KeyboardToolbar>
|
|
81
|
+
* ```.
|
|
82
|
+
*/
|
|
83
|
+
button?: typeof Button;
|
|
84
|
+
/**
|
|
85
|
+
* Custom icon component used to display next/prev buttons.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Use `icon` property for corresponding element instead:
|
|
88
|
+
* ```tsx
|
|
89
|
+
* <KeyboardToolbar>
|
|
90
|
+
* <KeyboardToolbar.Prev icon={MyCustomIcon} />
|
|
91
|
+
* </KeyboardToolbar>
|
|
92
|
+
* ```.
|
|
93
|
+
*/
|
|
94
|
+
icon?: typeof Arrow;
|
|
95
|
+
/**
|
|
96
|
+
* Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
|
|
97
|
+
* and want to show only `Done` button. Default to `true`.
|
|
98
|
+
*
|
|
99
|
+
* @deprecated Use compound API and conditional rendering for `<KeyboardToolbar.Next />` and `<KeyboardToolbar.Prev />`.
|
|
100
|
+
*/
|
|
101
|
+
showArrows?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* A callback that is called when the user presses the next button along with the default action.
|
|
104
|
+
*
|
|
105
|
+
* @deprecated Use compound API with `<KeyboardToolbar.Next />` and `onPress` callback instead.
|
|
106
|
+
*/
|
|
107
|
+
onNextCallback?: (event: GestureResponderEvent) => void;
|
|
108
|
+
/**
|
|
109
|
+
* A callback that is called when the user presses the previous button along with the default action.
|
|
110
|
+
*
|
|
111
|
+
* @deprecated Use compound API with `<KeyboardToolbar.Prev />` and `onPress` callback instead.
|
|
112
|
+
*/
|
|
113
|
+
onPrevCallback?: (event: GestureResponderEvent) => void;
|
|
114
|
+
/**
|
|
115
|
+
* A callback that is called when the user presses the done button along with the default action.
|
|
116
|
+
*
|
|
117
|
+
* @deprecated Use compound API with `<KeyboardToolbar.Done />` and `onPress` callback instead.
|
|
118
|
+
*/
|
|
119
|
+
onDoneCallback?: (event: GestureResponderEvent) => void;
|
|
120
|
+
/**
|
|
121
|
+
* A component that applies blur effect to the toolbar.
|
|
122
|
+
*
|
|
123
|
+
* @deprecated Use compound API and `<KeyboardToolbar.Effect />` instead.
|
|
124
|
+
*/
|
|
125
|
+
blur?: React.JSX.Element | null;
|
|
126
|
+
/**
|
|
127
|
+
* A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
|
|
128
|
+
*/
|
|
129
|
+
opacity?: HEX;
|
|
130
|
+
/**
|
|
131
|
+
* A object containing `left`/`right` properties. Used to specify proper container padding in landscape mode.
|
|
132
|
+
*/
|
|
133
|
+
insets?: SafeAreaInsets;
|
|
134
|
+
/** JSX children in case if compound API is used. */
|
|
135
|
+
children?: ReactNode;
|
|
136
|
+
} & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
|
|
@@ -5,11 +5,11 @@ import { WindowDimensionsEvents } from "../../bindings";
|
|
|
5
5
|
|
|
6
6
|
import type { WindowDimensionsEventData } from "../../types";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const window = Dimensions.get("window");
|
|
9
9
|
|
|
10
10
|
let initialDimensions: WindowDimensionsEventData = {
|
|
11
|
-
width:
|
|
12
|
-
height:
|
|
11
|
+
width: window.width,
|
|
12
|
+
height: window.height,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
WindowDimensionsEvents.addListener("windowDidResize", (e) => {
|
package/src/module.ts
CHANGED
|
@@ -26,8 +26,9 @@ KeyboardEvents.addListener("keyboardDidShow", (e) => {
|
|
|
26
26
|
lastState = e;
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const dismiss = async (options?: DismissOptions): Promise<void> => {
|
|
29
|
+
const dismiss = async (options?: Partial<DismissOptions>): Promise<void> => {
|
|
30
30
|
const keepFocus = options?.keepFocus ?? false;
|
|
31
|
+
const animated = options?.animated ?? true;
|
|
31
32
|
|
|
32
33
|
return new Promise((resolve) => {
|
|
33
34
|
if (isClosed) {
|
|
@@ -41,7 +42,7 @@ const dismiss = async (options?: DismissOptions): Promise<void> => {
|
|
|
41
42
|
subscription.remove();
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
KeyboardControllerNative.dismiss(keepFocus);
|
|
45
|
+
KeyboardControllerNative.dismiss(keepFocus, animated);
|
|
45
46
|
});
|
|
46
47
|
};
|
|
47
48
|
const isVisible = () => !isClosed;
|
|
@@ -9,7 +9,7 @@ export interface Spec extends TurboModule {
|
|
|
9
9
|
setInputMode(mode: number): void;
|
|
10
10
|
setDefaultMode(): void;
|
|
11
11
|
preload(): void;
|
|
12
|
-
dismiss(keepFocus: boolean): void;
|
|
12
|
+
dismiss(keepFocus: boolean, animated: boolean): void;
|
|
13
13
|
setFocusTo(direction: string): void;
|
|
14
14
|
|
|
15
15
|
// event emitter
|
package/src/types/module.ts
CHANGED
|
@@ -53,6 +53,10 @@ export type DismissOptions = {
|
|
|
53
53
|
* A boolean property indicating whether focus should be kept on the input after dismissing the keyboard. Default is `false`.
|
|
54
54
|
*/
|
|
55
55
|
keepFocus: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* A boolean property controlling whether dismissal should be animated. Default is `true`.
|
|
58
|
+
*/
|
|
59
|
+
animated: boolean;
|
|
56
60
|
};
|
|
57
61
|
export type KeyboardControllerModule = {
|
|
58
62
|
// android only
|
|
@@ -111,7 +115,7 @@ export type KeyboardControllerNativeModule = {
|
|
|
111
115
|
// ios only
|
|
112
116
|
preload: () => void;
|
|
113
117
|
// all platforms
|
|
114
|
-
dismiss: (keepFocus: boolean) => void;
|
|
118
|
+
dismiss: (keepFocus: boolean, animated: boolean) => void;
|
|
115
119
|
setFocusTo: (direction: Direction) => void;
|
|
116
120
|
// native event module stuff
|
|
117
121
|
addListener: (eventName: string) => void;
|