@react-native-ohos/react-native-keyboard-controller 1.12.8 → 1.12.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +603 -19
  4. package/harmony/keyboard_controller/BuildProfile.ets +16 -16
  5. package/harmony/keyboard_controller/Index.ets +8 -29
  6. package/harmony/keyboard_controller/ResourceTable.txt +8 -8
  7. package/harmony/keyboard_controller/build-profile.json5 +31 -31
  8. package/harmony/keyboard_controller/hvigorfile.ts +6 -6
  9. package/harmony/keyboard_controller/obfuscation-rules.txt +17 -17
  10. package/harmony/keyboard_controller/oh-package-lock.json5 +28 -18
  11. package/harmony/keyboard_controller/oh-package.json5 +11 -11
  12. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -7
  13. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +119 -96
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -111
  15. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -98
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +816 -274
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +147 -101
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -64
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -85
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +88 -109
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -84
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -60
  23. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -46
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -48
  25. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -64
  26. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -77
  27. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -45
  28. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -49
  29. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -186
  30. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -112
  31. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -64
  32. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -77
  33. package/harmony/keyboard_controller/src/main/ets/Logger.ts +45 -66
  34. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +49 -70
  35. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +405 -245
  36. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +107 -119
  37. package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -62
  38. package/harmony/keyboard_controller/src/main/module.json +29 -29
  39. package/harmony/keyboard_controller/src/main/module.json5 +11 -11
  40. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -8
  41. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -8
  42. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -8
  43. package/harmony/keyboard_controller/ts.ets +8 -29
  44. package/harmony/keyboard_controller.har +0 -0
  45. package/lib/commonjs/animated.js +4 -16
  46. package/lib/commonjs/animated.js.map +1 -1
  47. package/lib/commonjs/bindings.js +3 -3
  48. package/lib/commonjs/bindings.js.map +1 -1
  49. package/lib/commonjs/bindings.native.js +3 -3
  50. package/lib/commonjs/bindings.native.js.map +1 -1
  51. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
  52. package/lib/commonjs/components/KeyboardAvoidingView/index.js +3 -3
  53. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  54. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +43 -41
  55. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  56. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
  57. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  58. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
  59. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  60. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
  61. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
  62. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -1
  63. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -1
  64. package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
  65. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
  66. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
  67. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -1
  68. package/lib/commonjs/components/index.js.map +1 -1
  69. package/lib/commonjs/constants.js.map +1 -1
  70. package/lib/commonjs/context.js.map +1 -1
  71. package/lib/commonjs/hooks/index.js.map +1 -1
  72. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -1
  73. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/commonjs/internal.js +18 -18
  76. package/lib/commonjs/internal.js.map +1 -1
  77. package/lib/commonjs/monkey-patch.android.js +4 -4
  78. package/lib/commonjs/monkey-patch.android.js.map +1 -1
  79. package/lib/commonjs/monkey-patch.js.map +1 -1
  80. package/lib/commonjs/reanimated.js.map +1 -1
  81. package/lib/commonjs/reanimated.native.js.map +1 -1
  82. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  83. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  84. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
  85. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
  86. package/lib/commonjs/types.js.map +1 -1
  87. package/lib/commonjs/utils.js.map +1 -1
  88. package/lib/module/animated.js +5 -17
  89. package/lib/module/animated.js.map +1 -1
  90. package/lib/module/bindings.js +3 -3
  91. package/lib/module/bindings.js.map +1 -1
  92. package/lib/module/bindings.native.js +3 -3
  93. package/lib/module/bindings.native.js.map +1 -1
  94. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
  95. package/lib/module/components/KeyboardAvoidingView/index.js +3 -3
  96. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  97. package/lib/module/components/KeyboardAwareScrollView/index.js +44 -42
  98. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  99. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
  100. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  101. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
  102. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  103. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -1
  104. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -1
  105. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -1
  106. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -1
  107. package/lib/module/components/KeyboardToolbar/index.js +3 -3
  108. package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
  109. package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
  110. package/lib/module/components/hooks/useColorScheme.js.map +1 -1
  111. package/lib/module/components/index.js.map +1 -1
  112. package/lib/module/constants.js.map +1 -1
  113. package/lib/module/context.js.map +1 -1
  114. package/lib/module/hooks/index.js.map +1 -1
  115. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -1
  116. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
  117. package/lib/module/index.js.map +1 -1
  118. package/lib/module/internal.js +18 -18
  119. package/lib/module/internal.js.map +1 -1
  120. package/lib/module/monkey-patch.android.js +4 -4
  121. package/lib/module/monkey-patch.android.js.map +1 -1
  122. package/lib/module/monkey-patch.js.map +1 -1
  123. package/lib/module/reanimated.js.map +1 -1
  124. package/lib/module/reanimated.native.js.map +1 -1
  125. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  126. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  127. package/lib/module/specs/NativeKeyboardController.js.map +1 -1
  128. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
  129. package/lib/module/types.js.map +1 -1
  130. package/lib/module/utils.js.map +1 -1
  131. package/lib/typescript/types.d.ts +1 -0
  132. package/package.json +181 -178
  133. package/src/animated.tsx +246 -253
  134. package/src/bindings.native.ts +57 -57
  135. package/src/bindings.ts +38 -38
  136. package/src/components/KeyboardAvoidingView/hooks.ts +58 -58
  137. package/src/components/KeyboardAvoidingView/index.tsx +156 -156
  138. package/src/components/KeyboardAwareScrollView/index.tsx +381 -373
  139. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
  140. package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
  141. package/src/components/KeyboardStickyView/index.tsx +57 -57
  142. package/src/components/KeyboardToolbar/Arrow.tsx +80 -80
  143. package/src/components/KeyboardToolbar/Button.tsx +98 -98
  144. package/src/components/KeyboardToolbar/colors.native.ts +37 -37
  145. package/src/components/KeyboardToolbar/colors.ts +16 -16
  146. package/src/components/KeyboardToolbar/index.tsx +211 -211
  147. package/src/components/KeyboardToolbar/types.ts +40 -40
  148. package/src/components/hooks/useColorScheme.ts +5 -5
  149. package/src/components/index.ts +11 -11
  150. package/src/constants.ts +19 -19
  151. package/src/context.ts +65 -65
  152. package/src/hooks/index.ts +90 -90
  153. package/src/hooks/useWindowDimensions/index.android.ts +33 -33
  154. package/src/hooks/useWindowDimensions/index.ts +1 -1
  155. package/src/index.ts +21 -21
  156. package/src/internal.ts +84 -84
  157. package/src/monkey-patch.android.ts +44 -44
  158. package/src/monkey-patch.ts +4 -4
  159. package/src/reanimated.native.ts +132 -132
  160. package/src/reanimated.ts +29 -29
  161. package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -70
  162. package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -15
  163. package/src/specs/NativeKeyboardController.ts +19 -19
  164. package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
  165. package/src/types.ts +212 -211
  166. package/src/utils.ts +1 -1
