react-native-keyboard-controller 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/android/build.gradle +0 -40
  2. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +44 -8
  3. package/ios/KeyboardController.xcodeproj/project.pbxproj +2 -2
  4. package/ios/KeyboardControllerModule.mm +1 -1
  5. package/ios/KeyboardControllerView.mm +4 -4
  6. package/lib/commonjs/animated.js +14 -59
  7. package/lib/commonjs/animated.js.map +1 -1
  8. package/lib/commonjs/context.js +28 -0
  9. package/lib/commonjs/context.js.map +1 -0
  10. package/lib/commonjs/hooks.js +39 -0
  11. package/lib/commonjs/hooks.js.map +1 -0
  12. package/lib/commonjs/index.js +39 -0
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/internal.js +27 -0
  15. package/lib/commonjs/internal.js.map +1 -0
  16. package/lib/commonjs/monkey-patch.js +3 -3
  17. package/lib/commonjs/monkey-patch.js.map +1 -1
  18. package/lib/commonjs/native.js +24 -21
  19. package/lib/commonjs/native.js.map +1 -1
  20. package/lib/commonjs/replicas.js +2 -2
  21. package/lib/commonjs/replicas.js.map +1 -1
  22. package/lib/commonjs/{KeyboardControllerViewNativeComponent.js → specs/KeyboardControllerViewNativeComponent.js} +0 -0
  23. package/lib/commonjs/{KeyboardControllerViewNativeComponent.js.map → specs/KeyboardControllerViewNativeComponent.js.map} +0 -0
  24. package/lib/commonjs/{NativeKeyboardController.js → specs/NativeKeyboardController.js} +0 -0
  25. package/lib/commonjs/{NativeKeyboardController.js.map → specs/NativeKeyboardController.js.map} +0 -0
  26. package/lib/commonjs/{NativeStatusBarManagerCompat.js → specs/NativeStatusBarManagerCompat.js} +0 -0
  27. package/lib/commonjs/{NativeStatusBarManagerCompat.js.map → specs/NativeStatusBarManagerCompat.js.map} +0 -0
  28. package/lib/commonjs/types.js +6 -0
  29. package/lib/commonjs/types.js.map +1 -0
  30. package/lib/module/animated.js +12 -50
  31. package/lib/module/animated.js.map +1 -1
  32. package/lib/module/context.js +18 -0
  33. package/lib/module/context.js.map +1 -0
  34. package/lib/module/hooks.js +20 -0
  35. package/lib/module/hooks.js.map +1 -0
  36. package/lib/module/index.js +3 -0
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/internal.js +19 -0
  39. package/lib/module/internal.js.map +1 -0
  40. package/lib/module/monkey-patch.js +4 -3
  41. package/lib/module/monkey-patch.js.map +1 -1
  42. package/lib/module/native.js +23 -17
  43. package/lib/module/native.js.map +1 -1
  44. package/lib/module/replicas.js +1 -1
  45. package/lib/module/replicas.js.map +1 -1
  46. package/lib/module/{KeyboardControllerViewNativeComponent.js → specs/KeyboardControllerViewNativeComponent.js} +0 -0
  47. package/lib/module/{KeyboardControllerViewNativeComponent.js.map → specs/KeyboardControllerViewNativeComponent.js.map} +0 -0
  48. package/lib/module/{NativeKeyboardController.js → specs/NativeKeyboardController.js} +0 -0
  49. package/lib/module/{NativeKeyboardController.js.map → specs/NativeKeyboardController.js.map} +0 -0
  50. package/lib/module/{NativeStatusBarManagerCompat.js → specs/NativeStatusBarManagerCompat.js} +0 -0
  51. package/lib/module/{NativeStatusBarManagerCompat.js.map → specs/NativeStatusBarManagerCompat.js.map} +0 -0
  52. package/lib/module/types.js +2 -0
  53. package/lib/module/types.js.map +1 -0
  54. package/lib/typescript/animated.d.ts +1 -17
  55. package/lib/typescript/context.d.ts +16 -0
  56. package/lib/typescript/hooks.d.ts +4 -0
  57. package/lib/typescript/index.d.ts +3 -0
  58. package/lib/typescript/internal.d.ts +4 -0
  59. package/lib/typescript/native.d.ts +14 -26
  60. package/lib/typescript/{KeyboardControllerViewNativeComponent.d.ts → specs/KeyboardControllerViewNativeComponent.d.ts} +0 -0
  61. package/lib/typescript/{NativeKeyboardController.d.ts → specs/NativeKeyboardController.d.ts} +0 -0
  62. package/lib/typescript/{NativeStatusBarManagerCompat.d.ts → specs/NativeStatusBarManagerCompat.d.ts} +0 -0
  63. package/lib/typescript/types.d.ts +23 -0
  64. package/package.json +17 -20
  65. package/react-native-keyboard-controller.podspec +2 -1
  66. package/src/animated.tsx +12 -75
  67. package/src/context.ts +28 -0
  68. package/src/hooks.ts +28 -0
  69. package/src/index.ts +3 -0
  70. package/src/internal.ts +27 -0
  71. package/src/{monkey-patch.tsx → monkey-patch.ts} +3 -6
  72. package/src/native.ts +37 -66
  73. package/src/replicas.ts +1 -1
  74. package/src/{KeyboardControllerViewNativeComponent.ts → specs/KeyboardControllerViewNativeComponent.ts} +0 -0
  75. package/src/{NativeKeyboardController.ts → specs/NativeKeyboardController.ts} +0 -0
  76. package/src/{NativeStatusBarManagerCompat.ts → specs/NativeStatusBarManagerCompat.ts} +0 -0
  77. package/src/types.ts +42 -0
  78. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  79. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  80. package/android/gradlew +0 -185
  81. package/android/gradlew.bat +0 -89
  82. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +0 -31
  83. package/android/src/main/jni/Android.mk +0 -42
  84. package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +0 -71
  85. package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +0 -35
  86. package/android/src/main/jni/OnLoad.cpp +0 -9
  87. package/lib/commonjs/architecture.js +0 -13
  88. package/lib/commonjs/architecture.js.map +0 -1
  89. package/lib/module/architecture.js +0 -5
  90. package/lib/module/architecture.js.map +0 -1
  91. package/lib/typescript/architecture.d.ts +0 -2
  92. package/src/architecture.ts +0 -4
