react-native-keyboard-controller 1.1.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.
- package/android/build.gradle +32 -3
- 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 +6 -6
- package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModule.kt → KeyboardControllerModuleImpl.kt} +5 -17
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +45 -4
- package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerViewManager.kt → KeyboardControllerViewManagerImpl.kt} +8 -9
- package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatModule.kt → StatusBarManagerCompatImpl.kt} +10 -14
- 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 +1 -1
- package/ios/KeyboardController.xcodeproj/project.pbxproj +20 -16
- 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} +0 -0
- package/ios/KeyboardControllerViewManager.swift +2 -2
- package/ios/KeyboardMoveEvent.h +18 -0
- package/ios/KeyboardMoveEvent.m +74 -0
- package/lib/commonjs/animated.js +14 -59
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/context.js +28 -0
- package/lib/commonjs/context.js.map +1 -0
- package/lib/commonjs/hooks.js +39 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +39 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +27 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/monkey-patch.js +3 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/native.js +24 -19
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/replicas.js +2 -2
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeKeyboardController.js +13 -0
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +13 -0
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/animated.js +12 -50
- package/lib/module/animated.js.map +1 -1
- package/lib/module/context.js +18 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/hooks.js +20 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +19 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/monkey-patch.js +4 -2
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/native.js +23 -16
- package/lib/module/native.js.map +1 -1
- package/lib/module/replicas.js +1 -1
- package/lib/module/replicas.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +4 -0
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeKeyboardController.js +3 -0
- package/lib/module/specs/NativeKeyboardController.js.map +1 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/animated.d.ts +1 -17
- package/lib/typescript/context.d.ts +16 -0
- package/lib/typescript/hooks.d.ts +4 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/internal.d.ts +4 -0
- package/lib/typescript/native.d.ts +15 -27
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +13 -0
- package/lib/typescript/specs/NativeKeyboardController.d.ts +10 -0
- package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
- package/lib/typescript/types.d.ts +23 -0
- package/package.json +20 -8
- package/react-native-keyboard-controller.podspec +21 -1
- package/src/animated.tsx +12 -75
- package/src/context.ts +28 -0
- package/src/hooks.ts +28 -0
- package/src/index.ts +3 -0
- package/src/internal.ts +27 -0
- package/src/{monkey-patch.tsx → monkey-patch.ts} +3 -2
- package/src/native.ts +37 -61
- package/src/replicas.ts +1 -1
- package/src/specs/KeyboardControllerViewNativeComponent.ts +23 -0
- package/src/specs/NativeKeyboardController.ts +16 -0
- package/src/specs/NativeStatusBarManagerCompat.ts +13 -0
- package/src/types.ts +42 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/ios/KeyboardControllerModule.m +0 -21
- package/ios/KeyboardControllerModule.swift +0 -53
- package/ios/KeyboardMoveEvent.swift +0 -41
|
@@ -1 +1 @@
|
|
|
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 './
|
|
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 './hooks';\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,OAA3C;AACA,SAASC,QAAT,EAAmBC,MAAnB,EAA2BC,QAA3B,EAAqCC,QAArC,QAAqD,cAArD;AACA,SACEC,OADF,EAEEC,mBAFF,EAGEC,eAHF,EAIEC,cAJF,EAKEC,kBALF,EAMEC,UANF,QAOO,yBAPP;AAQA,SAASC,8BAAT,QAA+C,SAA/C;AAEA,SAASC,qBAAT,EAAgCC,kBAAhC,QAA0D,UAA1D;AAEA,MAAMC,oBAAoB,GAAGV,QAAQ,CAACW,EAAT,KAAgB,KAAhB,GAAwB,MAAxB,GAAiC,KAA9D,C,CAEA;;AACA,OAAO,MAAMC,oBAAoB,GAAGd,MAAM,CAACe,MAAP,CAAc,GAAd,EAAmB,GAAnB,EAAwB,GAAxB,EAA6B,CAA7B,CAA7B;;AAMP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAG,MAAyB;EAClE,MAAMC,MAAM,GAAGrB,MAAM,CAAC,IAAIG,QAAQ,CAACmB,KAAb,CAAmB,CAAnB,CAAD,CAArB;EACA,MAAMC,QAAQ,GAAGvB,MAAM,CAAC,IAAIG,QAAQ,CAACmB,KAAb,CAAmB,CAAnB,CAAD,CAAvB;EACA,MAAME,SAAS,GAAGtB,OAAO,CACvB,OAAO;IACLmB,MAAM,EAAEA,MAAM,CAACI,OADV;IAELF,QAAQ,EAAEA,QAAQ,CAACE;EAFd,CAAP,CADuB,EAKvB,EALuB,CAAzB;EAQAxB,SAAS,CAAC,MAAM;IACdc,kBAAkB,CAACW,YAAnB,CACEZ,qBAAqB,CAACa,wBADxB;IAIA,OAAO,MAAMZ,kBAAkB,CAACa,cAAnB,EAAb;EACD,CANQ,EAMN,EANM,CAAT;EAOA3B,SAAS,CAAC,MAAM;IACd,MAAM4B,QAAQ,GAAGxB,QAAQ,CAACyB,WAAT,CACd,WAAUd,oBAAqB,MADjB,EAEde,CAAD,IAAO;MACL5B,QAAQ,CAAC6B,MAAT,CAAgBX,MAAM,CAACI,OAAvB,EAAgC;QAC9BQ,OAAO,EAAE,CAACF,CAAC,CAACG,cAAF,CAAiBb,MADG;QAE9Bc,QAAQ,EAAEJ,CAAC,CAACI,QAAF,KAAe,CAAf,GAAmBJ,CAAC,CAACI,QAArB,GAAgC,GAFZ;QAG9BC,MAAM,EAAEhC,MAAM,CAACe,MAAP,CAAc,GAAd,EAAmB,GAAnB,EAAwB,GAAxB,EAA6B,CAA7B,CAHsB;QAI9BkB,eAAe,EAAE;MAJa,CAAhC,EAKGC,KALH;MAOA,OAAO,MAAMT,QAAQ,CAACU,MAAT,EAAb;IACD,CAXc,CAAjB;EAaD,CAdQ,EAcN,EAdM,CAAT;EAeAtC,SAAS,CAAC,MAAM;IACd,MAAM4B,QAAQ,GAAGxB,QAAQ,CAACyB,WAAT,CACd,WAAUd,oBAAqB,MADjB,EAEde,CAAD,IAAO;MACL5B,QAAQ,CAAC6B,MAAT,CAAgBX,MAAM,CAACI,OAAvB,EAAgC;QAC9BQ,OAAO,EAAE,CADqB;QAE9BE,QAAQ,EAAEJ,CAAC,CAACI,QAAF,KAAe,CAAf,GAAmBJ,CAAC,CAACI,QAArB,GAAgC,GAFZ;QAG9BC,MAAM,EAAEhC,MAAM,CAACe,MAAP,CAAc,GAAd,EAAmB,GAAnB,EAAwB,GAAxB,EAA6B,CAA7B,CAHsB;QAI9BkB,eAAe,EAAE;MAJa,CAAhC,EAKGC,KALH;MAOA,OAAO,MAAMT,QAAQ,CAACU,MAAT,EAAb;IACD,CAXc,CAAjB;EAaD,CAdQ,EAcN,EAdM,CAAT;EAgBA,OAAOf,SAAP;AACD,CAlDM;AAoDP,MAAMgB,iBAAiB,GAAG;EACxBC,OAAO,EAAE,GADe;EAExBC,SAAS,EAAE,IAFa;EAGxBC,IAAI,EAAE,CAHkB;EAIxBC,iBAAiB,EAAE,IAJK;EAKxBC,yBAAyB,EAAE,EALH;EAMxBC,kBAAkB,EAAE;AANI,CAA1B;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,qCAAqC,GAAG,MAAM;EACzD,MAAM1B,MAAM,GAAGX,cAAc,CAAC,CAAD,CAA7B;EACA,MAAMsC,WAAW,GAAGtC,cAAc,CAAC,CAAD,CAAlC;EAEA,MAAMa,QAAQ,GAAGd,eAAe,CAAC,MAAMY,MAAM,CAAC4B,KAAP,GAAeD,WAAW,CAACC,KAAlC,CAAhC;EAEA,MAAMC,OAAO,GAAGvC,kBAAkB,CAAEwC,OAAD,IAAqB;IACtDH,WAAW,CAACC,KAAZ,GAAoBE,OAApB;EACD,CAFiC,EAE/B,EAF+B,CAAlC;EAIA3C,mBAAmB,CACjB,OAAO;IACL4C,eAAe,EAAEJ,WAAW,CAACC;EADxB,CAAP,CADiB,EAIjB,CAACI,MAAD,EAASC,eAAT,KAA6B;IAC3B,MAAM;MAAEF;IAAF,IAAsBC,MAA5B;;IACA,MAAME,uBAAuB,GAAGD,eAAH,aAAGA,eAAH,uBAAGA,eAAe,CAAEF,eAAjD;;IAEA,IAAIA,eAAe,KAAKG,uBAAxB,EAAiD;MAC/ClC,MAAM,CAAC4B,KAAP,GAAerC,UAAU,CAACwC,eAAD,EAAkBZ,iBAAlB,CAAzB;IACD;EACF,CAXgB,EAYjB,EAZiB,CAAnB;EAeAvC,SAAS,CAAC,MAAM;IACd,MAAMuD,IAAI,GAAGnD,QAAQ,CAACyB,WAAT,CAAqB,kBAArB,EAA0CC,CAAD,IAAO;MAC3DxB,OAAO,CAAC2C,OAAD,CAAP,CAAiB,CAACnB,CAAC,CAACG,cAAF,CAAiBb,MAAnC;IACD,CAFY,CAAb;IAGA,MAAMoC,IAAI,GAAGpD,QAAQ,CAACyB,WAAT,CAAqB,kBAArB,EAAyC,MAAM;MAC1DvB,OAAO,CAAC2C,OAAD,CAAP,CAAiB,CAAjB;IACD,CAFY,CAAb;IAIA,OAAO,MAAM;MACXM,IAAI,CAACjB,MAAL;MACAkB,IAAI,CAAClB,MAAL;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 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["KeyboardControllerViewNativeComponent.ts"],"sourcesContent":["import type { HostComponent } from 'react-native';\n// @ts-expect-error - no type definition\nimport type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';\nimport type {\n DirectEventHandler,\n Float,\n Int32,\n} from 'react-native/Libraries/Types/CodegenTypes';\nimport codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\n\ntype KeyboardMoveEvent = Readonly<{\n height: Int32;\n progress: Float;\n}>;\n\nexport interface NativeProps extends ViewProps {\n statusBarTranslucent?: boolean;\n onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;\n}\n\nexport default codegenNativeComponent<NativeProps>(\n 'KeyboardControllerView'\n) as HostComponent<NativeProps>;\n"],"mappings":"AACA;AAOA,OAAOA,sBAAP,MAAmC,yDAAnC;AAYA,eAAeA,sBAAsB,CACnC,wBADmC,CAArC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeKeyboardController.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n // methods\n setInputMode(mode: number): void;\n setDefaultMode(): void;\n\n // event emitter\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('KeyboardController');\n"],"mappings":"AACA,SAASA,mBAAT,QAAoC,cAApC;AAcA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,oBAA9B,CAAf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeStatusBarManagerCompat.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\nexport interface Spec extends TurboModule {\n readonly getConstants: () => {};\n\n setHidden(hidden: boolean): void;\n setColor(color: number, animated: boolean): void;\n setTranslucent(translucent: boolean): void;\n setStyle(style: string): void;\n}\n\nexport default TurboModuleRegistry.get<Spec>('StatusBarManagerCompat');\n"],"mappings":"AACA,SAASA,mBAAT,QAAoC,cAApC;AAWA,eAAeA,mBAAmB,CAACC,GAApB,CAA8B,wBAA9B,CAAf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { NativeSyntheticEvent, ViewProps } from 'react-native';\n\n// DirectEventHandler events declaration\n\nexport type NativeEvent = {\n progress: number;\n height: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\n\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;\n\nexport type KeyboardControllerModule = {\n // android only\n setDefaultMode: () => void;\n setInputMode: (mode: number) => void;\n // native event module stuff\n addListener: (eventName: string) => void;\n removeListeners: (count: number) => void;\n};\n\n// Event module declarations\n\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n};\n"],"mappings":""}
|
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import Reanimated from 'react-native-reanimated';
|
|
4
|
-
declare type AnimatedContext = {
|
|
5
|
-
progress: Animated.Value;
|
|
6
|
-
height: Animated.Value;
|
|
7
|
-
};
|
|
8
|
-
declare type ReanimatedContext = {
|
|
9
|
-
progress: Reanimated.SharedValue<number>;
|
|
10
|
-
height: Reanimated.SharedValue<number>;
|
|
11
|
-
};
|
|
12
|
-
declare type KeyboardAnimationContext = {
|
|
13
|
-
animated: AnimatedContext;
|
|
14
|
-
reanimated: ReanimatedContext;
|
|
15
|
-
};
|
|
16
|
-
export declare const KeyboardContext: React.Context<KeyboardAnimationContext>;
|
|
17
|
-
export declare const useKeyboardAnimation: () => AnimatedContext;
|
|
18
|
-
export declare const useReanimatedKeyboardAnimation: () => ReanimatedContext;
|
|
2
|
+
import { ViewStyle } from 'react-native';
|
|
19
3
|
declare type Styles = {
|
|
20
4
|
container: ViewStyle;
|
|
21
5
|
hidden: ViewStyle;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
export declare type AnimatedContext = {
|
|
5
|
+
progress: Animated.Value;
|
|
6
|
+
height: Animated.Value;
|
|
7
|
+
};
|
|
8
|
+
export declare type ReanimatedContext = {
|
|
9
|
+
progress: SharedValue<number>;
|
|
10
|
+
height: SharedValue<number>;
|
|
11
|
+
};
|
|
12
|
+
export declare type KeyboardAnimationContext = {
|
|
13
|
+
animated: AnimatedContext;
|
|
14
|
+
reanimated: ReanimatedContext;
|
|
15
|
+
};
|
|
16
|
+
export declare const KeyboardContext: import("react").Context<KeyboardAnimationContext>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EventWithName, NativeEvent } from './types';
|
|
2
|
+
export declare function useAnimatedKeyboardHandler<TContext extends Record<string, unknown>>(handlers: {
|
|
3
|
+
onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
|
|
4
|
+
}, dependencies?: ReadonlyArray<unknown>): (e: import("react-native").NativeSyntheticEvent<EventWithName<NativeEvent>>) => void;
|
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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:
|
|
20
|
+
addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => import("react-native").EmitterSubscription;
|
|
31
21
|
};
|
|
32
|
-
export declare const KeyboardControllerView:
|
|
33
|
-
export declare const useResizeMode: () => void;
|
|
34
|
-
export {};
|
|
22
|
+
export declare const KeyboardControllerView: any;
|
|
@@ -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;
|
|
@@ -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.
|
|
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",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"react-native-keyboard-controller.podspec",
|
|
17
17
|
"!lib/typescript/example",
|
|
18
18
|
"!android/build",
|
|
19
|
+
"!android/.gradle",
|
|
20
|
+
"!android/gradle",
|
|
21
|
+
"!android/gradlew",
|
|
22
|
+
"!android/gradlew.bat",
|
|
19
23
|
"!ios/build",
|
|
20
24
|
"!**/__tests__",
|
|
21
25
|
"!**/__fixtures__",
|
|
@@ -54,8 +58,8 @@
|
|
|
54
58
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
55
59
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
56
60
|
"@types/jest": "^27.4.1",
|
|
57
|
-
"@types/react": "^18.0.
|
|
58
|
-
"@types/react-native": "0.
|
|
61
|
+
"@types/react": "^18.0.21",
|
|
62
|
+
"@types/react-native": "0.70.4",
|
|
59
63
|
"commitlint": "^11.0.0",
|
|
60
64
|
"clang-format": "^1.8.0",
|
|
61
65
|
"eslint": "^7.2.0",
|
|
@@ -65,17 +69,17 @@
|
|
|
65
69
|
"jest": "^27.5.1",
|
|
66
70
|
"pod-install": "^0.1.0",
|
|
67
71
|
"prettier": "^2.6.2",
|
|
68
|
-
"react": "18.
|
|
69
|
-
"react-native": "0.
|
|
72
|
+
"react": "18.1.0",
|
|
73
|
+
"react-native": "0.70.2",
|
|
70
74
|
"react-native-builder-bob": "^0.18.0",
|
|
71
|
-
"react-native-reanimated": "2.
|
|
75
|
+
"react-native-reanimated": "2.10.0",
|
|
72
76
|
"release-it": "^14.2.2",
|
|
73
|
-
"typescript": "^4.
|
|
77
|
+
"typescript": "^4.8.4"
|
|
74
78
|
},
|
|
75
79
|
"peerDependencies": {
|
|
76
80
|
"react": "*",
|
|
77
81
|
"react-native": "*",
|
|
78
|
-
"react-native-reanimated": "
|
|
82
|
+
"react-native-reanimated": ">=2.3.0"
|
|
79
83
|
},
|
|
80
84
|
"jest": {
|
|
81
85
|
"preset": "react-native",
|
|
@@ -150,5 +154,13 @@
|
|
|
150
154
|
}
|
|
151
155
|
]
|
|
152
156
|
]
|
|
157
|
+
},
|
|
158
|
+
"codegenConfig": {
|
|
159
|
+
"name": "reactnativekeyboardcontroller",
|
|
160
|
+
"type": "all",
|
|
161
|
+
"jsSrcsDir": "./src/specs",
|
|
162
|
+
"android": {
|
|
163
|
+
"javaPackageName": "com.reactnativekeyboardcontroller"
|
|
164
|
+
}
|
|
153
165
|
}
|
|
154
166
|
}
|
|
@@ -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"]
|
|
@@ -10,10 +12,28 @@ Pod::Spec.new do |s|
|
|
|
10
12
|
s.license = package["license"]
|
|
11
13
|
s.authors = package["author"]
|
|
12
14
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
15
|
+
s.platforms = { :ios => "11.0" }
|
|
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
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
29
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
s.dependency "React-RCTFabric"
|
|
33
|
+
s.dependency "React-Codegen"
|
|
34
|
+
s.dependency "RCT-Folly"
|
|
35
|
+
s.dependency "RCTRequired"
|
|
36
|
+
s.dependency "RCTTypeSafety"
|
|
37
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
38
|
+
end
|
|
19
39
|
end
|
package/src/animated.tsx
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo, useRef } from 'react';
|
|
2
2
|
import { Animated, StyleSheet, ViewStyle } from 'react-native';
|
|
3
|
-
import Reanimated, {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
8
|
-
|
|
9
|
-
|
|
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
package/src/internal.ts
ADDED
|
@@ -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,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
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
5
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
6
6
|
|
|
7
|
-
const RCTStatusBarManagerCompat =
|
|
7
|
+
const RCTStatusBarManagerCompat =
|
|
8
|
+
require('./specs/NativeStatusBarManagerCompat').default;
|
|
8
9
|
|
|
9
10
|
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
10
11
|
// in order to use library on all available platforms we have to monkey patch
|