@@ -1,211 +1,211 @@
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 { KeyboardController } 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 { ReactNode } from "react";
17
-
18
- export type KeyboardToolbarProps = {
19
- /** An element that is shown in the middle of the toolbar. */
20
- content?: JSX.Element | null;
21
- /** A set of dark/light colors consumed by toolbar component. */
22
- theme?: KeyboardToolbarTheme;
23
- /** Custom text for done button. */
24
- doneText?: ReactNode;
25
- /** Custom touchable component for toolbar (used for prev/next/done buttons). */
26
- button?: typeof Button;
27
- /** Custom icon component used to display next/prev buttons. */
28
- icon?: typeof Arrow;
29
- /**
30
- * Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
31
- * and want to show only `Done` button. Default to `true`.
32
- */
33
- showArrows?: boolean;
34
- /**
35
- * A callback that is called when the user presses the next button along with the default action.
36
- */
37
- onNextCallback?: () => void;
38
- /**
39
- * A callback that is called when the user presses the previous button along with the default action.
40
- */
41
- onPrevCallback?: () => void;
42
- /**
43
- * A callback that is called when the user presses the done button along with the default action.
44
- */
45
- onDoneCallback?: () => void;
46
- /**
47
- * A component that applies blur effect to the toolbar.
48
- */
49
- blur?: JSX.Element | null;
50
- /**
51
- * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
52
- */
53
- opacity?: HEX;
54
- };
55
- const TEST_ID_KEYBOARD_TOOLBAR = "keyboard.toolbar";
56
- const TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;
57
- const TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;
58
- const TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;
59
- const TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;
60
-
61
- const KEYBOARD_TOOLBAR_HEIGHT = 42;
62
- const DEFAULT_OPACITY: HEX = "FF";
63
- const offset = { closed: KEYBOARD_TOOLBAR_HEIGHT };
64
-
65
- const dismissKeyboard = () => KeyboardController.dismiss();
66
- const goToNextField = () => KeyboardController.setFocusTo("next");
67
- const goToPrevField = () => KeyboardController.setFocusTo("prev");
68
-
69
- /**
70
- * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
71
- * `Done` buttons.
72
- */
73
- const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
74
- content,
75
- theme = colors,
76
- doneText,
77
- button,
78
- icon,
79
- showArrows = true,
80
- onNextCallback,
81
- onPrevCallback,
82
- onDoneCallback,
83
- blur = null,
84
- opacity = DEFAULT_OPACITY,
85
- }) => {
86
- const colorScheme = useColorScheme();
87
- const [inputs, setInputs] = useState({
88
- current: 0,
89
- count: 0,
90
- });
91
- const isPrevDisabled = inputs.current === 0;
92
- const isNextDisabled = inputs.current === inputs.count - 1;
93
-
94
- useEffect(() => {
95
- const subscription = FocusedInputEvents.addListener("focusDidSet", (e) => {
96
- setInputs(e);
97
- });
98
-
99
- return subscription.remove;
100
- }, []);
101
- const doneStyle = useMemo(
102
- () => [styles.doneButton, { color: theme[colorScheme].primary }],
103
- [colorScheme, theme],
104
- );
105
- const toolbarStyle = useMemo(
106
- () => [
107
- styles.toolbar,
108
- {
109
- backgroundColor: `${theme[colorScheme].background}${opacity}`,
110
- },
111
- ],
112
- [colorScheme, opacity, theme],
113
- );
114
- const ButtonContainer = button || Button;
115
- const IconContainer = icon || Arrow;
116
-
117
- const onPressNext = useCallback(() => {
118
- goToNextField();
119
- onNextCallback?.();
120
- }, [onNextCallback]);
121
- const onPressPrev = useCallback(() => {
122
- goToPrevField();
123
- onPrevCallback?.();
124
- }, [onPrevCallback]);
125
- const onPressDone = useCallback(() => {
126
- dismissKeyboard();
127
- onDoneCallback?.();
128
- }, [onDoneCallback]);
129
-
130
- return (
131
- <KeyboardStickyView offset={offset}>
132
- <View style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
133
- {blur}
134
- {showArrows && (
135
- <>
136
- <ButtonContainer
137
- accessibilityLabel="Previous"
138
- accessibilityHint="Will move focus to previous field"
139
- disabled={isPrevDisabled}
140
- onPress={onPressPrev}
141
- testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}
142
- theme={theme}
143
- >
144
- <IconContainer
145
- disabled={isPrevDisabled}
146
- type="prev"
147
- theme={theme}
148
- />
149
- </ButtonContainer>
150
- <ButtonContainer
151
- accessibilityLabel="Next"
152
- accessibilityHint="Will move focus to next field"
153
- disabled={isNextDisabled}
154
- onPress={onPressNext}
155
- testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}
156
- theme={theme}
157
- >
158
- <IconContainer
159
- disabled={isNextDisabled}
160
- type="next"
161
- theme={theme}
162
- />
163
- </ButtonContainer>
164
- </>
165
- )}
166
-
167
- <View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>
168
- {content}
169
- </View>
170
- <ButtonContainer
171
- accessibilityLabel="Done"
172
- accessibilityHint="Will close the keyboard"
173
- onPress={onPressDone}
174
- testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}
175
- rippleRadius={28}
176
- style={styles.doneButtonContainer}
177
- theme={theme}
178
- >
179
- <Text style={doneStyle} maxFontSizeMultiplier={1.3}>
180
- {doneText || "Done"}
181
- </Text>
182
- </ButtonContainer>
183
- </View>
184
- </KeyboardStickyView>
185
- );
186
- };
187
-
188
- const styles = StyleSheet.create({
189
- flex: {
190
- flex: 1,
191
- },
192
- toolbar: {
193
- position: "absolute",
194
- bottom: 0,
195
- alignItems: "center",
196
- width: "100%",
197
- flexDirection: "row",
198
- height: KEYBOARD_TOOLBAR_HEIGHT,
199
- paddingHorizontal: 8,
200
- },
201
- doneButton: {
202
- fontWeight: "600",
203
- fontSize: 15,
204
- },
205
- doneButtonContainer: {
206
- marginRight: 8,
207
- },
208
- });
209
-
210
- export { colors as DefaultKeyboardToolbarTheme };
211
- 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 { KeyboardController } 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 { ReactNode } from "react";
17
+
18
+ export type KeyboardToolbarProps = {
19
+ /** An element that is shown in the middle of the toolbar. */
20
+ content?: JSX.Element | null;
21
+ /** A set of dark/light colors consumed by toolbar component. */
22
+ theme?: KeyboardToolbarTheme;
23
+ /** Custom text for done button. */
24
+ doneText?: ReactNode;
25
+ /** Custom touchable component for toolbar (used for prev/next/done buttons). */
26
+ button?: typeof Button;
27
+ /** Custom icon component used to display next/prev buttons. */
28
+ icon?: typeof Arrow;
29
+ /**
30
+ * Whether to show next and previous buttons. Can be useful to set it to `false` if you have only one input
31
+ * and want to show only `Done` button. Default to `true`.
32
+ */
33
+ showArrows?: boolean;
34
+ /**
35
+ * A callback that is called when the user presses the next button along with the default action.
36
+ */
37
+ onNextCallback?: () => void;
38
+ /**
39
+ * A callback that is called when the user presses the previous button along with the default action.
40
+ */
41
+ onPrevCallback?: () => void;
42
+ /**
43
+ * A callback that is called when the user presses the done button along with the default action.
44
+ */
45
+ onDoneCallback?: () => void;
46
+ /**
47
+ * A component that applies blur effect to the toolbar.
48
+ */
49
+ blur?: JSX.Element | null;
50
+ /**
51
+ * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
52
+ */
53
+ opacity?: HEX;
54
+ };
55
+ const TEST_ID_KEYBOARD_TOOLBAR = "keyboard.toolbar";
56
+ const TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;
57
+ const TEST_ID_KEYBOARD_TOOLBAR_NEXT = `${TEST_ID_KEYBOARD_TOOLBAR}.next`;
58
+ const TEST_ID_KEYBOARD_TOOLBAR_CONTENT = `${TEST_ID_KEYBOARD_TOOLBAR}.content`;
59
+ const TEST_ID_KEYBOARD_TOOLBAR_DONE = `${TEST_ID_KEYBOARD_TOOLBAR}.done`;
60
+
61
+ const KEYBOARD_TOOLBAR_HEIGHT = 42;
62
+ const DEFAULT_OPACITY: HEX = "FF";
63
+ const offset = { closed: KEYBOARD_TOOLBAR_HEIGHT };
64
+
65
+ const dismissKeyboard = () => KeyboardController.dismiss();
66
+ const goToNextField = () => KeyboardController.setFocusTo("next");
67
+ const goToPrevField = () => KeyboardController.setFocusTo("prev");
68
+
69
+ /**
70
+ * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
71
+ * `Done` buttons.
72
+ */
73
+ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
74
+ content,
75
+ theme = colors,
76
+ doneText,
77
+ button,
78
+ icon,
79
+ showArrows = true,
80
+ onNextCallback,
81
+ onPrevCallback,
82
+ onDoneCallback,
83
+ blur = null,
84
+ opacity = DEFAULT_OPACITY,
85
+ }) => {
86
+ const colorScheme = useColorScheme();
87
+ const [inputs, setInputs] = useState({
88
+ current: 0,
89
+ count: 0,
90
+ });
91
+ const isPrevDisabled = inputs.current === 0;
92
+ const isNextDisabled = inputs.current === inputs.count - 1;
93
+
94
+ useEffect(() => {
95
+ const subscription = FocusedInputEvents.addListener("focusDidSet", (e) => {
96
+ setInputs(e);
97
+ });
98
+
99
+ return subscription.remove;
100
+ }, []);
101
+ const doneStyle = useMemo(
102
+ () => [styles.doneButton, { color: theme[colorScheme].primary }],
103
+ [colorScheme, theme],
104
+ );
105
+ const toolbarStyle = useMemo(
106
+ () => [
107
+ styles.toolbar,
108
+ {
109
+ backgroundColor: `${theme[colorScheme].background}${opacity}`,
110
+ },
111
+ ],
112
+ [colorScheme, opacity, theme],
113
+ );
114
+ const ButtonContainer = button || Button;
115
+ const IconContainer = icon || Arrow;
116
+
117
+ const onPressNext = useCallback(() => {
118
+ goToNextField();
119
+ onNextCallback?.();
120
+ }, [onNextCallback]);
121
+ const onPressPrev = useCallback(() => {
122
+ goToPrevField();
123
+ onPrevCallback?.();
124
+ }, [onPrevCallback]);
125
+ const onPressDone = useCallback(() => {
126
+ dismissKeyboard();
127
+ onDoneCallback?.();
128
+ }, [onDoneCallback]);
129
+
130
+ return (
131
+ <KeyboardStickyView offset={offset}>
132
+ <View style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
133
+ {blur}
134
+ {showArrows && (
135
+ <>
136
+ <ButtonContainer
137
+ accessibilityLabel="Previous"
138
+ accessibilityHint="Will move focus to previous field"
139
+ disabled={isPrevDisabled}
140
+ onPress={onPressPrev}
141
+ testID={TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS}
142
+ theme={theme}
143
+ >
144
+ <IconContainer
145
+ disabled={isPrevDisabled}
146
+ type="prev"
147
+ theme={theme}
148
+ />
149
+ </ButtonContainer>
150
+ <ButtonContainer
151
+ accessibilityLabel="Next"
152
+ accessibilityHint="Will move focus to next field"
153
+ disabled={isNextDisabled}
154
+ onPress={onPressNext}
155
+ testID={TEST_ID_KEYBOARD_TOOLBAR_NEXT}
156
+ theme={theme}
157
+ >
158
+ <IconContainer
159
+ disabled={isNextDisabled}
160
+ type="next"
161
+ theme={theme}
162
+ />
163
+ </ButtonContainer>
164
+ </>
165
+ )}
166
+
167
+ <View style={styles.flex} testID={TEST_ID_KEYBOARD_TOOLBAR_CONTENT}>
168
+ {content}
169
+ </View>
170
+ <ButtonContainer
171
+ accessibilityLabel="Done"
172
+ accessibilityHint="Will close the keyboard"
173
+ onPress={onPressDone}
174
+ testID={TEST_ID_KEYBOARD_TOOLBAR_DONE}
175
+ rippleRadius={28}
176
+ style={styles.doneButtonContainer}
177
+ theme={theme}
178
+ >
179
+ <Text style={doneStyle} maxFontSizeMultiplier={1.3}>
180
+ {doneText || "Done"}
181
+ </Text>
182
+ </ButtonContainer>
183
+ </View>
184
+ </KeyboardStickyView>
185
+ );
186
+ };
187
+
188
+ const styles = StyleSheet.create({
189
+ flex: {
190
+ flex: 1,
191
+ },
192
+ toolbar: {
193
+ position: "absolute",
194
+ bottom: 0,
195
+ alignItems: "center",
196
+ width: "100%",
197
+ flexDirection: "row",
198
+ height: KEYBOARD_TOOLBAR_HEIGHT,
199
+ paddingHorizontal: 8,
200
+ },
201
+ doneButton: {
202
+ fontWeight: "600",
203
+ fontSize: 15,
204
+ },
205
+ doneButtonContainer: {
206
+ marginRight: 8,
207
+ },
208
+ });
209
+
210
+ export { colors as DefaultKeyboardToolbarTheme };
211
+ 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;
@@ -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
+ }