@react-native-ohos/react-native-keyboard-controller 1.12.8-beta.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 (251) 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 +30 -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-lock.json5 +19 -0
  12. package/harmony/keyboard_controller/oh-package.json5 +11 -0
  13. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
  15. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +111 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +98 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +274 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +101 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +64 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +85 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +110 -0
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +84 -0
  23. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +60 -0
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +46 -0
  25. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +48 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +64 -0
  27. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +77 -0
  28. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +45 -0
  29. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +49 -0
  30. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -0
  31. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -0
  32. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +64 -0
  33. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +77 -0
  34. package/harmony/keyboard_controller/src/main/ets/Logger.ts +67 -0
  35. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +70 -0
  36. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +245 -0
  37. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +119 -0
  38. package/harmony/keyboard_controller/src/main/ets/Type.ts +62 -0
  39. package/harmony/keyboard_controller/src/main/module.json +29 -0
  40. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  41. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  42. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  43. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  44. package/harmony/keyboard_controller/ts.ets +30 -0
  45. package/harmony/keyboard_controller.har +0 -0
  46. package/lib/commonjs/animated.js +188 -0
  47. package/lib/commonjs/animated.js.map +1 -0
  48. package/lib/commonjs/bindings.js +38 -0
  49. package/lib/commonjs/bindings.js.map +1 -0
  50. package/lib/commonjs/bindings.native.js +37 -0
  51. package/lib/commonjs/bindings.native.js.map +1 -0
  52. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +66 -0
  53. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  54. package/lib/commonjs/components/KeyboardAvoidingView/index.js +102 -0
  55. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  56. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +255 -0
  57. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  58. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  59. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  60. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  61. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  62. package/lib/commonjs/components/KeyboardStickyView/index.js +40 -0
  63. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  64. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  65. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  66. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  67. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  68. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  69. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  70. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  71. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  72. package/lib/commonjs/components/KeyboardToolbar/index.js +152 -0
  73. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  74. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  75. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  76. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  77. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  78. package/lib/commonjs/components/index.js +42 -0
  79. package/lib/commonjs/components/index.js.map +1 -0
  80. package/lib/commonjs/constants.js +27 -0
  81. package/lib/commonjs/constants.js.map +1 -0
  82. package/lib/commonjs/context.js +42 -0
  83. package/lib/commonjs/context.js.map +1 -0
  84. package/lib/commonjs/hooks/index.js +104 -0
  85. package/lib/commonjs/hooks/index.js.map +1 -0
  86. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +29 -0
  87. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  88. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  89. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  90. package/lib/commonjs/index.js +116 -0
  91. package/lib/commonjs/index.js.map +1 -0
  92. package/lib/commonjs/internal.js +73 -0
  93. package/lib/commonjs/internal.js.map +1 -0
  94. package/lib/commonjs/monkey-patch.android.js +57 -0
  95. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  96. package/lib/commonjs/monkey-patch.js +11 -0
  97. package/lib/commonjs/monkey-patch.js.map +1 -0
  98. package/lib/commonjs/reanimated.js +12 -0
  99. package/lib/commonjs/reanimated.js.map +1 -0
  100. package/lib/commonjs/reanimated.native.js +88 -0
  101. package/lib/commonjs/reanimated.native.js.map +1 -0
  102. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  103. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  104. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  105. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  106. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  107. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  108. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  109. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  110. package/lib/commonjs/types.js +6 -0
  111. package/lib/commonjs/types.js.map +1 -0
  112. package/lib/commonjs/utils.js +9 -0
  113. package/lib/commonjs/utils.js.map +1 -0
  114. package/lib/module/animated.js +180 -0
  115. package/lib/module/animated.js.map +1 -0
  116. package/lib/module/bindings.js +32 -0
  117. package/lib/module/bindings.js.map +1 -0
  118. package/lib/module/bindings.native.js +31 -0
  119. package/lib/module/bindings.native.js.map +1 -0
  120. package/lib/module/components/KeyboardAvoidingView/hooks.js +59 -0
  121. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  122. package/lib/module/components/KeyboardAvoidingView/index.js +95 -0
  123. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  124. package/lib/module/components/KeyboardAwareScrollView/index.js +248 -0
  125. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  126. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  127. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  128. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  129. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  130. package/lib/module/components/KeyboardStickyView/index.js +33 -0
  131. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  132. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  133. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  134. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  135. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  136. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  137. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  138. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  139. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  140. package/lib/module/components/KeyboardToolbar/index.js +140 -0
  141. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  142. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  143. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  144. package/lib/module/components/hooks/useColorScheme.js +4 -0
  145. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  146. package/lib/module/components/index.js +5 -0
  147. package/lib/module/components/index.js.map +1 -0
  148. package/lib/module/constants.js +21 -0
  149. package/lib/module/constants.js.map +1 -0
  150. package/lib/module/context.js +35 -0
  151. package/lib/module/context.js.map +1 -0
  152. package/lib/module/hooks/index.js +68 -0
  153. package/lib/module/hooks/index.js.map +1 -0
  154. package/lib/module/hooks/useWindowDimensions/index.android.js +22 -0
  155. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  156. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  157. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  158. package/lib/module/index.js +10 -0
  159. package/lib/module/index.js.map +1 -0
  160. package/lib/module/internal.js +66 -0
  161. package/lib/module/internal.js.map +1 -0
  162. package/lib/module/monkey-patch.android.js +47 -0
  163. package/lib/module/monkey-patch.android.js.map +1 -0
  164. package/lib/module/monkey-patch.js +5 -0
  165. package/lib/module/monkey-patch.js.map +1 -0
  166. package/lib/module/reanimated.js +6 -0
  167. package/lib/module/reanimated.js.map +1 -0
  168. package/lib/module/reanimated.native.js +78 -0
  169. package/lib/module/reanimated.native.js.map +1 -0
  170. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  171. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  172. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  173. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  174. package/lib/module/specs/NativeKeyboardController.js +3 -0
  175. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  176. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  177. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  178. package/lib/module/types.js +2 -0
  179. package/lib/module/types.js.map +1 -0
  180. package/lib/module/utils.js +2 -0
  181. package/lib/module/utils.js.map +1 -0
  182. package/lib/typescript/animated.d.ts +31 -0
  183. package/lib/typescript/bindings.d.ts +12 -0
  184. package/lib/typescript/bindings.native.d.ts +12 -0
  185. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +6 -0
  186. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +50 -0
  187. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +25 -0
  188. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  189. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  190. package/lib/typescript/components/KeyboardStickyView/index.d.ts +35 -0
  191. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  192. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +15 -0
  193. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  194. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  195. package/lib/typescript/components/KeyboardToolbar/index.d.ts +50 -0
  196. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  197. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  198. package/lib/typescript/components/index.d.ts +8 -0
  199. package/lib/typescript/constants.d.ts +16 -0
  200. package/lib/typescript/context.d.ts +23 -0
  201. package/lib/typescript/hooks/index.d.ts +17 -0
  202. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  203. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  204. package/lib/typescript/index.d.ts +8 -0
  205. package/lib/typescript/internal.d.ts +30 -0
  206. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  207. package/lib/typescript/monkey-patch.d.ts +2 -0
  208. package/lib/typescript/reanimated.d.ts +5 -0
  209. package/lib/typescript/reanimated.native.d.ts +7 -0
  210. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +53 -0
  211. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
  212. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  213. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  214. package/lib/typescript/types.d.ts +133 -0
  215. package/lib/typescript/utils.d.ts +1 -0
  216. package/package.json +178 -0
  217. package/react-native-keyboard-controller.podspec +61 -0
  218. package/src/animated.tsx +253 -0
  219. package/src/bindings.native.ts +57 -0
  220. package/src/bindings.ts +38 -0
  221. package/src/components/KeyboardAvoidingView/hooks.ts +58 -0
  222. package/src/components/KeyboardAvoidingView/index.tsx +156 -0
  223. package/src/components/KeyboardAwareScrollView/index.tsx +373 -0
  224. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  225. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  226. package/src/components/KeyboardStickyView/index.tsx +57 -0
  227. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  228. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  229. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  230. package/src/components/KeyboardToolbar/colors.ts +16 -0
  231. package/src/components/KeyboardToolbar/index.tsx +211 -0
  232. package/src/components/KeyboardToolbar/types.ts +40 -0
  233. package/src/components/hooks/useColorScheme.ts +5 -0
  234. package/src/components/index.ts +11 -0
  235. package/src/constants.ts +19 -0
  236. package/src/context.ts +65 -0
  237. package/src/hooks/index.ts +90 -0
  238. package/src/hooks/useWindowDimensions/index.android.ts +33 -0
  239. package/src/hooks/useWindowDimensions/index.ts +1 -0
  240. package/src/index.ts +21 -0
  241. package/src/internal.ts +84 -0
  242. package/src/monkey-patch.android.ts +44 -0
  243. package/src/monkey-patch.ts +4 -0
  244. package/src/reanimated.native.ts +132 -0
  245. package/src/reanimated.ts +29 -0
  246. package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -0
  247. package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -0
  248. package/src/specs/NativeKeyboardController.ts +19 -0
  249. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  250. package/src/types.ts +211 -0
  251. package/src/utils.ts +1 -0
