react-native-keyboard-controller 1.6.0 → 1.7.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/README.md +1 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +9 -1
- package/android/src/main/java/com/reactnativekeyboardcontroller/events/KeyboardTransitionEvent.kt +9 -9
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ViewGroup.kt +10 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt +13 -7
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/EdgeToEdgeReactViewGroup.kt +58 -40
- package/ios/Extensions.swift +2 -2
- package/ios/KeyboardController-Bridging-Header.h +0 -1
- package/lib/commonjs/animated.js +1 -1
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +35 -0
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +97 -0
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/commonjs/components/index.js +14 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/context.js +9 -6
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/index.js +17 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/animated.js +1 -1
- package/lib/module/animated.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js +28 -0
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
- package/lib/module/components/KeyboardAvoidingView/index.js +88 -0
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
- package/lib/module/components/index.js +2 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/context.js +9 -6
- package/lib/module/context.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +5 -0
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +29 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/replicas.d.ts +2 -7
- package/lib/typescript/types.d.ts +1 -1
- package/package.json +5 -5
- package/src/animated.tsx +1 -1
- package/src/components/KeyboardAvoidingView/hooks.ts +29 -0
- package/src/components/KeyboardAvoidingView/index.tsx +147 -0
- package/src/components/index.ts +1 -0
- package/src/context.ts +9 -2
- package/src/index.ts +2 -0
- package/src/types.ts +1 -1
package/lib/commonjs/index.js
CHANGED
|
@@ -3,10 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
KeyboardAvoidingView: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "KeyboardAvoidingView", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _components.KeyboardAvoidingView;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
require("./monkey-patch");
|
|
7
16
|
var _bindings = require("./bindings");
|
|
8
17
|
Object.keys(_bindings).forEach(function (key) {
|
|
9
18
|
if (key === "default" || key === "__esModule") return;
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
10
20
|
if (key in exports && exports[key] === _bindings[key]) return;
|
|
11
21
|
Object.defineProperty(exports, key, {
|
|
12
22
|
enumerable: true,
|
|
@@ -18,6 +28,7 @@ Object.keys(_bindings).forEach(function (key) {
|
|
|
18
28
|
var _animated = require("./animated");
|
|
19
29
|
Object.keys(_animated).forEach(function (key) {
|
|
20
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
21
32
|
if (key in exports && exports[key] === _animated[key]) return;
|
|
22
33
|
Object.defineProperty(exports, key, {
|
|
23
34
|
enumerable: true,
|
|
@@ -29,6 +40,7 @@ Object.keys(_animated).forEach(function (key) {
|
|
|
29
40
|
var _replicas = require("./replicas");
|
|
30
41
|
Object.keys(_replicas).forEach(function (key) {
|
|
31
42
|
if (key === "default" || key === "__esModule") return;
|
|
43
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
44
|
if (key in exports && exports[key] === _replicas[key]) return;
|
|
33
45
|
Object.defineProperty(exports, key, {
|
|
34
46
|
enumerable: true,
|
|
@@ -40,6 +52,7 @@ Object.keys(_replicas).forEach(function (key) {
|
|
|
40
52
|
var _context = require("./context");
|
|
41
53
|
Object.keys(_context).forEach(function (key) {
|
|
42
54
|
if (key === "default" || key === "__esModule") return;
|
|
55
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
43
56
|
if (key in exports && exports[key] === _context[key]) return;
|
|
44
57
|
Object.defineProperty(exports, key, {
|
|
45
58
|
enumerable: true,
|
|
@@ -51,6 +64,7 @@ Object.keys(_context).forEach(function (key) {
|
|
|
51
64
|
var _hooks = require("./hooks");
|
|
52
65
|
Object.keys(_hooks).forEach(function (key) {
|
|
53
66
|
if (key === "default" || key === "__esModule") return;
|
|
67
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
54
68
|
if (key in exports && exports[key] === _hooks[key]) return;
|
|
55
69
|
Object.defineProperty(exports, key, {
|
|
56
70
|
enumerable: true,
|
|
@@ -62,6 +76,7 @@ Object.keys(_hooks).forEach(function (key) {
|
|
|
62
76
|
var _constants = require("./constants");
|
|
63
77
|
Object.keys(_constants).forEach(function (key) {
|
|
64
78
|
if (key === "default" || key === "__esModule") return;
|
|
79
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
65
80
|
if (key in exports && exports[key] === _constants[key]) return;
|
|
66
81
|
Object.defineProperty(exports, key, {
|
|
67
82
|
enumerable: true,
|
|
@@ -73,6 +88,7 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
73
88
|
var _types = require("./types");
|
|
74
89
|
Object.keys(_types).forEach(function (key) {
|
|
75
90
|
if (key === "default" || key === "__esModule") return;
|
|
91
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
76
92
|
if (key in exports && exports[key] === _types[key]) return;
|
|
77
93
|
Object.defineProperty(exports, key, {
|
|
78
94
|
enumerable: true,
|
|
@@ -81,4 +97,5 @@ Object.keys(_types).forEach(function (key) {
|
|
|
81
97
|
}
|
|
82
98
|
});
|
|
83
99
|
});
|
|
100
|
+
var _components = require("./components");
|
|
84
101
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './bindings';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './constants';\nexport * from './types';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './bindings';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './constants';\nexport * from './types';\n\nexport { KeyboardAvoidingView } from './components';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n EmitterSubscription,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\n// DirectEventHandler events declaration\nexport type NativeEvent = {\n progress: number;\n height: number;\n duration: number;\n target: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveInteractive?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n duration: number;\n timestamp: number;\n target: number;\n};\nexport type KeyboardEventsModule = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => EmitterSubscription;\n};\n\n// reanimated hook declaration\nexport type KeyboardHandlerHook<TContext, Event> = (\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?:
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n EmitterSubscription,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\n// DirectEventHandler events declaration\nexport type NativeEvent = {\n progress: number;\n height: number;\n duration: number;\n target: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveInteractive?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n duration: number;\n timestamp: number;\n target: number;\n};\nexport type KeyboardEventsModule = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => EmitterSubscription;\n};\n\n// reanimated hook declaration\nexport type KeyboardHandlerHook<TContext, Event> = (\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?: unknown[]\n) => (e: NativeSyntheticEvent<Event>) => void;\n\n// package types\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (e: NativeEvent) => void;\n}>;\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
|
package/lib/module/animated.js
CHANGED
|
@@ -101,7 +101,7 @@ export const KeyboardProvider = _ref => {
|
|
|
101
101
|
onKeyboardMoveInteractive: onKeyboardMove,
|
|
102
102
|
navigationBarTranslucent: navigationBarTranslucent,
|
|
103
103
|
statusBarTranslucent: statusBarTranslucent
|
|
104
|
-
// @ts-expect-error
|
|
104
|
+
// @ts-expect-error https://github.com/software-mansion/react-native-reanimated/pull/4923
|
|
105
105
|
,
|
|
106
106
|
style: styles.container
|
|
107
107
|
}, children), /*#__PURE__*/React.createElement(Animated.View, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMemo","Animated","Platform","StyleSheet","Reanimated","useSharedValue","KeyboardContext","useSharedHandlers","useAnimatedValue","KeyboardControllerView","useAnimatedKeyboardHandler","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","progress","height","progressSV","heightSV","setHandlers","broadcast","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","OS","value","handler","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 { useSharedHandlers, useAnimatedValue } from './internal';\nimport { KeyboardControllerView } from './bindings';\nimport { useAnimatedKeyboardHandler } from './reanimated';\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 // @ts-expect-error
|
|
1
|
+
{"version":3,"names":["React","useMemo","Animated","Platform","StyleSheet","Reanimated","useSharedValue","KeyboardContext","useSharedHandlers","useAnimatedValue","KeyboardControllerView","useAnimatedKeyboardHandler","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","progress","height","progressSV","heightSV","setHandlers","broadcast","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","OS","value","handler","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 { useSharedHandlers, useAnimatedValue } from './internal';\nimport { KeyboardControllerView } from './bindings';\nimport { useAnimatedKeyboardHandler } from './reanimated';\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 // @ts-expect-error https://github.com/software-mansion/react-native-reanimated/pull/4923\n style={styles.container}\n >\n {children}\n </KeyboardControllerViewAnimated>\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 </KeyboardContext.Provider>\n );\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
2
|
+
import { useKeyboardHandler } from '../../hooks';
|
|
3
|
+
export const useKeyboardAnimation = () => {
|
|
4
|
+
const heightWhenOpened = useSharedValue(0);
|
|
5
|
+
const height = useSharedValue(0);
|
|
6
|
+
const progress = useSharedValue(0);
|
|
7
|
+
useKeyboardHandler({
|
|
8
|
+
onStart: e => {
|
|
9
|
+
'worklet';
|
|
10
|
+
|
|
11
|
+
if (e.height > 0) {
|
|
12
|
+
heightWhenOpened.value = e.height;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
onMove: e => {
|
|
16
|
+
'worklet';
|
|
17
|
+
|
|
18
|
+
progress.value = e.progress;
|
|
19
|
+
height.value = e.height;
|
|
20
|
+
}
|
|
21
|
+
}, []);
|
|
22
|
+
return {
|
|
23
|
+
height,
|
|
24
|
+
progress,
|
|
25
|
+
heightWhenOpened
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSharedValue","useKeyboardHandler","useKeyboardAnimation","heightWhenOpened","height","progress","onStart","e","value","onMove"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from 'react-native-reanimated';\nimport { useKeyboardHandler } from '../../hooks';\n\nexport const useKeyboardAnimation = () => {\n const heightWhenOpened = useSharedValue(0);\n const height = useSharedValue(0);\n const progress = useSharedValue(0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n if (e.height > 0) {\n heightWhenOpened.value = e.height;\n }\n },\n onMove: (e) => {\n 'worklet';\n\n progress.value = e.progress;\n height.value = e.height;\n },\n },\n []\n );\n\n return { height, progress, heightWhenOpened };\n};\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,yBAAyB;AACxD,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,OAAO,MAAMC,oBAAoB,GAAG,MAAM;EACxC,MAAMC,gBAAgB,GAAGH,cAAc,CAAC,CAAC,CAAC;EAC1C,MAAMI,MAAM,GAAGJ,cAAc,CAAC,CAAC,CAAC;EAChC,MAAMK,QAAQ,GAAGL,cAAc,CAAC,CAAC,CAAC;EAElCC,kBAAkB,CAChB;IACEK,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACH,MAAM,GAAG,CAAC,EAAE;QAChBD,gBAAgB,CAACK,KAAK,GAAGD,CAAC,CAACH,MAAM;MACnC;IACF,CAAC;IACDK,MAAM,EAAGF,CAAC,IAAK;MACb,SAAS;;MAETF,QAAQ,CAACG,KAAK,GAAGD,CAAC,CAACF,QAAQ;MAC3BD,MAAM,CAACI,KAAK,GAAGD,CAAC,CAACH,MAAM;IACzB;EACF,CAAC,EACD,EAAE,CACH;EAED,OAAO;IAAEA,MAAM;IAAEC,QAAQ;IAAEF;EAAiB,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import React, { forwardRef, useCallback, useMemo } from 'react';
|
|
3
|
+
import { useWindowDimensions, View } from 'react-native';
|
|
4
|
+
import Reanimated, { useAnimatedStyle, useWorkletCallback, useSharedValue, useDerivedValue, interpolate } from 'react-native-reanimated';
|
|
5
|
+
import { useKeyboardAnimation } from './hooks';
|
|
6
|
+
const defaultLayout = {
|
|
7
|
+
x: 0,
|
|
8
|
+
y: 0,
|
|
9
|
+
width: 0,
|
|
10
|
+
height: 0
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* View that moves out of the way when the keyboard appears by automatically
|
|
15
|
+
* adjusting its height, position, or bottom padding.
|
|
16
|
+
*/
|
|
17
|
+
const KeyboardAvoidingView = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
18
|
+
let {
|
|
19
|
+
behavior,
|
|
20
|
+
children,
|
|
21
|
+
contentContainerStyle,
|
|
22
|
+
enabled = true,
|
|
23
|
+
keyboardVerticalOffset = 0,
|
|
24
|
+
style,
|
|
25
|
+
onLayout: onLayoutProps,
|
|
26
|
+
...props
|
|
27
|
+
} = _ref;
|
|
28
|
+
const initialFrame = useSharedValue(null);
|
|
29
|
+
const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
|
|
30
|
+
const keyboard = useKeyboardAnimation();
|
|
31
|
+
const {
|
|
32
|
+
height: screenHeight
|
|
33
|
+
} = useWindowDimensions();
|
|
34
|
+
const relativeKeyboardHeight = useWorkletCallback(() => {
|
|
35
|
+
const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
|
|
36
|
+
return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
|
|
37
|
+
}, [screenHeight, keyboardVerticalOffset]);
|
|
38
|
+
const onLayout = useCallback(e => {
|
|
39
|
+
if (initialFrame.value === null) {
|
|
40
|
+
initialFrame.value = e.nativeEvent.layout;
|
|
41
|
+
}
|
|
42
|
+
onLayoutProps === null || onLayoutProps === void 0 ? void 0 : onLayoutProps(e);
|
|
43
|
+
}, [onLayoutProps]);
|
|
44
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
45
|
+
const bottom = interpolate(keyboard.progress.value, [0, 1], [0, relativeKeyboardHeight()]);
|
|
46
|
+
const bottomHeight = enabled ? bottom : 0;
|
|
47
|
+
switch (behavior) {
|
|
48
|
+
case 'height':
|
|
49
|
+
if (bottomHeight > 0) {
|
|
50
|
+
return {
|
|
51
|
+
height: frame.value.height - bottomHeight,
|
|
52
|
+
flex: 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {};
|
|
56
|
+
case 'position':
|
|
57
|
+
return {
|
|
58
|
+
bottom: bottomHeight
|
|
59
|
+
};
|
|
60
|
+
case 'padding':
|
|
61
|
+
return {
|
|
62
|
+
paddingBottom: bottomHeight
|
|
63
|
+
};
|
|
64
|
+
default:
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
}, [behavior, enabled, relativeKeyboardHeight]);
|
|
68
|
+
const isPositionBehavior = behavior === 'position';
|
|
69
|
+
const containerStyle = isPositionBehavior ? contentContainerStyle : style;
|
|
70
|
+
const combinedStyles = useMemo(() => [containerStyle, animatedStyle], [containerStyle, animatedStyle]);
|
|
71
|
+
if (isPositionBehavior) {
|
|
72
|
+
return /*#__PURE__*/React.createElement(View, _extends({
|
|
73
|
+
ref: ref,
|
|
74
|
+
style: style,
|
|
75
|
+
onLayout: onLayout
|
|
76
|
+
}, props), /*#__PURE__*/React.createElement(Reanimated.View, {
|
|
77
|
+
style: combinedStyles
|
|
78
|
+
}, children));
|
|
79
|
+
}
|
|
80
|
+
return /*#__PURE__*/React.createElement(Reanimated.View, _extends({
|
|
81
|
+
// @ts-expect-error because `ref` from reanimated is not compatible with react-native
|
|
82
|
+
ref: ref,
|
|
83
|
+
onLayout: onLayout,
|
|
84
|
+
style: combinedStyles
|
|
85
|
+
}, props), children);
|
|
86
|
+
});
|
|
87
|
+
export default KeyboardAvoidingView;
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useCallback","useMemo","useWindowDimensions","View","Reanimated","useAnimatedStyle","useWorkletCallback","useSharedValue","useDerivedValue","interpolate","useKeyboardAnimation","defaultLayout","x","y","width","height","KeyboardAvoidingView","ref","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","initialFrame","frame","value","keyboard","screenHeight","relativeKeyboardHeight","keyboardY","heightWhenOpened","Math","max","e","nativeEvent","layout","animatedStyle","bottom","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from 'react';\nimport {\n LayoutRectangle,\n useWindowDimensions,\n View,\n ViewProps,\n} from 'react-native';\nimport Reanimated, {\n useAnimatedStyle,\n useWorkletCallback,\n useSharedValue,\n useDerivedValue,\n interpolate,\n} from 'react-native-reanimated';\nimport { useKeyboardAnimation } from './hooks';\n\ntype Props = {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: 'height' | 'position' | 'padding';\n\n /**\n * Style of the content container when `behavior` is 'position'.\n */\n contentContainerStyle?: ViewProps['style'];\n\n /**\n * Controls whether this `KeyboardAvoidingView` instance should take effect.\n * This is useful when more than one is on the screen. Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * Distance between the top of the user screen and the React Native view. This\n * may be non-zero in some cases. Defaults to 0.\n */\n keyboardVerticalOffset?: number;\n} & ViewProps;\n\nconst defaultLayout: LayoutRectangle = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n};\n\n/**\n * View that moves out of the way when the keyboard appears by automatically\n * adjusting its height, position, or bottom padding.\n */\nconst KeyboardAvoidingView = forwardRef<View, React.PropsWithChildren<Props>>(\n (\n {\n behavior,\n children,\n contentContainerStyle,\n enabled = true,\n keyboardVerticalOffset = 0,\n style,\n onLayout: onLayoutProps,\n ...props\n },\n ref\n ) => {\n const initialFrame = useSharedValue<LayoutRectangle | null>(null);\n const frame = useDerivedValue(() => initialFrame.value || defaultLayout);\n\n const keyboard = useKeyboardAnimation();\n const { height: screenHeight } = useWindowDimensions();\n\n const relativeKeyboardHeight = useWorkletCallback(() => {\n const keyboardY =\n screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;\n\n return Math.max(frame.value.y + frame.value.height - keyboardY, 0);\n }, [screenHeight, keyboardVerticalOffset]);\n\n const onLayout = useCallback<NonNullable<ViewProps['onLayout']>>(\n (e) => {\n if (initialFrame.value === null) {\n initialFrame.value = e.nativeEvent.layout;\n }\n onLayoutProps?.(e);\n },\n [onLayoutProps]\n );\n\n const animatedStyle = useAnimatedStyle(() => {\n const bottom = interpolate(\n keyboard.progress.value,\n [0, 1],\n [0, relativeKeyboardHeight()]\n );\n const bottomHeight = enabled ? bottom : 0;\n\n switch (behavior) {\n case 'height':\n if (bottomHeight > 0) {\n return {\n height: frame.value.height - bottomHeight,\n flex: 0,\n };\n }\n\n return {};\n\n case 'position':\n return { bottom: bottomHeight };\n\n case 'padding':\n return { paddingBottom: bottomHeight };\n\n default:\n return {};\n }\n }, [behavior, enabled, relativeKeyboardHeight]);\n const isPositionBehavior = behavior === 'position';\n const containerStyle = isPositionBehavior ? contentContainerStyle : style;\n const combinedStyles = useMemo(\n () => [containerStyle, animatedStyle],\n [containerStyle, animatedStyle]\n );\n\n if (isPositionBehavior) {\n return (\n <View ref={ref} style={style} onLayout={onLayout} {...props}>\n <Reanimated.View style={combinedStyles}>{children}</Reanimated.View>\n </View>\n );\n }\n\n return (\n <Reanimated.View\n // @ts-expect-error because `ref` from reanimated is not compatible with react-native\n ref={ref}\n onLayout={onLayout}\n style={combinedStyles}\n {...props}\n >\n {children}\n </Reanimated.View>\n );\n }\n);\n\nexport default KeyboardAvoidingView;\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["default","KeyboardAvoidingView"],"sources":["index.ts"],"sourcesContent":["export { default as KeyboardAvoidingView } from './KeyboardAvoidingView';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,oBAAoB,QAAQ,wBAAwB"}
|
package/lib/module/context.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
import { Animated } from 'react-native';
|
|
3
|
+
const NOOP = () => {};
|
|
4
|
+
const DEFAULT_SHARED_VALUE = {
|
|
5
|
+
value: 0,
|
|
6
|
+
addListener: NOOP,
|
|
7
|
+
removeListener: NOOP,
|
|
8
|
+
modify: NOOP
|
|
9
|
+
};
|
|
3
10
|
const defaultContext = {
|
|
4
11
|
animated: {
|
|
5
12
|
progress: new Animated.Value(0),
|
|
6
13
|
height: new Animated.Value(0)
|
|
7
14
|
},
|
|
8
15
|
reanimated: {
|
|
9
|
-
progress:
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
height: {
|
|
13
|
-
value: 0
|
|
14
|
-
}
|
|
16
|
+
progress: DEFAULT_SHARED_VALUE,
|
|
17
|
+
height: DEFAULT_SHARED_VALUE
|
|
15
18
|
},
|
|
16
19
|
setHandlers: () => {}
|
|
17
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","Animated","defaultContext","animated","progress","Value","height","reanimated","
|
|
1
|
+
{"version":3,"names":["createContext","useContext","Animated","NOOP","DEFAULT_SHARED_VALUE","value","addListener","removeListener","modify","defaultContext","animated","progress","Value","height","reanimated","setHandlers","KeyboardContext","useKeyboardContext","context","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } 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 NOOP = () => {};\nconst DEFAULT_SHARED_VALUE: SharedValue<number> = {\n value: 0,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n};\nconst defaultContext: KeyboardAnimationContext = {\n animated: {\n progress: new Animated.Value(0),\n height: new Animated.Value(0),\n },\n reanimated: {\n progress: DEFAULT_SHARED_VALUE,\n height: DEFAULT_SHARED_VALUE,\n },\n setHandlers: () => {},\n};\nexport const KeyboardContext = createContext(defaultContext);\nexport const useKeyboardContext = () => {\n const context = useContext(KeyboardContext);\n\n if (__DEV__ && context === defaultContext) {\n console.warn(\n \"Couldn't find real values for `KeyboardContext`. Please make sure you're inside of `KeyboardProvider` - otherwise functionality of `react-native-keyboard-controller` will not work.\"\n );\n }\n\n return context;\n};\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjD,SAASC,QAAQ,QAAQ,cAAc;AAkBvC,MAAMC,IAAI,GAAG,MAAM,CAAC,CAAC;AACrB,MAAMC,oBAAyC,GAAG;EAChDC,KAAK,EAAE,CAAC;EACRC,WAAW,EAAEH,IAAI;EACjBI,cAAc,EAAEJ,IAAI;EACpBK,MAAM,EAAEL;AACV,CAAC;AACD,MAAMM,cAAwC,GAAG;EAC/CC,QAAQ,EAAE;IACRC,QAAQ,EAAE,IAAIT,QAAQ,CAACU,KAAK,CAAC,CAAC,CAAC;IAC/BC,MAAM,EAAE,IAAIX,QAAQ,CAACU,KAAK,CAAC,CAAC;EAC9B,CAAC;EACDE,UAAU,EAAE;IACVH,QAAQ,EAAEP,oBAAoB;IAC9BS,MAAM,EAAET;EACV,CAAC;EACDW,WAAW,EAAE,MAAM,CAAC;AACtB,CAAC;AACD,OAAO,MAAMC,eAAe,gBAAGhB,aAAa,CAACS,cAAc,CAAC;AAC5D,OAAO,MAAMQ,kBAAkB,GAAG,MAAM;EACtC,MAAMC,OAAO,GAAGjB,UAAU,CAACe,eAAe,CAAC;EAE3C,IAAIG,OAAO,IAAID,OAAO,KAAKT,cAAc,EAAE;IACzCW,OAAO,CAACC,IAAI,CACV,sLAAsL,CACvL;EACH;EAEA,OAAOH,OAAO;AAChB,CAAC"}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './bindings';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './constants';\nexport * from './types';\n"],"mappings":"AAAA,OAAO,gBAAgB;AAEvB,cAAc,YAAY;AAC1B,cAAc,YAAY;AAC1B,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,SAAS"}
|
|
1
|
+
{"version":3,"names":["KeyboardAvoidingView"],"sources":["index.ts"],"sourcesContent":["import './monkey-patch';\n\nexport * from './bindings';\nexport * from './animated';\nexport * from './replicas';\nexport * from './context';\nexport * from './hooks';\nexport * from './constants';\nexport * from './types';\n\nexport { KeyboardAvoidingView } from './components';\n"],"mappings":"AAAA,OAAO,gBAAgB;AAEvB,cAAc,YAAY;AAC1B,cAAc,YAAY;AAC1B,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,SAAS;AAEvB,SAASA,oBAAoB,QAAQ,cAAc"}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n EmitterSubscription,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\n// DirectEventHandler events declaration\nexport type NativeEvent = {\n progress: number;\n height: number;\n duration: number;\n target: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveInteractive?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n duration: number;\n timestamp: number;\n target: number;\n};\nexport type KeyboardEventsModule = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => EmitterSubscription;\n};\n\n// reanimated hook declaration\nexport type KeyboardHandlerHook<TContext, Event> = (\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?:
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n EmitterSubscription,\n NativeSyntheticEvent,\n ViewProps,\n} from 'react-native';\n\n// DirectEventHandler events declaration\nexport type NativeEvent = {\n progress: number;\n height: number;\n duration: number;\n target: number;\n};\nexport type EventWithName<T> = {\n eventName: string;\n} & T;\n\n// native View/Module declarations\nexport type KeyboardControllerProps = {\n onKeyboardMoveStart?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMove?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveEnd?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n onKeyboardMoveInteractive?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n // fake prop used to activate reanimated bindings\n onKeyboardMoveReanimated?: (\n e: NativeSyntheticEvent<EventWithName<NativeEvent>>\n ) => void;\n statusBarTranslucent?: boolean;\n navigationBarTranslucent?: boolean;\n} & ViewProps;\n\nexport type KeyboardGestureAreaProps = {\n interpolator: 'ios' | 'linear';\n /**\n * Whether to allow to show a keyboard from dismissed state by swipe up.\n * Default to `false`.\n */\n showOnSwipeUp?: boolean;\n /**\n * Whether to allow to control a keyboard by gestures. The strategy how\n * it should be controlled is determined by `interpolator` property.\n * Defaults to `true`.\n */\n enableSwipeToDismiss?: 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\nexport type KeyboardControllerEvents =\n | 'keyboardWillShow'\n | 'keyboardDidShow'\n | 'keyboardWillHide'\n | 'keyboardDidHide';\nexport type KeyboardEventData = {\n height: number;\n duration: number;\n timestamp: number;\n target: number;\n};\nexport type KeyboardEventsModule = {\n addListener: (\n name: KeyboardControllerEvents,\n cb: (e: KeyboardEventData) => void\n ) => EmitterSubscription;\n};\n\n// reanimated hook declaration\nexport type KeyboardHandlerHook<TContext, Event> = (\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?: unknown[]\n) => (e: NativeSyntheticEvent<Event>) => void;\n\n// package types\nexport type Handlers<T> = Record<string, T | undefined>;\nexport type KeyboardHandler = Partial<{\n onStart: (e: NativeEvent) => void;\n onMove: (e: NativeEvent) => void;\n onEnd: (e: NativeEvent) => void;\n onInteractive: (e: NativeEvent) => void;\n}>;\nexport type KeyboardHandlers = Handlers<KeyboardHandler>;\n"],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, ViewProps } from 'react-native';
|
|
3
|
+
/**
|
|
4
|
+
* View that moves out of the way when the keyboard appears by automatically
|
|
5
|
+
* adjusting its height, position, or bottom padding.
|
|
6
|
+
*/
|
|
7
|
+
declare const KeyboardAvoidingView: React.ForwardRefExoticComponent<{
|
|
8
|
+
/**
|
|
9
|
+
* Specify how to react to the presence of the keyboard.
|
|
10
|
+
*/
|
|
11
|
+
behavior?: "height" | "padding" | "position" | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Style of the content container when `behavior` is 'position'.
|
|
14
|
+
*/
|
|
15
|
+
contentContainerStyle?: ViewProps['style'];
|
|
16
|
+
/**
|
|
17
|
+
* Controls whether this `KeyboardAvoidingView` instance should take effect.
|
|
18
|
+
* This is useful when more than one is on the screen. Defaults to true.
|
|
19
|
+
*/
|
|
20
|
+
enabled?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Distance between the top of the user screen and the React Native view. This
|
|
23
|
+
* may be non-zero in some cases. Defaults to 0.
|
|
24
|
+
*/
|
|
25
|
+
keyboardVerticalOffset?: number | undefined;
|
|
26
|
+
} & ViewProps & {
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
} & React.RefAttributes<View>>;
|
|
29
|
+
export default KeyboardAvoidingView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as KeyboardAvoidingView } from './KeyboardAvoidingView';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react-native-reanimated" />
|
|
2
1
|
import { Animated } from 'react-native';
|
|
3
2
|
export declare const defaultAndroidEasing: import("react-native").EasingFunction;
|
|
4
3
|
type KeyboardAnimation = {
|
|
@@ -30,14 +29,10 @@ export declare const useKeyboardAnimationReplica: () => KeyboardAnimation;
|
|
|
30
29
|
*/
|
|
31
30
|
export declare const useReanimatedKeyboardAnimationReplica: () => {
|
|
32
31
|
height: import("react-native-reanimated").SharedValue<number>;
|
|
33
|
-
progress: Readonly<
|
|
34
|
-
value: number;
|
|
35
|
-
}>;
|
|
32
|
+
progress: Readonly<import("react-native-reanimated").SharedValue<number>>;
|
|
36
33
|
};
|
|
37
34
|
export declare const useGradualKeyboardAnimation: () => {
|
|
38
35
|
height: import("react-native-reanimated").SharedValue<number>;
|
|
39
|
-
progress: Readonly<
|
|
40
|
-
value: number;
|
|
41
|
-
}>;
|
|
36
|
+
progress: Readonly<import("react-native-reanimated").SharedValue<number>>;
|
|
42
37
|
};
|
|
43
38
|
export {};
|
|
@@ -52,7 +52,7 @@ export type KeyboardHandlerHook<TContext, Event> = (handlers: {
|
|
|
52
52
|
onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
|
|
53
53
|
onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;
|
|
54
54
|
onKeyboardMoveInteractive?: (e: NativeEvent, context: TContext) => void;
|
|
55
|
-
}, dependencies?:
|
|
55
|
+
}, dependencies?: unknown[]) => (e: NativeSyntheticEvent<Event>) => void;
|
|
56
56
|
export type Handlers<T> = Record<string, T | undefined>;
|
|
57
57
|
export type KeyboardHandler = Partial<{
|
|
58
58
|
onStart: (e: NativeEvent) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@commitlint/config-conventional": "^11.0.0",
|
|
59
|
-
"@react-native
|
|
59
|
+
"@react-native/eslint-config": "^0.72.2",
|
|
60
60
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
61
61
|
"@types/jest": "^29.2.1",
|
|
62
62
|
"@types/react": "^18.0.24",
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"pod-install": "^0.1.0",
|
|
71
71
|
"prettier": "^2.4.1",
|
|
72
72
|
"react": "18.2.0",
|
|
73
|
-
"react-native": "0.
|
|
73
|
+
"react-native": "0.72.4",
|
|
74
74
|
"react-native-builder-bob": "^0.18.0",
|
|
75
|
-
"react-native-reanimated": "
|
|
75
|
+
"react-native-reanimated": "3.4.2",
|
|
76
76
|
"release-it": "^14.2.2",
|
|
77
77
|
"typescript": "^4.8.4"
|
|
78
78
|
},
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"eslintConfig": {
|
|
114
114
|
"root": true,
|
|
115
115
|
"extends": [
|
|
116
|
-
"@react-native
|
|
116
|
+
"@react-native",
|
|
117
117
|
"prettier"
|
|
118
118
|
],
|
|
119
119
|
"rules": {
|
package/src/animated.tsx
CHANGED
|
@@ -146,7 +146,7 @@ export const KeyboardProvider = ({
|
|
|
146
146
|
onKeyboardMoveInteractive={onKeyboardMove}
|
|
147
147
|
navigationBarTranslucent={navigationBarTranslucent}
|
|
148
148
|
statusBarTranslucent={statusBarTranslucent}
|
|
149
|
-
// @ts-expect-error
|
|
149
|
+
// @ts-expect-error https://github.com/software-mansion/react-native-reanimated/pull/4923
|
|
150
150
|
style={styles.container}
|
|
151
151
|
>
|
|
152
152
|
{children}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
2
|
+
import { useKeyboardHandler } from '../../hooks';
|
|
3
|
+
|
|
4
|
+
export const useKeyboardAnimation = () => {
|
|
5
|
+
const heightWhenOpened = useSharedValue(0);
|
|
6
|
+
const height = useSharedValue(0);
|
|
7
|
+
const progress = useSharedValue(0);
|
|
8
|
+
|
|
9
|
+
useKeyboardHandler(
|
|
10
|
+
{
|
|
11
|
+
onStart: (e) => {
|
|
12
|
+
'worklet';
|
|
13
|
+
|
|
14
|
+
if (e.height > 0) {
|
|
15
|
+
heightWhenOpened.value = e.height;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
onMove: (e) => {
|
|
19
|
+
'worklet';
|
|
20
|
+
|
|
21
|
+
progress.value = e.progress;
|
|
22
|
+
height.value = e.height;
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
[]
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return { height, progress, heightWhenOpened };
|
|
29
|
+
};
|