react-native-keyboard-controller 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +72 -3
- package/android/gradle.properties +1 -1
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +31 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +25 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +32 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +25 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +188 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModule.kt → KeyboardControllerModuleImpl.kt} +5 -17
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +5 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManagerImpl.kt +71 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatModule.kt → StatusBarManagerCompatImpl.kt} +10 -14
- package/android/src/main/jni/Android.mk +42 -0
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +71 -0
- package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +35 -0
- package/android/src/main/jni/OnLoad.cpp +9 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +31 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +26 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +34 -0
- package/ios/.clang-format +90 -0
- package/ios/KeyboardController.xcodeproj/project.pbxproj +22 -14
- package/ios/KeyboardControllerModule-Header.h +6 -2
- package/ios/KeyboardControllerModule.mm +105 -0
- package/ios/KeyboardControllerView.h +23 -0
- package/ios/KeyboardControllerView.mm +81 -0
- package/ios/{KeyboardControllerViewManager.m → KeyboardControllerViewManager.mm} +1 -1
- package/ios/KeyboardControllerViewManager.swift +13 -64
- package/ios/KeyboardMoveEvent.h +18 -0
- package/ios/KeyboardMoveEvent.m +74 -0
- package/ios/KeyboardMovementObserver.swift +90 -0
- package/lib/commonjs/KeyboardControllerViewNativeComponent.js +16 -0
- package/lib/commonjs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/NativeKeyboardController.js +13 -0
- package/lib/commonjs/NativeKeyboardController.js.map +1 -0
- package/lib/commonjs/NativeStatusBarManagerCompat.js +13 -0
- package/lib/commonjs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/architecture.js +13 -0
- package/lib/commonjs/architecture.js.map +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/monkey-patch.js +3 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/native.js +4 -2
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/module/KeyboardControllerViewNativeComponent.js +4 -0
- package/lib/module/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/module/NativeKeyboardController.js +3 -0
- package/lib/module/NativeKeyboardController.js.map +1 -0
- package/lib/module/NativeStatusBarManagerCompat.js +3 -0
- package/lib/module/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/module/animated.js.map +1 -1
- package/lib/module/architecture.js +5 -0
- package/lib/module/architecture.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/monkey-patch.js +2 -1
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/native.js +3 -2
- package/lib/module/native.js.map +1 -1
- package/lib/module/replicas.js.map +1 -1
- package/lib/typescript/KeyboardControllerViewNativeComponent.d.ts +13 -0
- package/lib/typescript/NativeKeyboardController.d.ts +10 -0
- package/lib/typescript/NativeStatusBarManagerCompat.d.ts +10 -0
- package/lib/typescript/architecture.d.ts +2 -0
- package/lib/typescript/native.d.ts +1 -1
- package/lib/typescript/replicas.d.ts +3 -5
- package/package.json +23 -6
- package/react-native-keyboard-controller.podspec +19 -0
- package/src/KeyboardControllerViewNativeComponent.ts +23 -0
- package/src/NativeKeyboardController.ts +16 -0
- package/src/NativeStatusBarManagerCompat.ts +13 -0
- package/src/architecture.ts +4 -0
- package/src/monkey-patch.tsx +5 -1
- package/src/native.ts +12 -7
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +0 -77
- package/android/src/main/java/com/reactnativekeyboardcontroller/TranslateDeferringInsetsAnimationCallback.kt +0 -158
- package/ios/KeyboardControllerModule.m +0 -21
- package/ios/KeyboardControllerModule.swift +0 -53
- package/ios/KeyboardMoveEvent.swift +0 -41
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @ts-expect-error because `__turboModuleProxy` has any type (maybe think about own types declaration)
|
|
2
|
+
export const isTurboModuleEnabled = global.__turboModuleProxy != null; // @ts-expect-error because `nativeFabricUIManager` has any type (maybe think about own types declaration)
|
|
3
|
+
|
|
4
|
+
export const isFabricEnabled = global.nativeFabricUIManager != null;
|
|
5
|
+
//# sourceMappingURL=architecture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isTurboModuleEnabled","global","__turboModuleProxy","isFabricEnabled","nativeFabricUIManager"],"sources":["architecture.ts"],"sourcesContent":["// @ts-expect-error because `__turboModuleProxy` has any type (maybe think about own types declaration)\nexport const isTurboModuleEnabled = global.__turboModuleProxy != null;\n// @ts-expect-error because `nativeFabricUIManager` has any type (maybe think about own types declaration)\nexport const isFabricEnabled = global.nativeFabricUIManager != null;\n"],"mappings":"AAAA;AACA,OAAO,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,kBAAP,IAA6B,IAA1D,C,CACP;;AACA,OAAO,MAAMC,eAAe,GAAGF,MAAM,CAACG,qBAAP,IAAgC,IAAxD"}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './native';\nexport * from './animated';\nexport * from './replicas';\n"],"mappings":"AAAA,OAAO,gBAAP;AAEA,cAAc,UAAd;AACA,cAAc,YAAd;AACA,cAAc,YAAd"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { NativeModules, Platform } from 'react-native'; // @ts-expect-error because there is no corresponding type definition
|
|
2
2
|
|
|
3
3
|
import * as NativeAndroidManager from 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid';
|
|
4
|
+
import { isTurboModuleEnabled } from './architecture';
|
|
4
5
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
5
|
-
const RCTStatusBarManagerCompat = NativeModules.StatusBarManagerCompat; // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
6
|
+
const RCTStatusBarManagerCompat = isTurboModuleEnabled ? require('./NativeStatusBarManagerCompat').default : NativeModules.StatusBarManagerCompat; // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
6
7
|
// in order to use library on all available platforms we have to monkey patch
|
|
7
8
|
// default RN implementation and use modern `WindowInsetsControllerCompat`.
|
|
8
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","NativeAndroidManager","isTurboModuleEnabled","getConstants","default","RCTStatusBarManagerCompat","require","StatusBarManagerCompat","OS","setColor","color","animated","setTranslucent","translucent","setStyle","statusBarStyle","setHidden","hidden"],"sources":["monkey-patch.tsx"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n// @ts-expect-error because there is no corresponding type definition\nimport * as NativeAndroidManager from 'react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid';\n\nimport { isTurboModuleEnabled } from './architecture';\n\nconst getConstants = NativeAndroidManager.default.getConstants;\n\nconst RCTStatusBarManagerCompat = isTurboModuleEnabled\n ? require('./NativeStatusBarManagerCompat').default\n : NativeModules.StatusBarManagerCompat;\n\n// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so\n// in order to use library on all available platforms we have to monkey patch\n// default RN implementation and use modern `WindowInsetsControllerCompat`.\nif (Platform.OS === 'android') {\n NativeAndroidManager.default = {\n getConstants,\n setColor(color: number, animated: boolean): void {\n RCTStatusBarManagerCompat.setColor(color, animated);\n },\n\n setTranslucent(translucent: boolean): void {\n RCTStatusBarManagerCompat.setTranslucent(translucent);\n },\n\n /**\n * - statusBarStyles can be:\n * - 'default'\n * - 'dark-content'\n */\n setStyle(statusBarStyle?: string): void {\n RCTStatusBarManagerCompat.setStyle(statusBarStyle);\n },\n\n setHidden(hidden: boolean): void {\n RCTStatusBarManagerCompat.setHidden(hidden);\n },\n };\n}\n"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,QAAxB,QAAwC,cAAxC,C,CACA;;AACA,OAAO,KAAKC,oBAAZ,MAAsC,2EAAtC;AAEA,SAASC,oBAAT,QAAqC,gBAArC;AAEA,MAAMC,YAAY,GAAGF,oBAAoB,CAACG,OAArB,CAA6BD,YAAlD;AAEA,MAAME,yBAAyB,GAAGH,oBAAoB,GAClDI,OAAO,CAAC,gCAAD,CAAP,CAA0CF,OADQ,GAElDL,aAAa,CAACQ,sBAFlB,C,CAIA;AACA;AACA;;AACA,IAAIP,QAAQ,CAACQ,EAAT,KAAgB,SAApB,EAA+B;EAC7BP,oBAAoB,CAACG,OAArB,GAA+B;IAC7BD,YAD6B;;IAE7BM,QAAQ,CAACC,KAAD,EAAgBC,QAAhB,EAAyC;MAC/CN,yBAAyB,CAACI,QAA1B,CAAmCC,KAAnC,EAA0CC,QAA1C;IACD,CAJ4B;;IAM7BC,cAAc,CAACC,WAAD,EAA6B;MACzCR,yBAAyB,CAACO,cAA1B,CAAyCC,WAAzC;IACD,CAR4B;;IAU7B;AACJ;AACA;AACA;AACA;IACIC,QAAQ,CAACC,cAAD,EAAgC;MACtCV,yBAAyB,CAACS,QAA1B,CAAmCC,cAAnC;IACD,CAjB4B;;IAmB7BC,SAAS,CAACC,MAAD,EAAwB;MAC/BZ,yBAAyB,CAACW,SAA1B,CAAoCC,MAApC;IACD;;EArB4B,CAA/B;AAuBD"}
|
package/lib/module/native.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { requireNativeComponent, UIManager, Platform, NativeModules, NativeEventEmitter } from 'react-native';
|
|
3
|
+
import { isFabricEnabled, isTurboModuleEnabled } from './architecture';
|
|
3
4
|
const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
4
5
|
ios: "- You have run 'pod install'\n",
|
|
5
6
|
default: ''
|
|
@@ -14,13 +15,13 @@ export let AndroidSoftInputModes;
|
|
|
14
15
|
})(AndroidSoftInputModes || (AndroidSoftInputModes = {}));
|
|
15
16
|
|
|
16
17
|
const ComponentName = 'KeyboardControllerView';
|
|
17
|
-
const RCTKeyboardController = NativeModules.KeyboardController;
|
|
18
|
+
const RCTKeyboardController = isTurboModuleEnabled ? require('./NativeKeyboardController').default : NativeModules.KeyboardController;
|
|
18
19
|
export const KeyboardController = RCTKeyboardController;
|
|
19
20
|
const eventEmitter = new NativeEventEmitter(RCTKeyboardController);
|
|
20
21
|
export const KeyboardEvents = {
|
|
21
22
|
addListener: (name, cb) => eventEmitter.addListener('KeyboardController::' + name, cb)
|
|
22
23
|
};
|
|
23
|
-
export const KeyboardControllerView = UIManager.getViewManagerConfig(ComponentName) != null ? requireNativeComponent(ComponentName) : () => {
|
|
24
|
+
export const KeyboardControllerView = isFabricEnabled ? require('./KeyboardControllerViewNativeComponent').default : UIManager.getViewManagerConfig(ComponentName) != null ? requireNativeComponent(ComponentName) : () => {
|
|
24
25
|
throw new Error(LINKING_ERROR);
|
|
25
26
|
};
|
|
26
27
|
export const useResizeMode = () => {
|
package/lib/module/native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useEffect","requireNativeComponent","UIManager","Platform","NativeModules","NativeEventEmitter","isFabricEnabled","isTurboModuleEnabled","LINKING_ERROR","select","ios","default","AndroidSoftInputModes","ComponentName","RCTKeyboardController","require","KeyboardController","eventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","getViewManagerConfig","Error","useResizeMode","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode"],"sources":["native.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {\n requireNativeComponent,\n UIManager,\n Platform,\n NativeModules,\n NativeEventEmitter,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\nimport { isFabricEnabled, isTurboModuleEnabled } from './architecture';\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nexport enum AndroidSoftInputModes {\n SOFT_INPUT_ADJUST_NOTHING = 48,\n SOFT_INPUT_ADJUST_PAN = 32,\n SOFT_INPUT_ADJUST_RESIZE = 16,\n SOFT_INPUT_ADJUST_UNSPECIFIED = 0,\n}\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\nexport type KeyboardControllerProps = {\n onKeyboardMove: (e: NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n} & ViewProps;\ntype KeyboardController = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: AndroidSoftInputModes) => void;\n};\n\nconst ComponentName = 'KeyboardControllerView';\n\nconst RCTKeyboardController = isTurboModuleEnabled\n ? require('./NativeKeyboardController').default\n : NativeModules.KeyboardController;\nexport const KeyboardController = RCTKeyboardController as KeyboardController;\n\nconst eventEmitter = new NativeEventEmitter(RCTKeyboardController);\ntype KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\ntype KeyboardEvent = {\n height: number;\n};\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEvent) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView = isFabricEnabled\n ? require('./KeyboardControllerViewNativeComponent').default\n : UIManager.getViewManagerConfig(ComponentName) != null\n ? requireNativeComponent<KeyboardControllerProps>(ComponentName)\n : () => {\n throw new Error(LINKING_ERROR);\n };\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AACA,SACEC,sBADF,EAEEC,SAFF,EAGEC,QAHF,EAIEC,aAJF,EAKEC,kBALF,QAQO,cARP;AAUA,SAASC,eAAT,EAA0BC,oBAA1B,QAAsD,gBAAtD;AAEA,MAAMC,aAAa,GAChB,2FAAD,GACAL,QAAQ,CAACM,MAAT,CAAgB;EAAEC,GAAG,EAAE,gCAAP;EAAyCC,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAMA,WAAYC,qBAAZ;;WAAYA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,KAAAA,qB;;AA4BZ,MAAMC,aAAa,GAAG,wBAAtB;AAEA,MAAMC,qBAAqB,GAAGP,oBAAoB,GAC9CQ,OAAO,CAAC,4BAAD,CAAP,CAAsCJ,OADQ,GAE9CP,aAAa,CAACY,kBAFlB;AAGA,OAAO,MAAMA,kBAAkB,GAAGF,qBAA3B;AAEP,MAAMG,YAAY,GAAG,IAAIZ,kBAAJ,CAAuBS,qBAAvB,CAArB;AASA,OAAO,MAAMI,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IADW,EAEXC,EAFW,KAGRJ,YAAY,CAACE,WAAb,CAAyB,yBAAyBC,IAAlD,EAAwDC,EAAxD;AAJuB,CAAvB;AAMP,OAAO,MAAMC,sBAAsB,GAAGhB,eAAe,GACjDS,OAAO,CAAC,yCAAD,CAAP,CAAmDJ,OADF,GAEjDT,SAAS,CAACqB,oBAAV,CAA+BV,aAA/B,KAAiD,IAAjD,GACAZ,sBAAsB,CAA0BY,aAA1B,CADtB,GAEA,MAAM;EACJ,MAAM,IAAIW,KAAJ,CAAUhB,aAAV,CAAN;AACD,CANE;AAQP,OAAO,MAAMiB,aAAa,GAAG,MAAM;EACjCzB,SAAS,CAAC,MAAM;IACdgB,kBAAkB,CAACU,YAAnB,CACEd,qBAAqB,CAACe,wBADxB;IAIA,OAAO,MAAMX,kBAAkB,CAACY,cAAnB,EAAb;EACD,CANQ,EAMN,EANM,CAAT;AAOD,CARM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRef","useEffect","useMemo","Animated","Easing","Keyboard","Platform","runOnUI","useAnimatedReaction","useDerivedValue","useSharedValue","useWorkletCallback","withSpring","useReanimatedKeyboardAnimation","AndroidSoftInputModes","KeyboardController","availableOSEventType","OS","defaultAndroidEasing","bezier","useKeyboardAnimationReplica","height","Value","progress","animation","current","setInputMode","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","listener","addListener","e","timing","toValue","endCoordinates","duration","easing","useNativeDriver","start","remove","IOS_SPRING_CONFIG","damping","stiffness","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","useReanimatedKeyboardAnimationReplica","heightEvent","value","handler","_height","_keyboardHeight","result","_previousResult","_previousKeyboardHeight","show","hide","useGradualKeyboardAnimation"],"sources":["replicas.ts"],"sourcesContent":["import { useRef, useEffect, useMemo } from 'react';\nimport { Animated, Easing, Keyboard, Platform } from 'react-native';\nimport {\n runOnUI,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n useWorkletCallback,\n withSpring,\n} from 'react-native-reanimated';\nimport { useReanimatedKeyboardAnimation } from './animated';\n\nimport { AndroidSoftInputModes, KeyboardController } from './native';\n\nconst availableOSEventType = Platform.OS === 'ios' ? 'Will' : 'Did';\n\n// cubic-bezier(.17,.67,.34,.94)\nexport const defaultAndroidEasing = Easing.bezier(0.4, 0.0, 0.2, 1);\ntype KeyboardAnimation = {\n progress: Animated.Value;\n height: Animated.Value;\n};\n\n/**\n * An experimental implementation of tracing keyboard appearance.\n * Switch an input mode to adjust resize mode. In this case all did* events\n * are triggering before keyboard appears, and using some approximations\n * it tries to mimicries a native transition.\n *\n * @returns {Animated.Value}\n */\nexport const useKeyboardAnimationReplica = (): KeyboardAnimation => {\n const height = useRef(new Animated.Value(0));\n const progress = useRef(new Animated.Value(0));\n const animation = useMemo(\n () => ({\n height: height.current,\n progress: progress.current,\n }),\n []\n );\n\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Show`,\n (e) => {\n Animated.timing(height.current, {\n toValue: -e.endCoordinates.height,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n useEffect(() => {\n const listener = Keyboard.addListener(\n `keyboard${availableOSEventType}Hide`,\n (e) => {\n Animated.timing(height.current, {\n toValue: 0,\n duration: e.duration !== 0 ? e.duration : 300,\n easing: Easing.bezier(0.4, 0.0, 0.2, 1),\n useNativeDriver: true,\n }).start();\n\n return () => listener.remove();\n }\n );\n }, []);\n\n return animation;\n};\n\nconst IOS_SPRING_CONFIG = {\n damping: 500,\n stiffness: 1000,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 10,\n restSpeedThreshold: 10,\n};\n\n/**\n * A close replica to native iOS keyboard animation. The problem is that\n * iOS (unlike Android) can not fire events for each keyboard frame movement.\n * As a result we can not get gradual values (for example, for progress it always\n * will be 1 or 0). So if you want to rely on gradual values you will need to use\n * this replica.\n *\n * The transition is hardcoded and may vary from one to another OS versions. But it\n * seems like last time it has been changed in iOS 7. Since RN supports at least iOS\n * 11 it doesn't make sense to replicate iOS 7 behavior. If it changes in next OS\n * versions, then this implementation should be revisited and reflect necessary changes.\n *\n * @returns {height, progress} - animated values\n */\nexport const useReanimatedKeyboardAnimationReplica = () => {\n const height = useSharedValue(0);\n const heightEvent = useSharedValue(0);\n\n const progress = useDerivedValue(() => height.value / heightEvent.value);\n\n const handler = useWorkletCallback((_height: number) => {\n heightEvent.value = _height;\n }, []);\n\n useAnimatedReaction(\n () => ({\n _keyboardHeight: heightEvent.value,\n }),\n (result, _previousResult) => {\n const { _keyboardHeight } = result;\n const _previousKeyboardHeight = _previousResult?._keyboardHeight;\n\n if (_keyboardHeight !== _previousKeyboardHeight) {\n height.value = withSpring(_keyboardHeight, IOS_SPRING_CONFIG);\n }\n },\n []\n );\n\n useEffect(() => {\n const show = Keyboard.addListener('keyboardWillShow', (e) => {\n runOnUI(handler)(-e.endCoordinates.height);\n });\n const hide = Keyboard.addListener('keyboardWillHide', () => {\n runOnUI(handler)(0);\n });\n\n return () => {\n show.remove();\n hide.remove();\n };\n }, []);\n\n return { height, progress };\n};\n\nexport const useGradualKeyboardAnimation =\n Platform.OS === 'ios'\n ? useReanimatedKeyboardAnimationReplica\n : useReanimatedKeyboardAnimation;\n"],"mappings":"AAAA,SAASA,MAAT,EAAiBC,SAAjB,EAA4BC,OAA5B,QAA2C,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L;IACD,CAHD;EAID,CAZQ,EAYN,EAZM,CAAT;EAcA,OAAO;IAAElB,MAAF;IAAUE;EAAV,CAAP;AACD,CAxCM;AA0CP,OAAO,MAAMmC,2BAA2B,GACtCpD,QAAQ,CAACW,EAAT,KAAgB,KAAhB,GACI8B,qCADJ,GAEIlC,8BAHC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HostComponent } from 'react-native';
|
|
2
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
3
|
+
import type { DirectEventHandler, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
declare type KeyboardMoveEvent = Readonly<{
|
|
5
|
+
height: Int32;
|
|
6
|
+
progress: Float;
|
|
7
|
+
}>;
|
|
8
|
+
export interface NativeProps extends ViewProps {
|
|
9
|
+
statusBarTranslucent?: boolean;
|
|
10
|
+
onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: HostComponent<NativeProps>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
readonly getConstants: () => {};
|
|
4
|
+
setInputMode(mode: number): void;
|
|
5
|
+
setDefaultMode(): void;
|
|
6
|
+
addListener: (eventName: string) => void;
|
|
7
|
+
removeListeners: (count: number) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: Spec | null;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
readonly getConstants: () => {};
|
|
4
|
+
setHidden(hidden: boolean): void;
|
|
5
|
+
setColor(color: number, animated: boolean): void;
|
|
6
|
+
setTranslucent(translucent: boolean): void;
|
|
7
|
+
setStyle(style: string): void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: Spec | null;
|
|
10
|
+
export default _default;
|
|
@@ -29,6 +29,6 @@ declare type KeyboardEvent = {
|
|
|
29
29
|
export declare const KeyboardEvents: {
|
|
30
30
|
addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEvent) => void) => import("react-native").EmitterSubscription;
|
|
31
31
|
};
|
|
32
|
-
export declare const KeyboardControllerView:
|
|
32
|
+
export declare const KeyboardControllerView: any;
|
|
33
33
|
export declare const useResizeMode: () => void;
|
|
34
34
|
export {};
|
|
@@ -35,11 +35,9 @@ export declare const useReanimatedKeyboardAnimationReplica: () => {
|
|
|
35
35
|
}>;
|
|
36
36
|
};
|
|
37
37
|
export declare const useGradualKeyboardAnimation: () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
height: {
|
|
38
|
+
height: import("react-native-reanimated").SharedValue<number>;
|
|
39
|
+
progress: Readonly<{
|
|
42
40
|
value: number;
|
|
43
|
-
}
|
|
41
|
+
}>;
|
|
44
42
|
};
|
|
45
43
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"react-native-keyboard-controller.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
|
+
"!android/.gradle",
|
|
19
20
|
"!ios/build",
|
|
20
21
|
"!**/__tests__",
|
|
21
22
|
"!**/__fixtures__",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"test": "jest",
|
|
26
27
|
"typescript": "tsc --noEmit --project tsconfig.build.json",
|
|
27
28
|
"lint": "eslint --quiet \"**/*.{js,ts,tsx}\"",
|
|
29
|
+
"lint-clang": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i -n --Werror",
|
|
28
30
|
"prepare": "bob build",
|
|
29
31
|
"release": "release-it",
|
|
30
32
|
"example": "yarn --cwd example",
|
|
@@ -53,9 +55,10 @@
|
|
|
53
55
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
54
56
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
55
57
|
"@types/jest": "^27.4.1",
|
|
56
|
-
"@types/react": "^
|
|
57
|
-
"@types/react-native": "0.
|
|
58
|
+
"@types/react": "^18.0.17",
|
|
59
|
+
"@types/react-native": "0.69.5",
|
|
58
60
|
"commitlint": "^11.0.0",
|
|
61
|
+
"clang-format": "^1.8.0",
|
|
59
62
|
"eslint": "^7.2.0",
|
|
60
63
|
"eslint-config-prettier": "^7.0.0",
|
|
61
64
|
"eslint-plugin-prettier": "^3.1.3",
|
|
@@ -63,10 +66,10 @@
|
|
|
63
66
|
"jest": "^27.5.1",
|
|
64
67
|
"pod-install": "^0.1.0",
|
|
65
68
|
"prettier": "^2.6.2",
|
|
66
|
-
"react": "
|
|
67
|
-
"react-native": "0.
|
|
69
|
+
"react": "18.0.0",
|
|
70
|
+
"react-native": "0.69.4",
|
|
68
71
|
"react-native-builder-bob": "^0.18.0",
|
|
69
|
-
"react-native-reanimated": "2.
|
|
72
|
+
"react-native-reanimated": "2.9.1",
|
|
70
73
|
"release-it": "^14.2.2",
|
|
71
74
|
"typescript": "^4.6.3"
|
|
72
75
|
},
|
|
@@ -148,5 +151,19 @@
|
|
|
148
151
|
}
|
|
149
152
|
]
|
|
150
153
|
]
|
|
154
|
+
},
|
|
155
|
+
"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
|
+
]
|
|
151
168
|
}
|
|
152
169
|
}
|
|
@@ -2,6 +2,8 @@ require "json"
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
6
|
+
|
|
5
7
|
Pod::Spec.new do |s|
|
|
6
8
|
s.name = "react-native-keyboard-controller"
|
|
7
9
|
s.version = package["version"]
|
|
@@ -14,6 +16,23 @@ Pod::Spec.new do |s|
|
|
|
14
16
|
s.source = { :git => "https://github.com/kirillzyusko/react-native-keyboard-controller.git", :tag => "#{s.version}" }
|
|
15
17
|
|
|
16
18
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
19
|
+
s.public_header_files = "ios/**/*.h"
|
|
17
20
|
|
|
18
21
|
s.dependency "React-Core"
|
|
22
|
+
|
|
23
|
+
# This guard prevent to install the dependencies when we run `pod install` in the old architecture.
|
|
24
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
25
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
26
|
+
s.pod_target_xcconfig = {
|
|
27
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
28
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
s.dependency "React-RCTFabric"
|
|
32
|
+
s.dependency "React-Codegen"
|
|
33
|
+
s.dependency "RCT-Folly"
|
|
34
|
+
s.dependency "RCTRequired"
|
|
35
|
+
s.dependency "RCTTypeSafety"
|
|
36
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
37
|
+
end
|
|
19
38
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HostComponent } from 'react-native';
|
|
2
|
+
// @ts-expect-error - no type definition
|
|
3
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
4
|
+
import type {
|
|
5
|
+
DirectEventHandler,
|
|
6
|
+
Float,
|
|
7
|
+
Int32,
|
|
8
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
9
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
10
|
+
|
|
11
|
+
type KeyboardMoveEvent = Readonly<{
|
|
12
|
+
height: Int32;
|
|
13
|
+
progress: Float;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export interface NativeProps extends ViewProps {
|
|
17
|
+
statusBarTranslucent?: boolean;
|
|
18
|
+
onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default codegenNativeComponent<NativeProps>(
|
|
22
|
+
'KeyboardControllerView'
|
|
23
|
+
) as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
readonly getConstants: () => {};
|
|
6
|
+
|
|
7
|
+
// methods
|
|
8
|
+
setInputMode(mode: number): void;
|
|
9
|
+
setDefaultMode(): void;
|
|
10
|
+
|
|
11
|
+
// event emitter
|
|
12
|
+
addListener: (eventName: string) => void;
|
|
13
|
+
removeListeners: (count: number) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default TurboModuleRegistry.get<Spec>('KeyboardController');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
readonly getConstants: () => {};
|
|
6
|
+
|
|
7
|
+
setHidden(hidden: boolean): void;
|
|
8
|
+
setColor(color: number, animated: boolean): void;
|
|
9
|
+
setTranslucent(translucent: boolean): void;
|
|
10
|
+
setStyle(style: string): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default TurboModuleRegistry.get<Spec>('StatusBarManagerCompat');
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @ts-expect-error because `__turboModuleProxy` has any type (maybe think about own types declaration)
|
|
2
|
+
export const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
3
|
+
// @ts-expect-error because `nativeFabricUIManager` has any type (maybe think about own types declaration)
|
|
4
|
+
export const isFabricEnabled = global.nativeFabricUIManager != null;
|
package/src/monkey-patch.tsx
CHANGED
|
@@ -2,9 +2,13 @@ import { NativeModules, 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
|
+
|
|
5
7
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
6
8
|
|
|
7
|
-
const RCTStatusBarManagerCompat =
|
|
9
|
+
const RCTStatusBarManagerCompat = isTurboModuleEnabled
|
|
10
|
+
? require('./NativeStatusBarManagerCompat').default
|
|
11
|
+
: NativeModules.StatusBarManagerCompat;
|
|
8
12
|
|
|
9
13
|
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
10
14
|
// in order to use library on all available platforms we have to monkey patch
|
package/src/native.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
ViewProps,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
|
|
12
|
+
import { isFabricEnabled, isTurboModuleEnabled } from './architecture';
|
|
13
|
+
|
|
12
14
|
const LINKING_ERROR =
|
|
13
15
|
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
14
16
|
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
@@ -45,7 +47,9 @@ type KeyboardController = {
|
|
|
45
47
|
|
|
46
48
|
const ComponentName = 'KeyboardControllerView';
|
|
47
49
|
|
|
48
|
-
const RCTKeyboardController =
|
|
50
|
+
const RCTKeyboardController = isTurboModuleEnabled
|
|
51
|
+
? require('./NativeKeyboardController').default
|
|
52
|
+
: NativeModules.KeyboardController;
|
|
49
53
|
export const KeyboardController = RCTKeyboardController as KeyboardController;
|
|
50
54
|
|
|
51
55
|
const eventEmitter = new NativeEventEmitter(RCTKeyboardController);
|
|
@@ -63,12 +67,13 @@ export const KeyboardEvents = {
|
|
|
63
67
|
cb: (e: KeyboardEvent) => void
|
|
64
68
|
) => eventEmitter.addListener('KeyboardController::' + name, cb),
|
|
65
69
|
};
|
|
66
|
-
export const KeyboardControllerView =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
};
|
|
72
77
|
|
|
73
78
|
export const useResizeMode = () => {
|
|
74
79
|
useEffect(() => {
|
package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
package com.reactnativekeyboardcontroller
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import androidx.appcompat.widget.FitWindowsLinearLayout
|
|
5
|
-
import androidx.core.view.ViewCompat
|
|
6
|
-
import androidx.core.view.WindowInsetsAnimationCompat
|
|
7
|
-
import androidx.core.view.WindowInsetsCompat
|
|
8
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
|
-
import com.facebook.react.common.MapBuilder
|
|
10
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
-
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
13
|
-
import com.facebook.react.views.view.ReactViewManager
|
|
14
|
-
import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
|
|
15
|
-
|
|
16
|
-
class KeyboardControllerViewManager(reactContext: ReactApplicationContext) : ReactViewManager() {
|
|
17
|
-
private val TAG = KeyboardControllerViewManager::class.qualifiedName
|
|
18
|
-
private var mReactContext = reactContext
|
|
19
|
-
private var isStatusBarTranslucent = false
|
|
20
|
-
|
|
21
|
-
override fun getName() = "KeyboardControllerView"
|
|
22
|
-
|
|
23
|
-
override fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
|
|
24
|
-
val view = EdgeToEdgeReactViewGroup(reactContext)
|
|
25
|
-
val activity = mReactContext.currentActivity
|
|
26
|
-
|
|
27
|
-
if (activity == null) {
|
|
28
|
-
Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
|
|
29
|
-
return view
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
val window = activity.window
|
|
33
|
-
val decorView = window.decorView
|
|
34
|
-
|
|
35
|
-
ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
|
|
36
|
-
val content =
|
|
37
|
-
mReactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
|
|
38
|
-
R.id.action_bar_root
|
|
39
|
-
)
|
|
40
|
-
content?.setPadding(
|
|
41
|
-
0, if (this.isStatusBarTranslucent) 0 else insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0, 0,
|
|
42
|
-
insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
insets
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
ViewCompat.setWindowInsetsAnimationCallback(
|
|
49
|
-
decorView,
|
|
50
|
-
TranslateDeferringInsetsAnimationCallback(
|
|
51
|
-
view = view,
|
|
52
|
-
persistentInsetTypes = WindowInsetsCompat.Type.systemBars(),
|
|
53
|
-
deferredInsetTypes = WindowInsetsCompat.Type.ime(),
|
|
54
|
-
// We explicitly allow dispatch to continue down to binding.messageHolder's
|
|
55
|
-
// child views, so that step 2.5 below receives the call
|
|
56
|
-
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
|
|
57
|
-
context = mReactContext
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
return view
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@ReactProp(name = "statusBarTranslucent")
|
|
65
|
-
fun setStatusBarTranslucent(view: ReactViewGroup, isStatusBarTranslucent: Boolean) {
|
|
66
|
-
this.isStatusBarTranslucent = isStatusBarTranslucent
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
|
|
70
|
-
val map: MutableMap<String, Any> = MapBuilder.of(
|
|
71
|
-
KeyboardTransitionEvent.EVENT_NAME,
|
|
72
|
-
MapBuilder.of("registrationName", "onKeyboardMove")
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
return map
|
|
76
|
-
}
|
|
77
|
-
}
|