@@ -1,34 +1,22 @@
1
- import { NativeSyntheticEvent, ViewProps } from 'react-native';
1
+ import type { KeyboardControllerEvents, KeyboardControllerModule, KeyboardEventData } from './types';
2
2
  export declare enum AndroidSoftInputModes {
3
3
  SOFT_INPUT_ADJUST_NOTHING = 48,
4
4
  SOFT_INPUT_ADJUST_PAN = 32,
5
5
  SOFT_INPUT_ADJUST_RESIZE = 16,
6
- SOFT_INPUT_ADJUST_UNSPECIFIED = 0
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
+ SOFT_INPUT_STATE_UNSPECIFIED = 0,
16
+ SOFT_INPUT_STATE_VISIBLE = 4
7
17
  }
8
- export declare type NativeEvent = {
9
- progress: number;
10
- height: number;
11
- };
12
- export declare type EventWithName<T> = {
13
- eventName: string;
14
- } & T;
15
- export declare type KeyboardControllerProps = {
16
- onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
17
- onKeyboardMoveReanimated: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
18
- statusBarTranslucent?: boolean;
19
- } & ViewProps;
20
- declare type KeyboardController = {
21
- setDefaultMode: () => void;
22
- setInputMode: (mode: AndroidSoftInputModes) => void;
23
- };
24
- export declare const KeyboardController: KeyboardController;
25
- declare type KeyboardControllerEvents = 'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide';
26
- declare type KeyboardEvent = {
27
- height: number;
28
- };
18
+ export declare const KeyboardController: KeyboardControllerModule;
29
19
  export declare const KeyboardEvents: {
30
- addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEvent) => void) => import("react-native").EmitterSubscription;
20
+ addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => import("react-native").EmitterSubscription;
31
21
  };
