@react-native-ohos/react-native-keyboard-controller 1.12.8-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.
Files changed (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +19 -0
  4. package/harmony/keyboard_controller/BuildProfile.ets +17 -0
  5. package/harmony/keyboard_controller/Index.ets +9 -0
  6. package/harmony/keyboard_controller/ResourceTable.txt +9 -0
  7. package/harmony/keyboard_controller/build-profile.json5 +31 -0
  8. package/harmony/keyboard_controller/consumer-rules.txt +0 -0
  9. package/harmony/keyboard_controller/hvigorfile.ts +6 -0
  10. package/harmony/keyboard_controller/obfuscation-rules.txt +18 -0
  11. package/harmony/keyboard_controller/oh-package.json5 +11 -0
  12. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
  13. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -0
  15. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +158 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +74 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +89 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -0
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -0
  23. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -0
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -0
  25. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -0
  27. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -0
  28. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -0
  29. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -0
  30. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -0
  31. package/harmony/keyboard_controller/src/main/ets/Logger.ts +46 -0
  32. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +46 -0
  33. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +210 -0
  34. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +98 -0
  35. package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -0
  36. package/harmony/keyboard_controller/src/main/module.json +29 -0
  37. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  38. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  39. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  40. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  41. package/harmony/keyboard_controller/ts.ets +9 -0
  42. package/harmony/keyboard_controller.har +0 -0
  43. package/lib/commonjs/animated.js +174 -0
  44. package/lib/commonjs/animated.js.map +1 -0
  45. package/lib/commonjs/bindings.js +38 -0
  46. package/lib/commonjs/bindings.js.map +1 -0
  47. package/lib/commonjs/bindings.native.js +37 -0
  48. package/lib/commonjs/bindings.native.js.map +1 -0
  49. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +66 -0
  50. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  51. package/lib/commonjs/components/KeyboardAvoidingView/index.js +102 -0
  52. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  53. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +255 -0
  54. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  55. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  56. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  57. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  58. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  59. package/lib/commonjs/components/KeyboardStickyView/index.js +40 -0
  60. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  61. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  62. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  63. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  64. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  65. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  66. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  67. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  68. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  69. package/lib/commonjs/components/KeyboardToolbar/index.js +152 -0
  70. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  71. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  72. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  73. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  74. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  75. package/lib/commonjs/components/index.js +42 -0
  76. package/lib/commonjs/components/index.js.map +1 -0
  77. package/lib/commonjs/constants.js +25 -0
  78. package/lib/commonjs/constants.js.map +1 -0
  79. package/lib/commonjs/context.js +42 -0
  80. package/lib/commonjs/context.js.map +1 -0
  81. package/lib/commonjs/hooks/index.js +104 -0
  82. package/lib/commonjs/hooks/index.js.map +1 -0
  83. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +29 -0
  84. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  85. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  86. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  87. package/lib/commonjs/index.js +116 -0
  88. package/lib/commonjs/index.js.map +1 -0
  89. package/lib/commonjs/internal.js +73 -0
  90. package/lib/commonjs/internal.js.map +1 -0
  91. package/lib/commonjs/monkey-patch.android.js +57 -0
  92. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  93. package/lib/commonjs/monkey-patch.js +11 -0
  94. package/lib/commonjs/monkey-patch.js.map +1 -0
  95. package/lib/commonjs/reanimated.js +12 -0
  96. package/lib/commonjs/reanimated.js.map +1 -0
  97. package/lib/commonjs/reanimated.native.js +88 -0
  98. package/lib/commonjs/reanimated.native.js.map +1 -0
  99. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  100. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  101. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  102. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  103. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  104. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  105. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  106. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  107. package/lib/commonjs/types.js +6 -0
  108. package/lib/commonjs/types.js.map +1 -0
  109. package/lib/commonjs/utils.js +9 -0
  110. package/lib/commonjs/utils.js.map +1 -0
  111. package/lib/module/animated.js +166 -0
  112. package/lib/module/animated.js.map +1 -0
  113. package/lib/module/bindings.js +32 -0
  114. package/lib/module/bindings.js.map +1 -0
  115. package/lib/module/bindings.native.js +31 -0
  116. package/lib/module/bindings.native.js.map +1 -0
  117. package/lib/module/components/KeyboardAvoidingView/hooks.js +59 -0
  118. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  119. package/lib/module/components/KeyboardAvoidingView/index.js +95 -0
  120. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  121. package/lib/module/components/KeyboardAwareScrollView/index.js +248 -0
  122. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  123. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  124. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  125. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  126. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  127. package/lib/module/components/KeyboardStickyView/index.js +33 -0
  128. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  129. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  130. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  131. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  132. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  133. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  134. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  135. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  136. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  137. package/lib/module/components/KeyboardToolbar/index.js +140 -0
  138. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  139. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  140. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  141. package/lib/module/components/hooks/useColorScheme.js +4 -0
  142. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  143. package/lib/module/components/index.js +5 -0
  144. package/lib/module/components/index.js.map +1 -0
  145. package/lib/module/constants.js +19 -0
  146. package/lib/module/constants.js.map +1 -0
  147. package/lib/module/context.js +35 -0
  148. package/lib/module/context.js.map +1 -0
  149. package/lib/module/hooks/index.js +68 -0
  150. package/lib/module/hooks/index.js.map +1 -0
  151. package/lib/module/hooks/useWindowDimensions/index.android.js +22 -0
  152. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  153. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  154. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  155. package/lib/module/index.js +10 -0
  156. package/lib/module/index.js.map +1 -0
  157. package/lib/module/internal.js +66 -0
  158. package/lib/module/internal.js.map +1 -0
  159. package/lib/module/monkey-patch.android.js +47 -0
  160. package/lib/module/monkey-patch.android.js.map +1 -0
  161. package/lib/module/monkey-patch.js +5 -0
  162. package/lib/module/monkey-patch.js.map +1 -0
  163. package/lib/module/reanimated.js +6 -0
  164. package/lib/module/reanimated.js.map +1 -0
  165. package/lib/module/reanimated.native.js +78 -0
  166. package/lib/module/reanimated.native.js.map +1 -0
  167. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  168. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  169. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  170. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  171. package/lib/module/specs/NativeKeyboardController.js +3 -0
  172. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  173. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  174. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  175. package/lib/module/types.js +2 -0
  176. package/lib/module/types.js.map +1 -0
  177. package/lib/module/utils.js +2 -0
  178. package/lib/module/utils.js.map +1 -0
  179. package/lib/typescript/animated.d.ts +31 -0
  180. package/lib/typescript/bindings.d.ts +12 -0
  181. package/lib/typescript/bindings.native.d.ts +12 -0
  182. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +6 -0
  183. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +50 -0
  184. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +25 -0
  185. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  186. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  187. package/lib/typescript/components/KeyboardStickyView/index.d.ts +35 -0
  188. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  189. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +15 -0
  190. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  191. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  192. package/lib/typescript/components/KeyboardToolbar/index.d.ts +50 -0
  193. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  194. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  195. package/lib/typescript/components/index.d.ts +8 -0
  196. package/lib/typescript/constants.d.ts +16 -0
  197. package/lib/typescript/context.d.ts +23 -0
  198. package/lib/typescript/hooks/index.d.ts +17 -0
  199. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  200. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  201. package/lib/typescript/index.d.ts +8 -0
  202. package/lib/typescript/internal.d.ts +30 -0
  203. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  204. package/lib/typescript/monkey-patch.d.ts +2 -0
  205. package/lib/typescript/reanimated.d.ts +5 -0
  206. package/lib/typescript/reanimated.native.d.ts +7 -0
  207. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +53 -0
  208. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
  209. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  210. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  211. package/lib/typescript/types.d.ts +133 -0
  212. package/lib/typescript/utils.d.ts +1 -0
  213. package/package.json +177 -0
  214. package/react-native-keyboard-controller.podspec +61 -0
  215. package/src/animated.tsx +246 -0
  216. package/src/bindings.native.ts +57 -0
  217. package/src/bindings.ts +38 -0
  218. package/src/components/KeyboardAvoidingView/hooks.ts +58 -0
  219. package/src/components/KeyboardAvoidingView/index.tsx +156 -0
  220. package/src/components/KeyboardAwareScrollView/index.tsx +373 -0
  221. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  222. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  223. package/src/components/KeyboardStickyView/index.tsx +57 -0
  224. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  225. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  226. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  227. package/src/components/KeyboardToolbar/colors.ts +16 -0
  228. package/src/components/KeyboardToolbar/index.tsx +211 -0
  229. package/src/components/KeyboardToolbar/types.ts +40 -0
  230. package/src/components/hooks/useColorScheme.ts +5 -0
  231. package/src/components/index.ts +11 -0
  232. package/src/constants.ts +19 -0
  233. package/src/context.ts +65 -0
  234. package/src/hooks/index.ts +90 -0
  235. package/src/hooks/useWindowDimensions/index.android.ts +33 -0
  236. package/src/hooks/useWindowDimensions/index.ts +1 -0
  237. package/src/index.ts +21 -0
  238. package/src/internal.ts +84 -0
  239. package/src/monkey-patch.android.ts +44 -0
  240. package/src/monkey-patch.ts +4 -0
  241. package/src/reanimated.native.ts +132 -0
  242. package/src/reanimated.ts +29 -0
  243. package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -0
  244. package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -0
  245. package/src/specs/NativeKeyboardController.ts +19 -0
  246. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  247. package/src/types.ts +211 -0
  248. package/src/utils.ts +1 -0
@@ -0,0 +1,57 @@
1
+ import React, { forwardRef, useMemo } from "react";
2
+ import Reanimated, {
3
+ interpolate,
4
+ useAnimatedStyle,
5
+ } from "react-native-reanimated";
6
+
7
+ import { useReanimatedKeyboardAnimation } from "../../hooks";
8
+
9
+ import type { View, ViewProps } from "react-native";
10
+
11
+ export type KeyboardStickyViewProps = {
12
+ /**
13
+ * Specify additional offset to the view for given keyboard state.
14
+ */
15
+ offset?: {
16
+ /**
17
+ * Adds additional `translateY` when keyboard is close. By default `0`.
18
+ */
19
+ closed?: number;
20
+ /**
21
+ * Adds additional `translateY` when keyboard is open. By default `0`.
22
+ */
23
+ opened?: number;
24
+ };
25
+ } & ViewProps;
26
+
27
+ const KeyboardStickyView = forwardRef<
28
+ View,
29
+ React.PropsWithChildren<KeyboardStickyViewProps>
30
+ >(
31
+ (
32
+ { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },
33
+ ref,
34
+ ) => {
35
+ const { height, progress } = useReanimatedKeyboardAnimation();
36
+ const stickyViewStyle = useAnimatedStyle(() => {
37
+ const offset = interpolate(progress.value, [0, 1], [closed, opened]);
38
+
39
+ return {
40
+ transform: [{ translateY: height.value + offset }],
41
+ };
42
+ }, [closed, opened]);
43
+
44
+ const styles = useMemo(
45
+ () => [style, stickyViewStyle],
46
+ [style, stickyViewStyle],
47
+ );
48
+
49
+ return (
50
+ <Reanimated.View ref={ref} style={styles} {...props}>
51
+ {children}
52
+ </Reanimated.View>
53
+ );
54
+ },
55
+ );
56
+
57
+ export default KeyboardStickyView;
@@ -0,0 +1,80 @@
1
+ import React, { useMemo } from "react";
2
+ import { Animated, StyleSheet, View } from "react-native";
3
+
4
+ import useColorScheme from "../hooks/useColorScheme";
5
+
6
+ import type { KeyboardToolbarTheme } from "./types";
7
+ import type { ViewStyle } from "react-native";
8
+
9
+ type ArrowProps = {
10
+ type: "prev" | "next";
11
+ disabled?: boolean;
12
+ theme: KeyboardToolbarTheme;
13
+ };
14
+
15
+ const ArrowComponent: React.FC<ArrowProps> = ({ type, disabled, theme }) => {
16
+ const colorScheme = useColorScheme();
17
+
18
+ const color = useMemo(
19
+ () => ({
20
+ backgroundColor: disabled
21
+ ? theme[colorScheme].disabled
22
+ : theme[colorScheme].primary,
23
+ }),
24
+ [disabled, theme, colorScheme],
25
+ );
26
+ const left = useMemo(() => [styles.arrowLeftLine, color], [color]);
27
+ const right = useMemo(() => [styles.arrowRightLine, color], [color]);
28
+
29
+ return (
30
+ <View
31
+ style={
32
+ type === "next" ? styles.arrowDownContainer : styles.arrowUpContainer
33
+ }
34
+ >
35
+ <View style={styles.arrow}>
36
+ <Animated.View style={left} />
37
+ <Animated.View style={right} />
38
+ </View>
39
+ </View>
40
+ );
41
+ };
42
+
43
+ const arrowLine: ViewStyle = {
44
+ width: 13,
45
+ height: 2,
46
+ borderRadius: 1,
47
+ };
48
+ const arrowUpContainer: ViewStyle = {
49
+ marginHorizontal: 5,
50
+ width: 30,
51
+ height: 30,
52
+ justifyContent: "center",
53
+ alignItems: "center",
54
+ };
55
+ const styles = StyleSheet.create({
56
+ arrowUpContainer: arrowUpContainer,
57
+ arrowDownContainer: {
58
+ ...arrowUpContainer,
59
+ transform: [{ rotate: "180deg" }],
60
+ },
61
+ arrow: {
62
+ width: 20,
63
+ height: 20,
64
+ flexDirection: "row",
65
+ alignItems: "center",
66
+ justifyContent: "space-between",
67
+ },
68
+ arrowLeftLine: {
69
+ ...arrowLine,
70
+ transform: [{ rotate: "-45deg" }],
71
+ left: -0.5,
72
+ },
73
+ arrowRightLine: {
74
+ ...arrowLine,
75
+ transform: [{ rotate: "45deg" }],
76
+ left: -5.5,
77
+ },
78
+ });
79
+
80
+ export default ArrowComponent;
@@ -0,0 +1,98 @@
1
+ import React, { useMemo } from "react";
2
+ import {
3
+ Platform,
4
+ TouchableNativeFeedback,
5
+ TouchableOpacity,
6
+ View,
7
+ } from "react-native";
8
+
9
+ import useColorScheme from "../hooks/useColorScheme";
10
+
11
+ import type { KeyboardToolbarTheme } from "./types";
12
+ import type { PropsWithChildren } from "react";
13
+ import type { ViewStyle } from "react-native";
14
+
15
+ type ButtonProps = {
16
+ disabled?: boolean;
17
+ onPress: () => void;
18
+ accessibilityLabel: string;
19
+ accessibilityHint: string;
20
+ testID: string;
21
+ rippleRadius?: number;
22
+ style?: ViewStyle;
23
+ theme: KeyboardToolbarTheme;
24
+ };
25
+
26
+ const ButtonIOS = ({
27
+ children,
28
+ onPress,
29
+ disabled,
30
+ accessibilityLabel,
31
+ accessibilityHint,
32
+ testID,
33
+ style,
34
+ }: PropsWithChildren<ButtonProps>) => {
35
+ // immediately switch to plain view to avoid animation flickering
36
+ // when fade out animation happens and view becomes disabled
37
+ const Container = disabled
38
+ ? (View as unknown as typeof TouchableOpacity)
39
+ : TouchableOpacity;
40
+ const accessibilityState = useMemo(() => ({ disabled }), [disabled]);
41
+
42
+ return (
43
+ <Container
44
+ accessibilityState={accessibilityState}
45
+ accessibilityRole="button"
46
+ accessibilityLabel={accessibilityLabel}
47
+ accessibilityHint={accessibilityHint}
48
+ onPress={onPress}
49
+ style={style}
50
+ testID={testID}
51
+ >
52
+ {children}
53
+ </Container>
54
+ );
55
+ };
56
+ const ButtonAndroid = ({
57
+ children,
58
+ onPress,
59
+ disabled,
60
+ accessibilityLabel,
61
+ accessibilityHint,
62
+ testID,
63
+ rippleRadius = 18,
64
+ style,
65
+ theme,
66
+ }: PropsWithChildren<ButtonProps>) => {
67
+ const colorScheme = useColorScheme();
68
+ const accessibilityState = useMemo(() => ({ disabled }), [disabled]);
69
+ const ripple = useMemo(
70
+ () =>
71
+ TouchableNativeFeedback.Ripple(
72
+ theme[colorScheme].ripple,
73
+ true,
74
+ rippleRadius,
75
+ ),
76
+ [colorScheme, rippleRadius, theme],
77
+ );
78
+
79
+ return (
80
+ <TouchableNativeFeedback
81
+ accessibilityState={accessibilityState}
82
+ accessibilityRole="button"
83
+ accessibilityLabel={accessibilityLabel}
84
+ accessibilityHint={accessibilityHint}
85
+ onPress={onPress}
86
+ background={ripple}
87
+ testID={testID}
88
+ style={style}
89
+ >
90
+ <View style={style}>{children}</View>
91
+ </TouchableNativeFeedback>
92
+ );
93
+ };
94
+
95
+ export default Platform.select({
96
+ android: ButtonAndroid,
97
+ default: ButtonIOS,
98
+ });
@@ -0,0 +1,37 @@
1
+ import { Platform, PlatformColor } from "react-native";
2
+
3
+ import type { KeyboardToolbarTheme } from "./types";
4
+ import type { ColorValue } from "react-native";
5
+
6
+ export const colors: KeyboardToolbarTheme = {
7
+ light: {
8
+ primary: Platform.select<ColorValue>({
9
+ ios: PlatformColor("link"),
10
+ default: "#2c2c2c",
11
+ }),
12
+ disabled: Platform.select<ColorValue>({
13
+ ios: PlatformColor("systemGray4"),
14
+ default: "#B0BEC5",
15
+ }),
16
+ background: Platform.select({
17
+ ios: "#F8F8F8",
18
+ default: "#f3f3f4",
19
+ }),
20
+ ripple: "#bcbcbcbc",
21
+ },
22
+ dark: {
23
+ primary: Platform.select<ColorValue>({
24
+ ios: PlatformColor("label"),
25
+ default: "#fafafa",
26
+ }),
27
+ disabled: Platform.select<ColorValue>({
28
+ ios: PlatformColor("systemGray"),
29
+ default: "#707070",
30
+ }),
31
+ background: Platform.select({
32
+ ios: "#555756",
33
+ default: "#2C2C2E",
34
+ }),
35
+ ripple: "#F8F8F888",
36
+ },
37
+ };
@@ -0,0 +1,16 @@
1
+ import type { KeyboardToolbarTheme } from "./types";
2
+
3
+ export const colors: KeyboardToolbarTheme = {
4
+ light: {
5
+ primary: "#2c2c2c",
6
+ disabled: "#B0BEC5",
7
+ background: "#f3f3f4",
8
+ ripple: "#bcbcbcbc",
9
+ },
10
+ dark: {
11
+ primary: "#fafafa",
12
+ disabled: "#707070",
13
+ background: "#2C2C2E",
14
+ ripple: "#F8F8F888",
15
+ },
16
+ };
@@ -0,0 +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;
@@ -0,0 +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}`;
@@ -0,0 +1,5 @@
1
+ import { useColorScheme as useColorSchemeRN } from "react-native";
2
+
3
+ const useColorScheme = () => useColorSchemeRN() || "light";
4
+
5
+ export default useColorScheme;
@@ -0,0 +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";
@@ -0,0 +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
+ }
package/src/context.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { createContext, useContext } from "react";
2
+ import { Animated } from "react-native";
3
+
4
+ import type {
5
+ FocusedInputHandlers,
6
+ FocusedInputLayoutChangedEvent,
7
+ KeyboardHandlers,
8
+ } from "./types";
9
+ import type React from "react";
10
+ import type { SharedValue } from "react-native-reanimated";
11
+
12
+ export type AnimatedContext = {
13
+ progress: Animated.Value;
14
+ height: Animated.AnimatedMultiplication<number>;
15
+ };
16
+ export type ReanimatedContext = {
17
+ progress: SharedValue<number>;
18
+ height: SharedValue<number>;
19
+ };
20
+ export type KeyboardAnimationContext = {
21
+ enabled: boolean;
22
+ animated: AnimatedContext;
23
+ reanimated: ReanimatedContext;
24
+ layout: SharedValue<FocusedInputLayoutChangedEvent | null>;
25
+ setKeyboardHandlers: (handlers: KeyboardHandlers) => void;
26
+ setInputHandlers: (handlers: FocusedInputHandlers) => void;
27
+ setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
28
+ };
29
+ const NOOP = () => {};
30
+ const withSharedValue = <T>(value: T): SharedValue<T> => ({
31
+ value,
32
+ addListener: NOOP,
33
+ removeListener: NOOP,
34
+ modify: NOOP,
35
+ });
36
+ const DEFAULT_SHARED_VALUE = withSharedValue(0);
37
+ const DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(
38
+ null,
39
+ );
40
+ const defaultContext: KeyboardAnimationContext = {
41
+ enabled: true,
42
+ animated: {
43
+ progress: new Animated.Value(0),
44
+ height: new Animated.Value(0),
45
+ },
46
+ reanimated: {
47
+ progress: DEFAULT_SHARED_VALUE,
48
+ height: DEFAULT_SHARED_VALUE,
49
+ },
50
+ layout: DEFAULT_LAYOUT,
51
+ setKeyboardHandlers: NOOP,
52
+ setInputHandlers: NOOP,
53
+ setEnabled: NOOP,
54
+ };
55
+ export const KeyboardContext = createContext(defaultContext);
56
+ export const useKeyboardContext = () => {
57
+ const context = useContext(KeyboardContext);
58
+ if (__DEV__ && context === defaultContext) {
59
+ console.warn(
60
+ "Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.",
61
+ );
62
+ }
63
+
64
+ return context;
65
+ };