react-native-keyboard-controller 1.4.4 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/build.gradle +9 -2
- package/android/gradle.properties +2 -2
- package/android/react-native-helpers.gradle +48 -0
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardGestureAreaViewManager.kt +44 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/InteractiveKeyboardProvider.kt +6 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +27 -13
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationController.kt +394 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +1 -1
- package/android/src/main/java/com/reactnativekeyboardcontroller/events/KeyboardTransitionEvent.kt +2 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/Float.kt +4 -4
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +21 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/interpolators/Interpolator.kt +14 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/interpolators/IosInterpolator.kt +18 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/interpolators/LinearInterpolator.kt +11 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardControllerViewManagerImpl.kt +2 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardGestureAreaViewManagerImpl.kt +27 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/KeyboardGestureAreaReactViewGroup.kt +192 -0
- package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardGestureAreaViewManager.kt +33 -0
- package/ios/KeyboardControllerView.mm +10 -3
- package/ios/KeyboardControllerViewManager.mm +1 -0
- package/ios/KeyboardControllerViewManager.swift +1 -0
- package/ios/KeyboardMovementObserver.swift +78 -4
- package/jest/index.js +1 -0
- package/lib/commonjs/animated.js +13 -19
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/context.js +0 -3
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks.js +0 -13
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +0 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +13 -22
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/monkey-patch.js +3 -12
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/native.js +10 -10
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/replicas.js +3 -19
- package/lib/commonjs/replicas.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +0 -5
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +13 -0
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeKeyboardController.js +0 -3
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +0 -3
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js +0 -2
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/animated.js +13 -7
- package/lib/module/animated.js.map +1 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +13 -16
- package/lib/module/internal.js.map +1 -1
- package/lib/module/monkey-patch.js +4 -10
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/native.js +8 -5
- package/lib/module/native.js.map +1 -1
- package/lib/module/replicas.js +3 -5
- package/lib/module/replicas.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js +0 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/animated.d.ts +1 -1
- package/lib/typescript/context.d.ts +3 -3
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/native.d.ts +2 -1
- package/lib/typescript/replicas.d.ts +1 -1
- package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +6 -5
- package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
- package/lib/typescript/types.d.ts +29 -13
- package/package.json +11 -12
- package/src/animated.tsx +7 -0
- package/src/internal.ts +20 -3
- package/src/native.ts +5 -0
- package/src/specs/KeyboardControllerViewNativeComponent.ts +5 -6
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +14 -0
- package/src/types.ts +24 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport {\n useAnimatedKeyboardHandler,\n useSharedHandlers,\n useAnimatedValue,\n} from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n /**\n * Set the value to `true`, if you use translucent navigation bar on Android.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119\n * @platform android\n */\n navigationBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","setHandlers","broadcast","useSharedHandlers","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","Platform","OS","value","handler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","onKeyboardMoveInteractive","undefined"],"sources":["animated.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';\nimport Reanimated, { useSharedValue } from 'react-native-reanimated';\n\nimport { KeyboardContext } from './context';\nimport {\n useAnimatedKeyboardHandler,\n useSharedHandlers,\n useAnimatedValue,\n} from './internal';\nimport { KeyboardControllerView } from './native';\n\nimport type {\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from './types';\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView\n ) as React.FC<KeyboardControllerProps>\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: 'none',\n position: 'absolute',\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n /**\n * Set the value to `true`, if you use translucent navigation bar on Android.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119\n * @platform android\n */\n navigationBarTranslucent?: boolean;\n};\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n}: KeyboardProviderProps) => {\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const { setHandlers, broadcast } = useSharedHandlers<KeyboardHandler>();\n // memo\n const context = useMemo(\n () => ({\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n setHandlers,\n }),\n []\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n []\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver: true }\n ),\n []\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n 'worklet';\n\n if (platforms.includes(Platform.OS)) {\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const handler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onStart', event);\n updateSharedValues(event, ['ios']);\n },\n onKeyboardMove: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onMove', event);\n updateSharedValues(event, ['android']);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n 'worklet';\n\n broadcast('onEnd', event);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n 'worklet';\n\n updateSharedValues(event, ['android', 'ios']);\n broadcast('onInteractive', event);\n },\n },\n []\n );\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n onKeyboardMoveReanimated={handler}\n onKeyboardMoveStart={Platform.OS === 'ios' ? onKeyboardMove : undefined}\n onKeyboardMove={Platform.OS === 'android' ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n >\n <>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again (for example 'Animated transition').\n style={style}\n />\n {children}\n </>\n </KeyboardControllerViewAnimated>\n </KeyboardContext.Provider>\n );\n};\n"],"mappings":"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"}
|
package/lib/commonjs/context.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.KeyboardContext = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
9
|
const defaultContext = {
|
|
13
10
|
animated: {
|
|
14
11
|
progress: new _reactNative.Animated.Value(0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultContext","animated","progress","Animated","Value","height","reanimated","value","setHandlers","KeyboardContext","createContext"],"sources":["context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { Animated } from 'react-native';\n\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { KeyboardHandlers } from './types';\n\nexport type AnimatedContext = {\n progress: Animated.Value;\n height: Animated.AnimatedMultiplication<number>;\n};\nexport type ReanimatedContext = {\n progress: SharedValue<number>;\n height: SharedValue<number>;\n};\nexport type KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n setHandlers: (handlers: KeyboardHandlers) => void;\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: { value: 0 },\n height: { value: 0 },\n },\n setHandlers: () => {},\n};\nexport const KeyboardContext = createContext(defaultContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["defaultContext","animated","progress","Animated","Value","height","reanimated","value","setHandlers","KeyboardContext","createContext"],"sources":["context.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { Animated } from 'react-native';\n\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { KeyboardHandlers } from './types';\n\nexport type AnimatedContext = {\n progress: Animated.Value;\n height: Animated.AnimatedMultiplication<number>;\n};\nexport type ReanimatedContext = {\n progress: SharedValue<number>;\n height: SharedValue<number>;\n};\nexport type KeyboardAnimationContext = {\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n setHandlers: (handlers: KeyboardHandlers) => void;\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: { value: 0 },\n height: { value: 0 },\n },\n setHandlers: () => {},\n};\nexport const KeyboardContext = createContext(defaultContext);\n"],"mappings":";;;;;;AAAA;AACA;AAkBA,MAAMA,cAAwC,GAAG;EAC/CC,QAAQ,EAAE;IACRC,QAAQ,EAAE,IAAIC,qBAAQ,CAACC,KAAK,CAAC,CAAC,CAAC;IAC/BC,MAAM,EAAE,IAAIF,qBAAQ,CAACC,KAAK,CAAC,CAAC;EAC9B,CAAC;EACDE,UAAU,EAAE;IACVJ,QAAQ,EAAE;MAAEK,KAAK,EAAE;IAAE,CAAC;IACtBF,MAAM,EAAE;MAAEE,KAAK,EAAE;IAAE;EACrB,CAAC;EACDC,WAAW,EAAE,MAAM,CAAC;AACtB,CAAC;AACM,MAAMC,eAAe,gBAAG,IAAAC,oBAAa,EAACV,cAAc,CAAC;AAAC"}
|
package/lib/commonjs/hooks.js
CHANGED
|
@@ -7,41 +7,29 @@ exports.useGenericKeyboardHandler = useGenericKeyboardHandler;
|
|
|
7
7
|
exports.useKeyboardAnimation = void 0;
|
|
8
8
|
exports.useKeyboardHandler = useKeyboardHandler;
|
|
9
9
|
exports.useResizeMode = exports.useReanimatedKeyboardAnimation = void 0;
|
|
10
|
-
|
|
11
10
|
var _react = require("react");
|
|
12
|
-
|
|
13
11
|
var _context = require("./context");
|
|
14
|
-
|
|
15
12
|
var _native = require("./native");
|
|
16
|
-
|
|
17
13
|
var _utils = require("./utils");
|
|
18
|
-
|
|
19
14
|
const useResizeMode = () => {
|
|
20
15
|
(0, _react.useEffect)(() => {
|
|
21
16
|
_native.KeyboardController.setInputMode(_native.AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
22
|
-
|
|
23
17
|
return () => _native.KeyboardController.setDefaultMode();
|
|
24
18
|
}, []);
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
exports.useResizeMode = useResizeMode;
|
|
28
|
-
|
|
29
21
|
const useKeyboardAnimation = () => {
|
|
30
22
|
useResizeMode();
|
|
31
23
|
const context = (0, _react.useContext)(_context.KeyboardContext);
|
|
32
24
|
return context.animated;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
exports.useKeyboardAnimation = useKeyboardAnimation;
|
|
36
|
-
|
|
37
27
|
const useReanimatedKeyboardAnimation = () => {
|
|
38
28
|
useResizeMode();
|
|
39
29
|
const context = (0, _react.useContext)(_context.KeyboardContext);
|
|
40
30
|
return context.reanimated;
|
|
41
31
|
};
|
|
42
|
-
|
|
43
32
|
exports.useReanimatedKeyboardAnimation = useReanimatedKeyboardAnimation;
|
|
44
|
-
|
|
45
33
|
function useGenericKeyboardHandler(handler, deps) {
|
|
46
34
|
const context = (0, _react.useContext)(_context.KeyboardContext);
|
|
47
35
|
(0, _react.useEffect)(() => {
|
|
@@ -56,7 +44,6 @@ function useGenericKeyboardHandler(handler, deps) {
|
|
|
56
44
|
};
|
|
57
45
|
}, deps);
|
|
58
46
|
}
|
|
59
|
-
|
|
60
47
|
function useKeyboardHandler(handler, deps) {
|
|
61
48
|
useResizeMode();
|
|
62
49
|
useGenericKeyboardHandler(handler, deps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useResizeMode","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","useContext","KeyboardContext","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","key","uuid","setHandlers","undefined","useKeyboardHandler"],"sources":["hooks.ts"],"sourcesContent":["import { DependencyList, useContext, useEffect } from 'react';\n\nimport { AnimatedContext, KeyboardContext, ReanimatedContext } from './context';\nimport { AndroidSoftInputModes, KeyboardController } from './native';\nimport { uuid } from './utils';\n\nimport type { KeyboardHandler } from './types';\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n const context = useContext(KeyboardContext);\n\n useEffect(() => {\n const key = uuid();\n\n context.setHandlers({ [key]: handler });\n\n return () => {\n context.setHandlers({ [key]: undefined });\n };\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["useResizeMode","useEffect","KeyboardController","setInputMode","AndroidSoftInputModes","SOFT_INPUT_ADJUST_RESIZE","setDefaultMode","useKeyboardAnimation","context","useContext","KeyboardContext","animated","useReanimatedKeyboardAnimation","reanimated","useGenericKeyboardHandler","handler","deps","key","uuid","setHandlers","undefined","useKeyboardHandler"],"sources":["hooks.ts"],"sourcesContent":["import { DependencyList, useContext, useEffect } from 'react';\n\nimport { AnimatedContext, KeyboardContext, ReanimatedContext } from './context';\nimport { AndroidSoftInputModes, KeyboardController } from './native';\nimport { uuid } from './utils';\n\nimport type { KeyboardHandler } from './types';\n\nexport const useResizeMode = () => {\n useEffect(() => {\n KeyboardController.setInputMode(\n AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE\n );\n\n return () => KeyboardController.setDefaultMode();\n }, []);\n};\n\nexport const useKeyboardAnimation = (): AnimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.animated;\n};\n\nexport const useReanimatedKeyboardAnimation = (): ReanimatedContext => {\n useResizeMode();\n const context = useContext(KeyboardContext);\n\n return context.reanimated;\n};\n\nexport function useGenericKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n const context = useContext(KeyboardContext);\n\n useEffect(() => {\n const key = uuid();\n\n context.setHandlers({ [key]: handler });\n\n return () => {\n context.setHandlers({ [key]: undefined });\n };\n }, deps);\n}\n\nexport function useKeyboardHandler(\n handler: KeyboardHandler,\n deps?: DependencyList\n) {\n useResizeMode();\n useGenericKeyboardHandler(handler, deps);\n}\n"],"mappings":";;;;;;;;;AAAA;AAEA;AACA;AACA;AAIO,MAAMA,aAAa,GAAG,MAAM;EACjC,IAAAC,gBAAS,EAAC,MAAM;IACdC,0BAAkB,CAACC,YAAY,CAC7BC,6BAAqB,CAACC,wBAAwB,CAC/C;IAED,OAAO,MAAMH,0BAAkB,CAACI,cAAc,EAAE;EAClD,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAAC;AAEK,MAAMC,oBAAoB,GAAG,MAAuB;EACzDP,aAAa,EAAE;EACf,MAAMQ,OAAO,GAAG,IAAAC,iBAAU,EAACC,wBAAe,CAAC;EAE3C,OAAOF,OAAO,CAACG,QAAQ;AACzB,CAAC;AAAC;AAEK,MAAMC,8BAA8B,GAAG,MAAyB;EACrEZ,aAAa,EAAE;EACf,MAAMQ,OAAO,GAAG,IAAAC,iBAAU,EAACC,wBAAe,CAAC;EAE3C,OAAOF,OAAO,CAACK,UAAU;AAC3B,CAAC;AAAC;AAEK,SAASC,yBAAyB,CACvCC,OAAwB,EACxBC,IAAqB,EACrB;EACA,MAAMR,OAAO,GAAG,IAAAC,iBAAU,EAACC,wBAAe,CAAC;EAE3C,IAAAT,gBAAS,EAAC,MAAM;IACd,MAAMgB,GAAG,GAAG,IAAAC,WAAI,GAAE;IAElBV,OAAO,CAACW,WAAW,CAAC;MAAE,CAACF,GAAG,GAAGF;IAAQ,CAAC,CAAC;IAEvC,OAAO,MAAM;MACXP,OAAO,CAACW,WAAW,CAAC;QAAE,CAACF,GAAG,GAAGG;MAAU,CAAC,CAAC;IAC3C,CAAC;EACH,CAAC,EAAEJ,IAAI,CAAC;AACV;AAEO,SAASK,kBAAkB,CAChCN,OAAwB,EACxBC,IAAqB,EACrB;EACAhB,aAAa,EAAE;EACfc,yBAAyB,CAACC,OAAO,EAAEC,IAAI,CAAC;AAC1C"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
require("./monkey-patch");
|
|
8
|
-
|
|
9
7
|
var _native = require("./native");
|
|
10
|
-
|
|
11
8
|
Object.keys(_native).forEach(function (key) {
|
|
12
9
|
if (key === "default" || key === "__esModule") return;
|
|
13
10
|
if (key in exports && exports[key] === _native[key]) return;
|
|
@@ -18,9 +15,7 @@ Object.keys(_native).forEach(function (key) {
|
|
|
18
15
|
}
|
|
19
16
|
});
|
|
20
17
|
});
|
|
21
|
-
|
|
22
18
|
var _animated = require("./animated");
|
|
23
|
-
|
|
24
19
|
Object.keys(_animated).forEach(function (key) {
|
|
25
20
|
if (key === "default" || key === "__esModule") return;
|
|
26
21
|
if (key in exports && exports[key] === _animated[key]) return;
|
|
@@ -31,9 +26,7 @@ Object.keys(_animated).forEach(function (key) {
|
|
|
31
26
|
}
|
|
32
27
|
});
|
|
33
28
|
});
|
|
34
|
-
|
|
35
29
|
var _replicas = require("./replicas");
|
|
36
|
-
|
|
37
30
|
Object.keys(_replicas).forEach(function (key) {
|
|
38
31
|
if (key === "default" || key === "__esModule") return;
|
|
39
32
|
if (key in exports && exports[key] === _replicas[key]) return;
|
|
@@ -44,9 +37,7 @@ Object.keys(_replicas).forEach(function (key) {
|
|
|
44
37
|
}
|
|
45
38
|
});
|
|
46
39
|
});
|
|
47
|
-
|
|
48
40
|
var _context = require("./context");
|
|
49
|
-
|
|
50
41
|
Object.keys(_context).forEach(function (key) {
|
|
51
42
|
if (key === "default" || key === "__esModule") return;
|
|
52
43
|
if (key in exports && exports[key] === _context[key]) return;
|
|
@@ -57,9 +48,7 @@ Object.keys(_context).forEach(function (key) {
|
|
|
57
48
|
}
|
|
58
49
|
});
|
|
59
50
|
});
|
|
60
|
-
|
|
61
51
|
var _hooks = require("./hooks");
|
|
62
|
-
|
|
63
52
|
Object.keys(_hooks).forEach(function (key) {
|
|
64
53
|
if (key === "default" || key === "__esModule") return;
|
|
65
54
|
if (key in exports && exports[key] === _hooks[key]) return;
|
|
@@ -70,9 +59,7 @@ Object.keys(_hooks).forEach(function (key) {
|
|
|
70
59
|
}
|
|
71
60
|
});
|
|
72
61
|
});
|
|
73
|
-
|
|
74
62
|
var _types = require("./types");
|
|
75
|
-
|
|
76
63
|
Object.keys(_types).forEach(function (key) {
|
|
77
64
|
if (key === "default" || key === "__esModule") return;
|
|
78
65
|
if (key in exports && exports[key] === _types[key]) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './native';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './types';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './native';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './types';\n"],"mappings":";;;;;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/lib/commonjs/internal.js
CHANGED
|
@@ -6,13 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useAnimatedKeyboardHandler = useAnimatedKeyboardHandler;
|
|
7
7
|
exports.useAnimatedValue = useAnimatedValue;
|
|
8
8
|
exports.useSharedHandlers = useSharedHandlers;
|
|
9
|
-
|
|
10
9
|
var _react = require("react");
|
|
11
|
-
|
|
12
10
|
var _reactNative = require("react-native");
|
|
13
|
-
|
|
14
11
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
15
|
-
|
|
16
12
|
function useAnimatedKeyboardHandler(handlers, dependencies) {
|
|
17
13
|
const {
|
|
18
14
|
context,
|
|
@@ -24,22 +20,24 @@ function useAnimatedKeyboardHandler(handlers, dependencies) {
|
|
|
24
20
|
const {
|
|
25
21
|
onKeyboardMoveStart,
|
|
26
22
|
onKeyboardMove,
|
|
27
|
-
onKeyboardMoveEnd
|
|
23
|
+
onKeyboardMoveEnd,
|
|
24
|
+
onKeyboardMoveInteractive
|
|
28
25
|
} = handlers;
|
|
29
|
-
|
|
30
26
|
if (onKeyboardMoveStart && event.eventName.endsWith('onKeyboardMoveStart')) {
|
|
31
27
|
onKeyboardMoveStart(event, context);
|
|
32
28
|
}
|
|
33
|
-
|
|
34
29
|
if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {
|
|
35
30
|
onKeyboardMove(event, context);
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {
|
|
39
33
|
onKeyboardMoveEnd(event, context);
|
|
40
34
|
}
|
|
41
|
-
|
|
35
|
+
if (onKeyboardMoveInteractive && event.eventName.endsWith('onKeyboardMoveInteractive')) {
|
|
36
|
+
onKeyboardMoveInteractive(event, context);
|
|
37
|
+
}
|
|
38
|
+
}, ['onKeyboardMoveStart', 'onKeyboardMove', 'onKeyboardMoveEnd', 'onKeyboardMoveInteractive'], doDependenciesDiffer);
|
|
42
39
|
}
|
|
40
|
+
|
|
43
41
|
/**
|
|
44
42
|
* Hook for storing worklet handlers (objects with keys, where values are worklets).
|
|
45
43
|
* Returns methods for setting handlers and broadcasting events in them.
|
|
@@ -51,11 +49,11 @@ function useAnimatedKeyboardHandler(handlers, dependencies) {
|
|
|
51
49
|
* onEvent2: () => {},
|
|
52
50
|
* }
|
|
53
51
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
52
|
function useSharedHandlers() {
|
|
57
53
|
const handlers = (0, _reactNativeReanimated.useSharedValue)({});
|
|
58
|
-
const jsHandlers = (0, _react.useRef)({});
|
|
54
|
+
const jsHandlers = (0, _react.useRef)({});
|
|
55
|
+
|
|
56
|
+
// since js -> worklet -> js call is asynchronous, we can not write handlers
|
|
59
57
|
// straight into shared variable (using current shared value as a previous result),
|
|
60
58
|
// since there may be a race condition in a call, and closure may have out-of-dated
|
|
61
59
|
// values. As a result, some of handlers may be not written to "all handlers" object.
|
|
@@ -64,33 +62,30 @@ function useSharedHandlers() {
|
|
|
64
62
|
// This approach allow us to update synchronously handlers in js thread (and it assures,
|
|
65
63
|
// that it will have all of them) and then update them in worklet thread (calls are
|
|
66
64
|
// happening in FIFO order, so we will always have actual value).
|
|
67
|
-
|
|
68
65
|
const updateSharedHandlers = () => {
|
|
69
66
|
handlers.value = jsHandlers.current;
|
|
70
67
|
};
|
|
71
|
-
|
|
72
68
|
const setHandlers = (0, _react.useCallback)(handler => {
|
|
73
|
-
jsHandlers.current = {
|
|
69
|
+
jsHandlers.current = {
|
|
70
|
+
...jsHandlers.current,
|
|
74
71
|
...handler
|
|
75
72
|
};
|
|
76
73
|
updateSharedHandlers();
|
|
77
74
|
}, []);
|
|
78
|
-
|
|
79
75
|
const broadcast = (type, event) => {
|
|
80
76
|
'worklet';
|
|
81
77
|
|
|
82
78
|
Object.keys(handlers.value).forEach(key => {
|
|
83
79
|
var _handlers$value$key, _handlers$value$key$t;
|
|
84
|
-
|
|
85
80
|
return (_handlers$value$key = handlers.value[key]) === null || _handlers$value$key === void 0 ? void 0 : (_handlers$value$key$t = _handlers$value$key[type]) === null || _handlers$value$key$t === void 0 ? void 0 : _handlers$value$key$t.call(_handlers$value$key, event);
|
|
86
81
|
});
|
|
87
82
|
};
|
|
88
|
-
|
|
89
83
|
return {
|
|
90
84
|
setHandlers,
|
|
91
85
|
broadcast
|
|
92
86
|
};
|
|
93
87
|
}
|
|
88
|
+
|
|
94
89
|
/**
|
|
95
90
|
* TS variant of `useAnimatedValue` hook which is added in RN 0.71
|
|
96
91
|
* A better alternative of storing animated values in refs, since
|
|
@@ -100,15 +95,11 @@ function useSharedHandlers() {
|
|
|
100
95
|
*
|
|
101
96
|
* @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
|
|
102
97
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
98
|
function useAnimatedValue(initialValue, config) {
|
|
106
99
|
const ref = (0, _react.useRef)(null);
|
|
107
|
-
|
|
108
100
|
if (ref.current == null) {
|
|
109
101
|
ref.current = new _reactNative.Animated.Value(initialValue, config);
|
|
110
102
|
}
|
|
111
|
-
|
|
112
103
|
return ref.current;
|
|
113
104
|
}
|
|
114
105
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","useHandler","useEvent","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","eventName","endsWith","useSharedHandlers","useSharedValue","jsHandlers","useRef","updateSharedHandlers","value","current","setHandlers","useCallback","handler","broadcast","type","Object","keys","forEach","key","useAnimatedValue","initialValue","config","ref","Animated","Value"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const {
|
|
1
|
+
{"version":3,"names":["useAnimatedKeyboardHandler","handlers","dependencies","context","doDependenciesDiffer","useHandler","useEvent","event","onKeyboardMoveStart","onKeyboardMove","onKeyboardMoveEnd","onKeyboardMoveInteractive","eventName","endsWith","useSharedHandlers","useSharedValue","jsHandlers","useRef","updateSharedHandlers","value","current","setHandlers","useCallback","handler","broadcast","type","Object","keys","forEach","key","useAnimatedValue","initialValue","config","ref","Animated","Value"],"sources":["internal.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useEvent, useHandler, useSharedValue } from 'react-native-reanimated';\n\nimport type { EventWithName, Handlers, NativeEvent } from './types';\n\nexport function useAnimatedKeyboardHandler<\n TContext extends Record<string, unknown>\n>(\n handlers: {\n onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMove?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;\n onKeyboardMoveInteractive?: (e: NativeEvent, context: TContext) => void;\n },\n dependencies?: ReadonlyArray<unknown>\n) {\n const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);\n\n return useEvent(\n (event: EventWithName<NativeEvent>) => {\n 'worklet';\n const {\n onKeyboardMoveStart,\n onKeyboardMove,\n onKeyboardMoveEnd,\n onKeyboardMoveInteractive,\n } = handlers;\n\n if (\n onKeyboardMoveStart &&\n event.eventName.endsWith('onKeyboardMoveStart')\n ) {\n onKeyboardMoveStart(event, context);\n }\n\n if (onKeyboardMove && event.eventName.endsWith('onKeyboardMove')) {\n onKeyboardMove(event, context);\n }\n\n if (onKeyboardMoveEnd && event.eventName.endsWith('onKeyboardMoveEnd')) {\n onKeyboardMoveEnd(event, context);\n }\n\n if (\n onKeyboardMoveInteractive &&\n event.eventName.endsWith('onKeyboardMoveInteractive')\n ) {\n onKeyboardMoveInteractive(event, context);\n }\n },\n [\n 'onKeyboardMoveStart',\n 'onKeyboardMove',\n 'onKeyboardMoveEnd',\n 'onKeyboardMoveInteractive',\n ],\n doDependenciesDiffer\n );\n}\n\n/**\n * Hook for storing worklet handlers (objects with keys, where values are worklets).\n * Returns methods for setting handlers and broadcasting events in them.\n *\n * T is a generic that looks like:\n * @example\n * {\n * onEvent: () => {},\n * onEvent2: () => {},\n * }\n */\nexport function useSharedHandlers<T extends Record<string, Function>>() {\n const handlers = useSharedValue<Handlers<T>>({});\n const jsHandlers = useRef<Handlers<T>>({});\n\n // since js -> worklet -> js call is asynchronous, we can not write handlers\n // straight into shared variable (using current shared value as a previous result),\n // since there may be a race condition in a call, and closure may have out-of-dated\n // values. As a result, some of handlers may be not written to \"all handlers\" object.\n // Below we are writing all handlers to `ref` and afterwards synchronize them with\n // shared value (since `refs` are not referring to actual value in worklets).\n // This approach allow us to update synchronously handlers in js thread (and it assures,\n // that it will have all of them) and then update them in worklet thread (calls are\n // happening in FIFO order, so we will always have actual value).\n const updateSharedHandlers = () => {\n handlers.value = jsHandlers.current;\n };\n const setHandlers = useCallback((handler: Handlers<T>) => {\n jsHandlers.current = {\n ...jsHandlers.current,\n ...handler,\n };\n updateSharedHandlers();\n }, []);\n const broadcast = (type: keyof T, event: NativeEvent) => {\n 'worklet';\n\n Object.keys(handlers.value).forEach((key) =>\n handlers.value[key]?.[type]?.(event)\n );\n };\n\n return { setHandlers, broadcast };\n}\n\n/**\n * TS variant of `useAnimatedValue` hook which is added in RN 0.71\n * A better alternative of storing animated values in refs, since\n * it doesn't recreate a new `Animated.Value` object on every re-render\n * and therefore consumes less memory. We can not use a variant from\n * RN, since this library supports earlier versions of RN.\n *\n * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937\n */\nexport function useAnimatedValue(\n initialValue: number,\n config?: Animated.AnimatedConfig\n): Animated.Value {\n const ref = useRef<Animated.Value | null>(null);\n\n if (ref.current == null) {\n ref.current = new Animated.Value(initialValue, config);\n }\n\n return ref.current;\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAIO,SAASA,0BAA0B,CAGxCC,QAKC,EACDC,YAAqC,EACrC;EACA,MAAM;IAAEC,OAAO;IAAEC;EAAqB,CAAC,GAAG,IAAAC,iCAAU,EAACJ,QAAQ,EAAEC,YAAY,CAAC;EAE5E,OAAO,IAAAI,+BAAQ,EACZC,KAAiC,IAAK;IACrC,SAAS;;IACT,MAAM;MACJC,mBAAmB;MACnBC,cAAc;MACdC,iBAAiB;MACjBC;IACF,CAAC,GAAGV,QAAQ;IAEZ,IACEO,mBAAmB,IACnBD,KAAK,CAACK,SAAS,CAACC,QAAQ,CAAC,qBAAqB,CAAC,EAC/C;MACAL,mBAAmB,CAACD,KAAK,EAAEJ,OAAO,CAAC;IACrC;IAEA,IAAIM,cAAc,IAAIF,KAAK,CAACK,SAAS,CAACC,QAAQ,CAAC,gBAAgB,CAAC,EAAE;MAChEJ,cAAc,CAACF,KAAK,EAAEJ,OAAO,CAAC;IAChC;IAEA,IAAIO,iBAAiB,IAAIH,KAAK,CAACK,SAAS,CAACC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;MACtEH,iBAAiB,CAACH,KAAK,EAAEJ,OAAO,CAAC;IACnC;IAEA,IACEQ,yBAAyB,IACzBJ,KAAK,CAACK,SAAS,CAACC,QAAQ,CAAC,2BAA2B,CAAC,EACrD;MACAF,yBAAyB,CAACJ,KAAK,EAAEJ,OAAO,CAAC;IAC3C;EACF,CAAC,EACD,CACE,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,2BAA2B,CAC5B,EACDC,oBAAoB,CACrB;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASU,iBAAiB,GAAuC;EACtE,MAAMb,QAAQ,GAAG,IAAAc,qCAAc,EAAc,CAAC,CAAC,CAAC;EAChD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAc,CAAC,CAAC,CAAC;;EAE1C;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,oBAAoB,GAAG,MAAM;IACjCjB,QAAQ,CAACkB,KAAK,GAAGH,UAAU,CAACI,OAAO;EACrC,CAAC;EACD,MAAMC,WAAW,GAAG,IAAAC,kBAAW,EAAEC,OAAoB,IAAK;IACxDP,UAAU,CAACI,OAAO,GAAG;MACnB,GAAGJ,UAAU,CAACI,OAAO;MACrB,GAAGG;IACL,CAAC;IACDL,oBAAoB,EAAE;EACxB,CAAC,EAAE,EAAE,CAAC;EACN,MAAMM,SAAS,GAAG,CAACC,IAAa,EAAElB,KAAkB,KAAK;IACvD,SAAS;;IAETmB,MAAM,CAACC,IAAI,CAAC1B,QAAQ,CAACkB,KAAK,CAAC,CAACS,OAAO,CAAEC,GAAG;MAAA;MAAA,8BACtC5B,QAAQ,CAACkB,KAAK,CAACU,GAAG,CAAC,iFAAnB,oBAAsBJ,IAAI,CAAC,0DAA3B,gDAA8BlB,KAAK,CAAC;IAAA,EACrC;EACH,CAAC;EAED,OAAO;IAAEc,WAAW;IAAEG;EAAU,CAAC;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASM,gBAAgB,CAC9BC,YAAoB,EACpBC,MAAgC,EAChB;EAChB,MAAMC,GAAG,GAAG,IAAAhB,aAAM,EAAwB,IAAI,CAAC;EAE/C,IAAIgB,GAAG,CAACb,OAAO,IAAI,IAAI,EAAE;IACvBa,GAAG,CAACb,OAAO,GAAG,IAAIc,qBAAQ,CAACC,KAAK,CAACJ,YAAY,EAAEC,MAAM,CAAC;EACxD;EAEA,OAAOC,GAAG,CAACb,OAAO;AACpB"}
|
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _reactNative = require("react-native");
|
|
4
|
-
|
|
5
4
|
var NativeAndroidManager = _interopRequireWildcard(require("react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid"));
|
|
6
|
-
|
|
7
5
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
-
|
|
9
6
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
|
|
11
7
|
// @ts-expect-error because there is no corresponding type definition
|
|
8
|
+
|
|
12
9
|
const getConstants = NativeAndroidManager.default.getConstants;
|
|
10
|
+
const RCTStatusBarManagerCompat = require('./specs/NativeStatusBarManagerCompat').default;
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
|
|
15
13
|
// in order to use library on all available platforms we have to monkey patch
|
|
16
14
|
// default RN implementation and use modern `WindowInsetsControllerCompat`.
|
|
17
|
-
|
|
18
|
-
|
|
19
15
|
if (_reactNative.Platform.OS === 'android') {
|
|
20
16
|
NativeAndroidManager.default = {
|
|
21
17
|
getConstants,
|
|
22
|
-
|
|
23
18
|
setColor(color, animated) {
|
|
24
19
|
RCTStatusBarManagerCompat.setColor(color, animated);
|
|
25
20
|
},
|
|
26
|
-
|
|
27
21
|
setTranslucent(translucent) {
|
|
28
22
|
RCTStatusBarManagerCompat.setTranslucent(translucent);
|
|
29
23
|
},
|
|
30
|
-
|
|
31
24
|
/**
|
|
32
25
|
* - statusBarStyles can be:
|
|
33
26
|
* - 'default'
|
|
@@ -36,11 +29,9 @@ if (_reactNative.Platform.OS === 'android') {
|
|
|
36
29
|
setStyle(statusBarStyle) {
|
|
37
30
|
RCTStatusBarManagerCompat.setStyle(statusBarStyle);
|
|
38
31
|
},
|
|
39
|
-
|
|
40
32
|
setHidden(hidden) {
|
|
41
33
|
RCTStatusBarManagerCompat.setHidden(hidden);
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
};
|
|
45
36
|
}
|
|
46
37
|
//# sourceMappingURL=monkey-patch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getConstants","NativeAndroidManager","default","RCTStatusBarManagerCompat","require","Platform","OS","setColor","color","animated","setTranslucent","translucent","setStyle","statusBarStyle","setHidden","hidden"],"sources":["monkey-patch.ts"],"sourcesContent":["import { 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\nconst getConstants = NativeAndroidManager.default.getConstants;\n\nconst RCTStatusBarManagerCompat =\n require('./specs/NativeStatusBarManagerCompat').default;\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
|
|
1
|
+
{"version":3,"names":["getConstants","NativeAndroidManager","default","RCTStatusBarManagerCompat","require","Platform","OS","setColor","color","animated","setTranslucent","translucent","setStyle","statusBarStyle","setHidden","hidden"],"sources":["monkey-patch.ts"],"sourcesContent":["import { 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\nconst getConstants = NativeAndroidManager.default.getConstants;\n\nconst RCTStatusBarManagerCompat =\n require('./specs/NativeStatusBarManagerCompat').default;\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;AAEA;AAAkH;AAAA;AADlH;;AAGA,MAAMA,YAAY,GAAGC,oBAAoB,CAACC,OAAO,CAACF,YAAY;AAE9D,MAAMG,yBAAyB,GAC7BC,OAAO,CAAC,sCAAsC,CAAC,CAACF,OAAO;;AAEzD;AACA;AACA;AACA,IAAIG,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;EAC7BL,oBAAoB,CAACC,OAAO,GAAG;IAC7BF,YAAY;IACZO,QAAQ,CAACC,KAAa,EAAEC,QAAiB,EAAQ;MAC/CN,yBAAyB,CAACI,QAAQ,CAACC,KAAK,EAAEC,QAAQ,CAAC;IACrD,CAAC;IAEDC,cAAc,CAACC,WAAoB,EAAQ;MACzCR,yBAAyB,CAACO,cAAc,CAACC,WAAW,CAAC;IACvD,CAAC;IAED;AACJ;AACA;AACA;AACA;IACIC,QAAQ,CAACC,cAAuB,EAAQ;MACtCV,yBAAyB,CAACS,QAAQ,CAACC,cAAc,CAAC;IACpD,CAAC;IAEDC,SAAS,CAACC,MAAe,EAAQ;MAC/BZ,yBAAyB,CAACW,SAAS,CAACC,MAAM,CAAC;IAC7C;EACF,CAAC;AACH"}
|
package/lib/commonjs/native.js
CHANGED
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.KeyboardEvents = exports.KeyboardControllerView = exports.KeyboardController = exports.AndroidSoftInputModes = void 0;
|
|
7
|
-
|
|
6
|
+
exports.KeyboardGestureArea = exports.KeyboardEvents = exports.KeyboardControllerView = exports.KeyboardController = exports.AndroidSoftInputModes = void 0;
|
|
8
7
|
var _reactNative = require("react-native");
|
|
9
|
-
|
|
10
8
|
const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
11
9
|
ios: "- You have run 'pod install'\n",
|
|
12
10
|
default: ''
|
|
13
|
-
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
11
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
14
12
|
|
|
13
|
+
// copied from `android.view.WindowManager.LayoutParams`
|
|
15
14
|
let AndroidSoftInputModes;
|
|
16
15
|
exports.AndroidSoftInputModes = AndroidSoftInputModes;
|
|
17
|
-
|
|
18
16
|
(function (AndroidSoftInputModes) {
|
|
19
17
|
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_NOTHING"] = 48] = "SOFT_INPUT_ADJUST_NOTHING";
|
|
20
18
|
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_ADJUST_PAN"] = 32] = "SOFT_INPUT_ADJUST_PAN";
|
|
@@ -31,14 +29,11 @@ exports.AndroidSoftInputModes = AndroidSoftInputModes;
|
|
|
31
29
|
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_STATE_UNSPECIFIED"] = 0] = "SOFT_INPUT_STATE_UNSPECIFIED";
|
|
32
30
|
AndroidSoftInputModes[AndroidSoftInputModes["SOFT_INPUT_STATE_VISIBLE"] = 4] = "SOFT_INPUT_STATE_VISIBLE";
|
|
33
31
|
})(AndroidSoftInputModes || (exports.AndroidSoftInputModes = AndroidSoftInputModes = {}));
|
|
34
|
-
|
|
35
32
|
const RCTKeyboardController = require('./specs/NativeKeyboardController').default;
|
|
36
|
-
|
|
37
33
|
const KeyboardController = RCTKeyboardController ? RCTKeyboardController : new Proxy({}, {
|
|
38
34
|
get() {
|
|
39
35
|
throw new Error(LINKING_ERROR);
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
});
|
|
43
38
|
exports.KeyboardController = KeyboardController;
|
|
44
39
|
const eventEmitter = new _reactNative.NativeEventEmitter(KeyboardController);
|
|
@@ -46,8 +41,13 @@ const KeyboardEvents = {
|
|
|
46
41
|
addListener: (name, cb) => eventEmitter.addListener('KeyboardController::' + name, cb)
|
|
47
42
|
};
|
|
48
43
|
exports.KeyboardEvents = KeyboardEvents;
|
|
49
|
-
|
|
50
44
|
const KeyboardControllerView = require('./specs/KeyboardControllerViewNativeComponent').default;
|
|
51
|
-
|
|
52
45
|
exports.KeyboardControllerView = KeyboardControllerView;
|
|
46
|
+
const KeyboardGestureArea = _reactNative.Platform.OS === 'android' && _reactNative.Platform.Version >= 30 ? require('./specs/KeyboardGestureAreaNativeComponent').default : _ref => {
|
|
47
|
+
let {
|
|
48
|
+
children
|
|
49
|
+
} = _ref;
|
|
50
|
+
return children;
|
|
51
|
+
};
|
|
52
|
+
exports.KeyboardGestureArea = KeyboardGestureArea;
|
|
53
53
|
//# sourceMappingURL=native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventData,\n} from './types';\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 Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\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 SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView: React.FC<KeyboardControllerProps> =\n require('./specs/KeyboardControllerViewNativeComponent').default;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","AndroidSoftInputModes","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","KeyboardGestureArea","OS","Version","children"],"sources":["native.ts"],"sourcesContent":["import { Platform, NativeEventEmitter } from 'react-native';\n\nimport type {\n KeyboardControllerEvents,\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventData,\n KeyboardGestureAreaProps,\n} from './types';\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 Go\\n';\n\n// copied from `android.view.WindowManager.LayoutParams`\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 SOFT_INPUT_IS_FORWARD_NAVIGATION = 256,\n SOFT_INPUT_MASK_ADJUST = 240,\n SOFT_INPUT_MASK_STATE = 15,\n SOFT_INPUT_MODE_CHANGED = 512,\n SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3,\n SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5,\n SOFT_INPUT_STATE_HIDDEN = 2,\n SOFT_INPUT_STATE_UNCHANGED = 1,\n SOFT_INPUT_STATE_UNSPECIFIED = 0,\n SOFT_INPUT_STATE_VISIBLE = 4,\n}\n\nconst RCTKeyboardController =\n require('./specs/NativeKeyboardController').default;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => eventEmitter.addListener('KeyboardController::' + name, cb),\n};\nexport const KeyboardControllerView: React.FC<KeyboardControllerProps> =\n require('./specs/KeyboardControllerViewNativeComponent').default;\nexport const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =\n Platform.OS === 'android' && Platform.Version >= 30\n ? require('./specs/KeyboardGestureAreaNativeComponent').default\n : ({ children }: KeyboardGestureAreaProps) => children;\n"],"mappings":";;;;;;AAAA;AAUA,MAAMA,aAAa,GAChB,2FAA0F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AAAA,IACYC,qBAAqB;AAAA;AAAA,WAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;EAArBA,qBAAqB,CAArBA,qBAAqB;AAAA,GAArBA,qBAAqB,qCAArBA,qBAAqB;AAiBjC,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAkC,CAAC,CAACH,OAAO;AAC9C,MAAMI,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBAAqB,GACrB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAK,CAACX,aAAa,CAAC;EAChC;AACF,CAAC,CAEoB;AAAC;AAE9B,MAAMY,YAAY,GAAG,IAAIC,+BAAkB,CAACL,kBAAkB,CAAC;AAExD,MAAMM,cAAc,GAAG;EAC5BC,WAAW,EAAE,CACXC,IAA8B,EAC9BC,EAAkC,KAC/BL,YAAY,CAACG,WAAW,CAAC,sBAAsB,GAAGC,IAAI,EAAEC,EAAE;AACjE,CAAC;AAAC;AACK,MAAMC,sBAAyD,GACpEX,OAAO,CAAC,+CAA+C,CAAC,CAACH,OAAO;AAAC;AAC5D,MAAMe,mBAAuD,GAClElB,qBAAQ,CAACmB,EAAE,KAAK,SAAS,IAAInB,qBAAQ,CAACoB,OAAO,IAAI,EAAE,GAC/Cd,OAAO,CAAC,4CAA4C,CAAC,CAACH,OAAO,GAC7D;EAAA,IAAC;IAAEkB;EAAmC,CAAC;EAAA,OAAKA,QAAQ;AAAA;AAAC"}
|
package/lib/commonjs/replicas.js
CHANGED
|
@@ -4,23 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useReanimatedKeyboardAnimationReplica = exports.useKeyboardAnimationReplica = exports.useGradualKeyboardAnimation = exports.defaultAndroidEasing = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
9
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
13
|
-
|
|
14
10
|
var _hooks = require("./hooks");
|
|
15
|
-
|
|
16
11
|
var _native = require("./native");
|
|
12
|
+
const availableOSEventType = _reactNative.Platform.OS === 'ios' ? 'Will' : 'Did';
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
// cubic-bezier(.17,.67,.34,.94)
|
|
20
15
|
const defaultAndroidEasing = _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1);
|
|
21
|
-
|
|
22
16
|
exports.defaultAndroidEasing = defaultAndroidEasing;
|
|
23
|
-
|
|
24
17
|
/**
|
|
25
18
|
* An experimental implementation of tracing keyboard appearance.
|
|
26
19
|
* Switch an input mode to adjust resize mode. In this case all did* events
|
|
@@ -38,7 +31,6 @@ const useKeyboardAnimationReplica = () => {
|
|
|
38
31
|
}), []);
|
|
39
32
|
(0, _react.useEffect)(() => {
|
|
40
33
|
_native.KeyboardController.setInputMode(_native.AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE);
|
|
41
|
-
|
|
42
34
|
return () => _native.KeyboardController.setDefaultMode();
|
|
43
35
|
}, []);
|
|
44
36
|
(0, _react.useEffect)(() => {
|
|
@@ -49,7 +41,6 @@ const useKeyboardAnimationReplica = () => {
|
|
|
49
41
|
easing: _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1),
|
|
50
42
|
useNativeDriver: true
|
|
51
43
|
}).start();
|
|
52
|
-
|
|
53
44
|
return () => listener.remove();
|
|
54
45
|
});
|
|
55
46
|
}, []);
|
|
@@ -61,13 +52,11 @@ const useKeyboardAnimationReplica = () => {
|
|
|
61
52
|
easing: _reactNative.Easing.bezier(0.4, 0.0, 0.2, 1),
|
|
62
53
|
useNativeDriver: true
|
|
63
54
|
}).start();
|
|
64
|
-
|
|
65
55
|
return () => listener.remove();
|
|
66
56
|
});
|
|
67
57
|
}, []);
|
|
68
58
|
return animation;
|
|
69
59
|
};
|
|
70
|
-
|
|
71
60
|
exports.useKeyboardAnimationReplica = useKeyboardAnimationReplica;
|
|
72
61
|
const IOS_SPRING_CONFIG = {
|
|
73
62
|
damping: 500,
|
|
@@ -77,6 +66,7 @@ const IOS_SPRING_CONFIG = {
|
|
|
77
66
|
restDisplacementThreshold: 10,
|
|
78
67
|
restSpeedThreshold: 10
|
|
79
68
|
};
|
|
69
|
+
|
|
80
70
|
/**
|
|
81
71
|
* A close replica to native iOS keyboard animation. The problem is that
|
|
82
72
|
* iOS (unlike Android) can not fire events for each keyboard frame movement.
|
|
@@ -91,7 +81,6 @@ const IOS_SPRING_CONFIG = {
|
|
|
91
81
|
*
|
|
92
82
|
* @returns {height, progress} - animated values
|
|
93
83
|
*/
|
|
94
|
-
|
|
95
84
|
const useReanimatedKeyboardAnimationReplica = () => {
|
|
96
85
|
const height = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
97
86
|
const heightEvent = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
@@ -105,9 +94,7 @@ const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
105
94
|
const {
|
|
106
95
|
_keyboardHeight
|
|
107
96
|
} = result;
|
|
108
|
-
|
|
109
97
|
const _previousKeyboardHeight = _previousResult === null || _previousResult === void 0 ? void 0 : _previousResult._keyboardHeight;
|
|
110
|
-
|
|
111
98
|
if (_keyboardHeight !== _previousKeyboardHeight) {
|
|
112
99
|
height.value = (0, _reactNativeReanimated.withSpring)(_keyboardHeight, IOS_SPRING_CONFIG);
|
|
113
100
|
}
|
|
@@ -116,11 +103,9 @@ const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
116
103
|
const show = _reactNative.Keyboard.addListener('keyboardWillShow', e => {
|
|
117
104
|
(0, _reactNativeReanimated.runOnUI)(handler)(-e.endCoordinates.height);
|
|
118
105
|
});
|
|
119
|
-
|
|
120
106
|
const hide = _reactNative.Keyboard.addListener('keyboardWillHide', () => {
|
|
121
107
|
(0, _reactNativeReanimated.runOnUI)(handler)(0);
|
|
122
108
|
});
|
|
123
|
-
|
|
124
109
|
return () => {
|
|
125
110
|
show.remove();
|
|
126
111
|
hide.remove();
|
|
@@ -131,7 +116,6 @@ const useReanimatedKeyboardAnimationReplica = () => {
|
|
|
131
116
|
progress
|
|
132
117
|
};
|
|
133
118
|
};
|
|
134
|
-
|
|
135
119
|
exports.useReanimatedKeyboardAnimationReplica = useReanimatedKeyboardAnimationReplica;
|
|
136
120
|
const useGradualKeyboardAnimation = _reactNative.Platform.OS === 'ios' ? useReanimatedKeyboardAnimationReplica : _hooks.useReanimatedKeyboardAnimation;
|
|
137
121
|
exports.useGradualKeyboardAnimation = useGradualKeyboardAnimation;
|