32
22
  export declare const KeyboardControllerView: any;
33
- export declare const useResizeMode: () => void;
34
- export {};
@@ -0,0 +1,23 @@
1
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
2
+ export declare type NativeEvent = {
3
+ progress: number;
4
+ height: number;
5
+ };
6
+ export declare type EventWithName<T> = {
7
+ eventName: string;
8
+ } & T;
9
+ export declare type KeyboardControllerProps = {
10
+ onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
11
+ onKeyboardMoveReanimated: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
12
+ statusBarTranslucent?: boolean;
13
+ } & ViewProps;
14
+ export declare type KeyboardControllerModule = {
15
+ setDefaultMode: () => void;
16
+ setInputMode: (mode: number) => void;
17
+ addListener: (eventName: string) => void;
18
+ removeListeners: (count: number) => void;
19
+ };
20
+ export declare type KeyboardControllerEvents = 'keyboardWillShow' | 'keyboardDidShow' | 'keyboardWillHide' | 'keyboardDidHide';
21
+ export declare type KeyboardEventData = {
22
+ height: number;
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Keyboard manager which works in identical way on both iOS and Android",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -17,6 +17,9 @@
17
17
  "!lib/typescript/example",
18
18
  "!android/build",
19
19
  "!android/.gradle",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
20
23
  "!ios/build",
21
24
  "!**/__tests__",
22
25
  "!**/__fixtures__",
@@ -55,8 +58,8 @@
55
58
  "@react-native-community/eslint-config": "^2.0.0",
56
59
  "@release-it/conventional-changelog": "^2.0.0",
57
60
  "@types/jest": "^27.4.1",
58
- "@types/react": "^18.0.17",
59
- "@types/react-native": "0.69.5",
61
+ "@types/react": "^18.0.21",
62
+ "@types/react-native": "0.70.4",
60
63
  "commitlint": "^11.0.0",
61
64
  "clang-format": "^1.8.0",
62
65
  "eslint": "^7.2.0",
@@ -66,17 +69,17 @@
66
69
  "jest": "^27.5.1",
67
70
  "pod-install": "^0.1.0",
68
71
  "prettier": "^2.6.2",
69
- "react": "18.0.0",
70
- "react-native": "0.69.4",
72
+ "react": "18.1.0",
73
+ "react-native": "0.70.2",
71
74
  "react-native-builder-bob": "^0.18.0",
72
- "react-native-reanimated": "2.9.1",
75
+ "react-native-reanimated": "2.10.0",
73
76
  "release-it": "^14.2.2",
74
- "typescript": "^4.6.3"
77
+ "typescript": "^4.8.4"
75
78
  },
76
79
  "peerDependencies": {
77
80
  "react": "*",
78
81
  "react-native": "*",
79
- "react-native-reanimated": "^2.3.0"
82
+ "react-native-reanimated": ">=2.3.0"
80
83
  },
81
84
  "jest": {
82
85
  "preset": "react-native",
@@ -153,17 +156,11 @@
153
156
  ]
154
157
  },
155
158
  "codegenConfig": {
156
- "libraries": [
157
- {
158
- "name": "RNKeyboardControllerSpec",
159
- "type": "modules",
160
- "jsSrcsDir": "src"
161
- },
162
- {
163
- "name": "RNKeyboardControllerViewSpec",
164
- "type": "components",
165
- "jsSrcsDir": "src"
166
- }
167
- ]
159
+ "name": "reactnativekeyboardcontroller",
160
+ "type": "all",
161
+ "jsSrcsDir": "./src/specs",
162
+ "android": {
163
+ "javaPackageName": "com.reactnativekeyboardcontroller"
164
+ }
168
165
  }