@@ -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
+ };
@@ -0,0 +1,90 @@
1
+ import { useEffect } from "react";
2
+
3
+ import { KeyboardController } from "../bindings";
4
+ import { AndroidSoftInputModes } from "../constants";
5
+ import { useKeyboardContext } from "../context";
6
+ import { uuid } from "../utils";
7
+
8
+ import type { AnimatedContext, ReanimatedContext } from "../context";
9
+ import type { FocusedInputHandler, KeyboardHandler } from "../types";
10
+ import type { DependencyList } from "react";
11
+
12
+ export const useResizeMode = () => {
13
+ useEffect(() => {
14
+ KeyboardController.setInputMode(
15
+ AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
16
+ );
17
+
18
+ return () => KeyboardController.setDefaultMode();
19
+ }, []);
20
+ };
21
+
22
+ export const useKeyboardAnimation = (): AnimatedContext => {
23
+ useResizeMode();
24
+ const context = useKeyboardContext();
25
+
26
+ return context.animated;
27
+ };
28
+
29
+ export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
30
+ useResizeMode();
31
+ const context = useKeyboardContext();
32
+
33
+ return context.reanimated;
34
+ };
35
+
36
+ export function useGenericKeyboardHandler(
37
+ handler: KeyboardHandler,
38
+ deps?: DependencyList,
39
+ ) {
40
+ const context = useKeyboardContext();
41
+
42
+ useEffect(() => {
43
+ const key = uuid();
44
+
45
+ context.setKeyboardHandlers({ [key]: handler });
46
+
47
+ return () => {
48
+ context.setKeyboardHandlers({ [key]: undefined });
49
+ };
50
+ }, deps);
51
+ }
52
+
53
+ export function useKeyboardHandler(
54
+ handler: KeyboardHandler,
55
+ deps?: DependencyList,
56
+ ) {
57
+ useResizeMode();
58
+ useGenericKeyboardHandler(handler, deps);
59
+ }
60
+
61
+ export function useKeyboardController() {
62
+ const context = useKeyboardContext();
63
+
64
+ return { setEnabled: context.setEnabled, enabled: context.enabled };
65
+ }
66
+
67
+ export function useReanimatedFocusedInput() {
68
+ const context = useKeyboardContext();
69
+
70
+ return { input: context.layout };
71
+ }
72
+
73
+ export function useFocusedInputHandler(
74
+ handler?: FocusedInputHandler,
75
+ deps?: DependencyList,
76
+ ) {
77
+ const context = useKeyboardContext();
78
+
79
+ useEffect(() => {
80
+ const key = uuid();
81
+
82
+ context.setInputHandlers({ [key]: handler });
83
+
84
+ return () => {
85
+ context.setInputHandlers({ [key]: undefined });
86
+ };
87
+ }, deps);
88
+ }
89
+
90
+ export * from "./useWindowDimensions";
@@ -0,0 +1,33 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { WindowDimensionsEvents } from "../../bindings";
4
+
5
+ import type { WindowDimensionsEventData } from "../../types";
6
+
7
+ let initialDimensions: WindowDimensionsEventData = {
8
+ width: 0,
9
+ height: 0,
10
+ };
11
+
12
+ WindowDimensionsEvents.addListener("windowDidResize", (e) => {
13
+ initialDimensions = e;
14
+ });
15
+
16
+ export const useWindowDimensions = () => {
17
+ const [dimensions, setDimensions] = useState(initialDimensions);
18
+
19
+ useEffect(() => {
20
+ const subscription = WindowDimensionsEvents.addListener(
21
+ "windowDidResize",
22
+ (e) => {
23
+ setDimensions(e);
24
+ },
25
+ );
26
+
27
+ return () => {
28
+ subscription.remove();
29
+ };
30
+ }, []);
31
+
32
+ return dimensions;
33
+ };
@@ -0,0 +1 @@
1
+ export { useWindowDimensions } from "react-native";
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ export * from "./bindings";
2
+ export * from "./animated";
3
+ export * from "./context";
4
+ export * from "./hooks";
5
+ export * from "./constants";
6
+ export * from "./types";
7
+
8
+ export {
9
+ KeyboardAvoidingView,
10
+ KeyboardStickyView,
11
+ KeyboardAwareScrollView,
12
+ // keyboard toolbar
13
+ KeyboardToolbar,
14
+ DefaultKeyboardToolbarTheme,
15
+ } from "./components";
16
+ export type {
17
+ KeyboardAvoidingViewProps,
18
+ KeyboardStickyViewProps,
19
+ KeyboardAwareScrollViewProps,
20
+ KeyboardToolbarProps,
21
+ } from "./components";