169
166
  }
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
12
12
  s.license = package["license"]
13
13
  s.authors = package["author"]
14
14
 
15
- s.platforms = { :ios => "10.0" }
15
+ s.platforms = { :ios => "11.0" }
16
16
  s.source = { :git => "https://github.com/kirillzyusko/react-native-keyboard-controller.git", :tag => "#{s.version}" }
17
17
 
18
18
  s.source_files = "ios/**/*.{h,m,mm,swift}"
@@ -25,6 +25,7 @@ Pod::Spec.new do |s|
25
25
  s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
26
26
  s.pod_target_xcconfig = {
27
27
  "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
28
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
28
29
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
29
30
  }
30
31
 
package/src/animated.tsx CHANGED
@@ -1,17 +1,12 @@
1
- import React, { useContext, useMemo, useRef } from 'react';
1
+ import React, { useMemo, useRef } from 'react';
2
2
  import { Animated, StyleSheet, ViewStyle } from 'react-native';
3
- import Reanimated, {
4
- useEvent,
5
- useHandler,
6
- useSharedValue,
7
- } from 'react-native-reanimated';
8
- import {
9
- EventWithName,
10
- KeyboardControllerProps,
11
- KeyboardControllerView,
12
- NativeEvent,
13
- useResizeMode,
14
- } from './native';
3
+ import Reanimated, { useSharedValue } from 'react-native-reanimated';
4
+
5
+ import { KeyboardContext } from './context';
6
+ import { useAnimatedKeyboardHandler } from './internal';
7
+ import { KeyboardControllerView } from './native';
8
+
9
+ import type { KeyboardControllerProps, NativeEvent } from './types';
15
10
 
16
11
  const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
17
12
  Animated.createAnimatedComponent(
@@ -19,66 +14,6 @@ const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
19
14
  ) as React.FC<KeyboardControllerProps>
20
15
  );
21
16
 
22
- type AnimatedContext = {
23
- progress: Animated.Value;
24
- height: Animated.Value;
25
- };
26
- type ReanimatedContext = {
27
- progress: Reanimated.SharedValue<number>;
28
- height: Reanimated.SharedValue<number>;
29
- };
30
- type KeyboardAnimationContext = {
31
- animated: AnimatedContext;
32
- reanimated: ReanimatedContext;
33
- };
34
- const defaultContext: KeyboardAnimationContext = {
35
- animated: {
36
- progress: new Animated.Value(0),
37
- height: new Animated.Value(0),
38
- },
39
- reanimated: {
40
- progress: { value: 0 },
41
- height: { value: 0 },
42
- },
43
- };
44
- export const KeyboardContext = React.createContext(defaultContext);
45
-
46
- export const useKeyboardAnimation = (): AnimatedContext => {
47
- useResizeMode();
48
- const context = useContext(KeyboardContext);
49
-
50
- return context.animated;
51
- };
52
-
53
- export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
54
- useResizeMode();
55
- const context = useContext(KeyboardContext);
56
-
57
- return context.reanimated;
58
- };
59
-
60
- function useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(
61
- handlers: {
62
- onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
63
- },
64
- dependencies?: ReadonlyArray<unknown>
65
- ) {
66
- const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
67
-
68
- return useEvent(
69
- (event: EventWithName<NativeEvent>) => {
70
- 'worklet';
71
- const { onKeyboardMove } = handlers;
72
-
73
- if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
74
- onKeyboardMove(event, context);
75
- }
76
- },
77
- ['onKeyboardMove'],
78
- doDependenciesDiffer
79
- );
80
- }
81
-
82
17
  type Styles = {
83
18
  container: ViewStyle;
84
19
  hidden: ViewStyle;
@@ -112,10 +47,13 @@ export const KeyboardProvider = ({
112
47
  children,
113
48
  statusBarTranslucent,
114
49
  }: KeyboardProviderProps) => {
50
+ // animated values
115
51
  const progress = useRef(new Animated.Value(0)).current;
116
52
  const height = useRef(new Animated.Value(0)).current;
53
+ // shared values
117
54
  const progressSV = useSharedValue(0);
118
55
  const heightSV = useSharedValue(0);
56
+ // memo
119
57
  const context = useMemo(
120
58
  () => ({
121
59
  animated: { progress: progress, height: height },
@@ -130,7 +68,6 @@ export const KeyboardProvider = ({
130
68
  ],
131
69
  []
132
70
  );
133
-
134
71
  const onKeyboardMove = useMemo(
135
72
  () =>
136
73
  Animated.event(
@@ -146,7 +83,7 @@ export const KeyboardProvider = ({
146
83
  ),
147
84
  []
148
85
  );
149
-
86
+ // handlers
150
87
  const handler = useAnimatedKeyboardHandler(
151
88
  {
152
89
  onKeyboardMove: (event: NativeEvent) => {
package/src/context.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { createContext } from 'react';
2
+ import { Animated } from 'react-native';
3
+
4
+ import type { SharedValue } from 'react-native-reanimated';
5
+
6
+ export type AnimatedContext = {
7
+ progress: Animated.Value;
8
+ height: Animated.Value;
9
+ };
10
+ export type ReanimatedContext = {
11
+ progress: SharedValue<number>;
12
+ height: SharedValue<number>;
13
+ };
14
+ export type KeyboardAnimationContext = {
15
+ animated: AnimatedContext;
16
+ reanimated: ReanimatedContext;
17
+ };
18
+ const defaultContext: KeyboardAnimationContext = {
19
+ animated: {
20
+ progress: new Animated.Value(0),
21
+ height: new Animated.Value(0),
22
+ },
23
+ reanimated: {
24
+ progress: { value: 0 },
25
+ height: { value: 0 },
26
+ },
27
+ };
28
+ export const KeyboardContext = createContext(defaultContext);
package/src/hooks.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { useContext, useEffect } from 'react';
2
+
3
+ import { AnimatedContext, KeyboardContext, ReanimatedContext } from './context';
4
+ import { AndroidSoftInputModes, KeyboardController } from './native';
5
+
6
+ export const useResizeMode = () => {
7
+ useEffect(() => {
8
+ KeyboardController.setInputMode(
9
+ AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
10
+ );
11
+
12
+ return () => KeyboardController.setDefaultMode();
13
+ }, []);
14
+ };
15
+
16
+ export const useKeyboardAnimation = (): AnimatedContext => {
17
+ useResizeMode();
18
+ const context = useContext(KeyboardContext);
19
+
20
+ return context.animated;
21
+ };
22
+
23
+ export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
24
+ useResizeMode();
25
+ const context = useContext(KeyboardContext);
26
+
27
+ return context.reanimated;
28
+ };
package/src/index.ts CHANGED
@@ -3,3 +3,6 @@ import './monkey-patch';
3
3
  export * from './native';
4
4
  export * from './animated';
5
5
  export * from './replicas';
6
+ export * from './context';
7
+ export * from './hooks';
8
+ export * from './types';
@@ -0,0 +1,27 @@
1
+ import { useEvent, useHandler } from 'react-native-reanimated';
2
+
3
+ import type { EventWithName, NativeEvent } from './types';
4
+
5
+ export function useAnimatedKeyboardHandler<
6
+ TContext extends Record<string, unknown>
7
+ >(
8
+ handlers: {
9
+ onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
10
+ },
11
+ dependencies?: ReadonlyArray<unknown>
12
+ ) {
13
+ const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
14
+
15
+ return useEvent(
16
+ (event: EventWithName<NativeEvent>) => {
17
+ 'worklet';
18
+ const { onKeyboardMove } = handlers;
19
+
20
+ if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
21
+ onKeyboardMove(event, context);
22
+ }
23
+ },
24
+ ['onKeyboardMove'],
25
+ doDependenciesDiffer
26
+ );
27
+ }
@@ -1,14 +1,11 @@
1
- import { NativeModules, Platform } from 'react-native';
1
+ import { Platform } from 'react-native';
2
2
  // @ts-expect-error because there is no corresponding type definition
3
3
  import * as NativeAndroidManager from 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid';
4
4
 
5
- import { isTurboModuleEnabled } from './architecture';
6
-
7
5
  const getConstants = NativeAndroidManager.default.getConstants;
8
6
 
9
- const RCTStatusBarManagerCompat = isTurboModuleEnabled
10
- ? require('./NativeStatusBarManagerCompat').default
11
- : NativeModules.StatusBarManagerCompat;
7
+ const RCTStatusBarManagerCompat =
8
+ require('./specs/NativeStatusBarManagerCompat').default;
12
9
 
13
10
  // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
14
11
  // in order to use library on all available platforms we have to monkey patch
package/src/native.ts CHANGED
@@ -1,86 +1,57 @@
1
- import { useEffect } from 'react';
2
- import {
3
- requireNativeComponent,
4
- UIManager,
5
- Platform,
6
- NativeModules,
7
- NativeEventEmitter,
8
- NativeSyntheticEvent,
9
- ViewProps,
10
- } from 'react-native';
1
+ import { Platform, NativeEventEmitter } from 'react-native';
11
2
 
12
- import { isFabricEnabled, isTurboModuleEnabled } from './architecture';
3
+ import type {
4
+ KeyboardControllerEvents,
5
+ KeyboardControllerModule,
6
+ KeyboardEventData,
7
+ } from './types';
13
8
 
14
9
  const LINKING_ERROR =
15
10
  `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
16
11
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
17
12
  '- You rebuilt the app after installing the package\n' +
18
- '- You are not using Expo managed workflow\n';
13
+ '- You are not using Expo Go\n';
19
14
 
15
+ // copied from `android.view.WindowManager.LayoutParams`
20
16
  export enum AndroidSoftInputModes {
21
17
  SOFT_INPUT_ADJUST_NOTHING = 48,
22
18
  SOFT_INPUT_ADJUST_PAN = 32,
23
19
  SOFT_INPUT_ADJUST_RESIZE = 16,
24
20
  SOFT_INPUT_ADJUST_UNSPECIFIED = 0,
21
+ SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,
22
+ SOFT_INPUT_MASK_ADJUST = 240,
23
+ SOFT_INPUT_MASK_STATE = 15,
24
+ SOFT_INPUT_MODE_CHANGED = 512,
25
+ SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,
26
+ SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,
27
+ SOFT_INPUT_STATE_HIDDEN = 2,
28
+ SOFT_INPUT_STATE_UNCHANGED = 1,
29
+ SOFT_INPUT_STATE_UNSPECIFIED = 0,
30
+ SOFT_INPUT_STATE_VISIBLE = 4,
25
31
  }
26
32
 
27
- export type NativeEvent = {
28
- progress: number;
29
- height: number;
30
- };
31
- export type EventWithName<T> = {
32
- eventName: string;
33
- } & T;
34
- export type KeyboardControllerProps = {
35
- onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
36
- // fake prop used to activate reanimated bindings
37
- onKeyboardMoveReanimated: (
38
- e: NativeSyntheticEvent<EventWithName<NativeEvent>>
39
- ) => void;
40
- statusBarTranslucent?: boolean;
41
- } & ViewProps;
42
- type KeyboardController = {
43
- // android only
44
- setDefaultMode: () => void;
45
- setInputMode: (mode: AndroidSoftInputModes) => void;
46
- };
47
-
48
- const ComponentName = 'KeyboardControllerView';
49
-
50
- const RCTKeyboardController = isTurboModuleEnabled
51
- ? require('./NativeKeyboardController').default
52
- : NativeModules.KeyboardController;
53
- export const KeyboardController = RCTKeyboardController as KeyboardController;
33
+ const RCTKeyboardController =
34
+ require('./specs/NativeKeyboardController').default;
35
+ export const KeyboardController = (
36
+ RCTKeyboardController
37
+ ? RCTKeyboardController
38
+ : new Proxy(
39
+ {},
40
+ {
41
+ get() {
42
+ throw new Error(LINKING_ERROR);
43
+ },
44
+ }
45
+ )
46
+ ) as KeyboardControllerModule;
47
+
48
+ const eventEmitter = new NativeEventEmitter(KeyboardController);
54
49
 
55
- const eventEmitter = new NativeEventEmitter(RCTKeyboardController);
56
- type KeyboardControllerEvents =
57
- | 'keyboardWillShow'
58
- | 'keyboardDidShow'
59
- | 'keyboardWillHide'
60
- | 'keyboardDidHide';
61
- type KeyboardEvent = {
62
- height: number;
63
- };
64
50
  export const KeyboardEvents = {
65
51
  addListener: (
66
52
  name: KeyboardControllerEvents,
67
- cb: (e: KeyboardEvent) => void
53
+ cb: (e: KeyboardEventData) => void
68
54
  ) => eventEmitter.addListener('KeyboardController::' + name, cb),
69
55
  };
70
- export const KeyboardControllerView = isFabricEnabled
71
- ? require('./KeyboardControllerViewNativeComponent').default
72
- : UIManager.getViewManagerConfig(ComponentName) != null
73
- ? requireNativeComponent<KeyboardControllerProps>(ComponentName)
74
- : () => {
75
- throw new Error(LINKING_ERROR);
76
- };
77
-
78
- export const useResizeMode = () => {
79
- useEffect(() => {
80
- KeyboardController.setInputMode(
81
- AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE
82
- );
83
-
84
- return () => KeyboardController.setDefaultMode();
85
- }, []);
86
- };
56
+ export const KeyboardControllerView =
57
+ require('./specs/KeyboardControllerViewNativeComponent').default;
package/src/replicas.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  useWorkletCallback,
9
9
  withSpring,
10
10
  } from 'react-native-reanimated';
11
- import { useReanimatedKeyboardAnimation } from './animated';
11
+ import { useReanimatedKeyboardAnimation } from './hooks';
12
12
 
13
13
  import { AndroidSoftInputModes, KeyboardController } from './native';
14
14
 
package/src/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
2
+
3
+ // DirectEventHandler events declaration
4
+
5
+ export type NativeEvent = {
6
+ progress: number;
7
+ height: number;
8
+ };
9
+ export type EventWithName<T> = {
10
+ eventName: string;
11
+ } & T;
12
+
13
+ // native View/Module declarations
14
+
15
+ export type KeyboardControllerProps = {
16
+ onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
17
+ // fake prop used to activate reanimated bindings
18
+ onKeyboardMoveReanimated: (
19
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>
20
+ ) => void;
21
+ statusBarTranslucent?: boolean;
22
+ } & ViewProps;
23
+
24
+ export type KeyboardControllerModule = {
25
+ // android only
26
+ setDefaultMode: () => void;
27
+ setInputMode: (mode: number) => void;
28
+ // native event module stuff
29
+ addListener: (eventName: string) => void;
30
+ removeListeners: (count: number) => void;
31
+ };
32
+
33
+ // Event module declarations
34
+
35
+ export type KeyboardControllerEvents =
36
+ | 'keyboardWillShow'
37
+ | 'keyboardDidShow'
38
+ | 'keyboardWillHide'
39
+ | 'keyboardDidHide';
40
+ export type KeyboardEventData = {
41
+ height: number;
42
+ };
@@ -1,5 +0,0 @@
1
- distributionBase=GRADLE_USER_HOME
2
- distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4
- zipStoreBase=GRADLE_USER_HOME
5
- zipStorePath=wrapper/dists