react-native-keyboard-controller 1.14.2 → 1.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/OverKeyboardViewGroup.kt +1 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/RootViewCompat.kt +18 -0
- package/lib/commonjs/animated.js +10 -2
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +9 -4
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/context.js +3 -1
- package/lib/commonjs/context.js.map +1 -1
- package/lib/module/animated.js +10 -2
- package/lib/module/animated.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js +9 -4
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/context.js +3 -1
- package/lib/module/context.js.map +1 -1
- package/package.json +5 -2
- package/src/animated.tsx +12 -2
- package/src/components/KeyboardAvoidingView/hooks.ts +10 -4
- package/src/context.ts +2 -0
|
@@ -10,7 +10,6 @@ import com.facebook.react.bridge.UiThreadUtil
|
|
|
10
10
|
import com.facebook.react.config.ReactFeatureFlags
|
|
11
11
|
import com.facebook.react.uimanager.JSPointerDispatcher
|
|
12
12
|
import com.facebook.react.uimanager.JSTouchDispatcher
|
|
13
|
-
import com.facebook.react.uimanager.RootView
|
|
14
13
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
15
14
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
16
15
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
@@ -98,7 +97,7 @@ class OverKeyboardHostView(
|
|
|
98
97
|
class OverKeyboardRootViewGroup(
|
|
99
98
|
private val reactContext: ThemedReactContext,
|
|
100
99
|
) : ReactViewGroup(reactContext),
|
|
101
|
-
|
|
100
|
+
RootViewCompat {
|
|
102
101
|
private val jsTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
|
|
103
102
|
private var jsPointerDispatcher: JSPointerDispatcher? = null
|
|
104
103
|
internal var eventDispatcher: EventDispatcher? = null
|
package/android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/RootViewCompat.kt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.reactnativekeyboardcontroller.views.overlay
|
|
2
|
+
|
|
3
|
+
import android.view.MotionEvent
|
|
4
|
+
import com.facebook.react.uimanager.RootView
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Compat layer for `RootView` interface for RN < 0.73
|
|
8
|
+
* which has a default implementation of deprecated method.
|
|
9
|
+
*/
|
|
10
|
+
interface RootViewCompat : RootView {
|
|
11
|
+
@Deprecated(
|
|
12
|
+
"This method shouldn't be used anymore.",
|
|
13
|
+
ReplaceWith("onChildStartedNativeGesture(View childView, MotionEvent ev)"),
|
|
14
|
+
)
|
|
15
|
+
override fun onChildStartedNativeGesture(ev: MotionEvent?) {
|
|
16
|
+
onChildStartedNativeGesture(null, ev)
|
|
17
|
+
}
|
|
18
|
+
}
|
package/lib/commonjs/animated.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.KeyboardProvider = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeIsEdgeToEdge = require("react-native-is-edge-to-edge");
|
|
9
10
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
10
11
|
var _bindings = require("./bindings");
|
|
11
12
|
var _context = require("./context");
|
|
@@ -17,6 +18,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
17
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
19
|
/* eslint react/jsx-sort-props: off */
|
|
19
20
|
|
|
21
|
+
const IS_EDGE_TO_EDGE = (0, _reactNativeIsEdgeToEdge.isEdgeToEdge)();
|
|
20
22
|
const KeyboardControllerViewAnimated = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.Animated.createAnimatedComponent(_bindings.KeyboardControllerView));
|
|
21
23
|
const styles = _reactNative.StyleSheet.create({
|
|
22
24
|
container: {
|
|
@@ -127,13 +129,19 @@ const KeyboardProvider = ({
|
|
|
127
129
|
(0, _monkeyPatch.revertMonkeyPatch)();
|
|
128
130
|
}
|
|
129
131
|
}, [enabled]);
|
|
132
|
+
if (__DEV__) {
|
|
133
|
+
(0, _reactNativeIsEdgeToEdge.controlEdgeToEdgeValues)({
|
|
134
|
+
statusBarTranslucent,
|
|
135
|
+
navigationBarTranslucent
|
|
136
|
+
});
|
|
137
|
+
}
|
|
130
138
|
return /*#__PURE__*/_react.default.createElement(_context.KeyboardContext.Provider, {
|
|
131
139
|
value: context
|
|
132
140
|
}, /*#__PURE__*/_react.default.createElement(KeyboardControllerViewAnimated, {
|
|
133
141
|
ref: viewTagRef,
|
|
134
142
|
enabled: enabled,
|
|
135
|
-
navigationBarTranslucent: navigationBarTranslucent,
|
|
136
|
-
statusBarTranslucent: statusBarTranslucent,
|
|
143
|
+
navigationBarTranslucent: IS_EDGE_TO_EDGE || navigationBarTranslucent,
|
|
144
|
+
statusBarTranslucent: IS_EDGE_TO_EDGE || statusBarTranslucent,
|
|
137
145
|
style: styles.container
|
|
138
146
|
// on*Reanimated prop must precede animated handlers to work correctly
|
|
139
147
|
,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_bindings","_context","_eventMappings","_internal","_monkeyPatch","_reanimated","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","OS","Platform","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","enabled","initiallyEnabled","viewTagRef","useRef","setEnabled","useState","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","layout","setKeyboardHandlers","useEventHandlerRegistration","keyboardEventsMap","setInputHandlers","focusedInputEventsMap","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","value","keyboardHandler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveInteractive","inputLayoutHandler","useFocusedInputLayoutHandler","onFocusedInputLayoutChanged","target","useEffect","applyMonkeyPatch","revertMonkeyPatch","createElement","KeyboardContext","Provider","ref","onKeyboardMoveReanimated","undefined","onFocusedInputLayoutChangedReanimated","View","exports"],"sources":["animated.tsx"],"sourcesContent":["/* eslint react/jsx-sort-props: off */\nimport React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Animated, Platform, StyleSheet } from \"react-native\";\nimport Reanimated, { useSharedValue } from \"react-native-reanimated\";\n\nimport { KeyboardControllerView } from \"./bindings\";\nimport { KeyboardContext } from \"./context\";\nimport { focusedInputEventsMap, keyboardEventsMap } from \"./event-mappings\";\nimport { useAnimatedValue, useEventHandlerRegistration } from \"./internal\";\nimport { applyMonkeyPatch, revertMonkeyPatch } from \"./monkey-patch\";\nimport {\n useAnimatedKeyboardHandler,\n useFocusedInputLayoutHandler,\n} from \"./reanimated\";\n\nimport type { KeyboardAnimationContext } from \"./context\";\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(KeyboardControllerView),\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 * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\n// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package\n// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details\nconst OS = Platform.OS;\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n // ref\n const viewTagRef = useRef<React.Component<KeyboardControllerProps>>(null);\n // state\n const [enabled, setEnabled] = useState(initiallyEnabled);\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 layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(\n keyboardEventsMap,\n viewTagRef,\n );\n const setInputHandlers = useEventHandlerRegistration<FocusedInputHandler>(\n focusedInputEventsMap,\n viewTagRef,\n );\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n layout,\n setKeyboardHandlers,\n setInputHandlers,\n setEnabled,\n }),\n [enabled],\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(OS)) {\n // eslint-disable-next-line react-compiler/react-compiler\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const keyboardHandler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"ios\"]);\n },\n onKeyboardMove: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\"]);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\", \"ios\"]);\n },\n },\n [],\n );\n const inputLayoutHandler = useFocusedInputLayoutHandler(\n {\n onFocusedInputLayoutChanged: (e) => {\n \"worklet\";\n\n if (e.target !== -1) {\n layout.value = e;\n } else {\n layout.value = null;\n }\n },\n },\n [],\n );\n\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n ref={viewTagRef}\n enabled={enabled}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n // on*Reanimated prop must precede animated handlers to work correctly\n onKeyboardMoveReanimated={keyboardHandler}\n onKeyboardMoveStart={OS === \"ios\" ? onKeyboardMove : undefined}\n onKeyboardMove={OS === \"android\" ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n onFocusedInputLayoutChangedReanimated={inputLayoutHandler}\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":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAGsB,SAAAS,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAA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B,EAAC,CAAC;IACpB,CAAC,MAAM;MACL,IAAAC,8BAAiB,EAAC,CAAC;IACrB;EACF,CAAC,EAAE,CAAC7C,OAAO,CAAC,CAAC;EAEb,oBACElD,MAAA,CAAAiB,OAAA,CAAA+E,aAAA,CAAC1F,QAAA,CAAA2F,eAAe,CAACC,QAAQ;IAACd,KAAK,EAAEhB;EAAQ,gBACvCpE,MAAA,CAAAiB,OAAA,CAAA+E,aAAA,CAACjE,8BAA8B;IAC7BoE,GAAG,EAAE/C,UAAW;IAChBF,OAAO,EAAEA,OAAQ;IACjBD,wBAAwB,EAAEA,wBAAyB;IACnDD,oBAAoB,EAAEA,oBAAqB;IAC3CyB,KAAK,EAAErC,MAAM,CAACG;IACd;IAAA;IACA6D,wBAAwB,EAAEf,eAAgB;IAC1CE,mBAAmB,EAAE3C,EAAE,KAAK,KAAK,GAAGiC,cAAc,GAAGwB,SAAU;IAC/DxB,cAAc,EAAEjC,EAAE,KAAK,SAAS,GAAGiC,cAAc,GAAGwB,SAAU;IAC9Db,yBAAyB,EAAEX,cAAe;IAC1CyB,qCAAqC,EAAEb;EAAmB,GAEzD1C,QAC6B,CAAC,eACjC/C,MAAA,CAAAiB,OAAA,CAAA+E,aAAA,CAAC7F,YAAA,CAAA+B,QAAQ,CAACqE,IAAI;IACZ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA9B,KAAK,EAAEA;EAAM,CACd,CACuB,CAAC;AAE/B,CAAC;AAAC+B,OAAA,CAAA1D,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeIsEdgeToEdge","_reactNativeReanimated","_bindings","_context","_eventMappings","_internal","_monkeyPatch","_reanimated","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","IS_EDGE_TO_EDGE","isEdgeToEdge","KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","OS","Platform","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","enabled","initiallyEnabled","viewTagRef","useRef","setEnabled","useState","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","layout","setKeyboardHandlers","useEventHandlerRegistration","keyboardEventsMap","setInputHandlers","focusedInputEventsMap","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","value","keyboardHandler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveInteractive","inputLayoutHandler","useFocusedInputLayoutHandler","onFocusedInputLayoutChanged","target","useEffect","applyMonkeyPatch","revertMonkeyPatch","__DEV__","controlEdgeToEdgeValues","createElement","KeyboardContext","Provider","ref","onKeyboardMoveReanimated","undefined","onFocusedInputLayoutChangedReanimated","View","exports"],"sources":["animated.tsx"],"sourcesContent":["/* eslint react/jsx-sort-props: off */\nimport React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Animated, Platform, StyleSheet } from \"react-native\";\nimport {\n controlEdgeToEdgeValues,\n isEdgeToEdge,\n} from \"react-native-is-edge-to-edge\";\nimport Reanimated, { useSharedValue } from \"react-native-reanimated\";\n\nimport { KeyboardControllerView } from \"./bindings\";\nimport { KeyboardContext } from \"./context\";\nimport { focusedInputEventsMap, keyboardEventsMap } from \"./event-mappings\";\nimport { useAnimatedValue, useEventHandlerRegistration } from \"./internal\";\nimport { applyMonkeyPatch, revertMonkeyPatch } from \"./monkey-patch\";\nimport {\n useAnimatedKeyboardHandler,\n useFocusedInputLayoutHandler,\n} from \"./reanimated\";\n\nimport type { KeyboardAnimationContext } from \"./context\";\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\nconst IS_EDGE_TO_EDGE = isEdgeToEdge();\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(KeyboardControllerView),\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 * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\n// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package\n// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details\nconst OS = Platform.OS;\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n // ref\n const viewTagRef = useRef<React.Component<KeyboardControllerProps>>(null);\n // state\n const [enabled, setEnabled] = useState(initiallyEnabled);\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 layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(\n keyboardEventsMap,\n viewTagRef,\n );\n const setInputHandlers = useEventHandlerRegistration<FocusedInputHandler>(\n focusedInputEventsMap,\n viewTagRef,\n );\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n layout,\n setKeyboardHandlers,\n setInputHandlers,\n setEnabled,\n }),\n [enabled],\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(OS)) {\n // eslint-disable-next-line react-compiler/react-compiler\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const keyboardHandler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"ios\"]);\n },\n onKeyboardMove: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\"]);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\", \"ios\"]);\n },\n },\n [],\n );\n const inputLayoutHandler = useFocusedInputLayoutHandler(\n {\n onFocusedInputLayoutChanged: (e) => {\n \"worklet\";\n\n if (e.target !== -1) {\n layout.value = e;\n } else {\n layout.value = null;\n }\n },\n },\n [],\n );\n\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n if (__DEV__) {\n controlEdgeToEdgeValues({ statusBarTranslucent, navigationBarTranslucent });\n }\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n ref={viewTagRef}\n enabled={enabled}\n navigationBarTranslucent={IS_EDGE_TO_EDGE || navigationBarTranslucent}\n statusBarTranslucent={IS_EDGE_TO_EDGE || statusBarTranslucent}\n style={styles.container}\n // on*Reanimated prop must precede animated handlers to work correctly\n onKeyboardMoveReanimated={keyboardHandler}\n onKeyboardMoveStart={OS === \"ios\" ? onKeyboardMove : undefined}\n onKeyboardMove={OS === \"android\" ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n onFocusedInputLayoutChangedReanimated={inputLayoutHandler}\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":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF,OAAA;AAIA,IAAAG,sBAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAEA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAGsB,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAZ,wBAAAY,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SA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7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useKeyboardAnimation = void 0;
|
|
7
|
+
var _react = require("react");
|
|
7
8
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
8
9
|
var _context = require("../../context");
|
|
9
10
|
var _hooks = require("../../hooks");
|
|
@@ -11,10 +12,14 @@ const useKeyboardAnimation = () => {
|
|
|
11
12
|
const {
|
|
12
13
|
reanimated
|
|
13
14
|
} = (0, _context.useKeyboardContext)();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
|
|
16
|
+
// calculate it only once on mount, to avoid `SharedValue` reads during a render
|
|
17
|
+
const [initialHeight] = (0, _react.useState)(() => -reanimated.height.value);
|
|
18
|
+
const [initialProgress] = (0, _react.useState)(() => reanimated.progress.value);
|
|
19
|
+
const heightWhenOpened = (0, _reactNativeReanimated.useSharedValue)(initialHeight);
|
|
20
|
+
const height = (0, _reactNativeReanimated.useSharedValue)(initialHeight);
|
|
21
|
+
const progress = (0, _reactNativeReanimated.useSharedValue)(initialProgress);
|
|
22
|
+
const isClosed = (0, _reactNativeReanimated.useSharedValue)(initialProgress === 0);
|
|
18
23
|
(0, _hooks.useKeyboardHandler)({
|
|
19
24
|
onStart: e => {
|
|
20
25
|
"worklet";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNativeReanimated","_context","_hooks","useKeyboardAnimation","reanimated","useKeyboardContext","initialHeight","useState","height","value","initialProgress","progress","heightWhenOpened","useSharedValue","isClosed","useKeyboardHandler","onStart","e","onMove","onInteractive","onEnd","exports"],"sources":["hooks.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardContext } from \"../../context\";\nimport { useKeyboardHandler } from \"../../hooks\";\n\nexport const useKeyboardAnimation = () => {\n const { reanimated } = useKeyboardContext();\n\n // calculate it only once on mount, to avoid `SharedValue` reads during a render\n const [initialHeight] = useState(() => -reanimated.height.value);\n const [initialProgress] = useState(() => reanimated.progress.value);\n\n const heightWhenOpened = useSharedValue(initialHeight);\n const height = useSharedValue(initialHeight);\n const progress = useSharedValue(initialProgress);\n const isClosed = useSharedValue(initialProgress === 0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n isClosed.value = false;\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 onInteractive: (e) => {\n \"worklet\";\n\n progress.value = e.progress;\n height.value = e.height;\n },\n onEnd: (e) => {\n \"worklet\";\n\n isClosed.value = e.height === 0;\n\n height.value = e.height;\n progress.value = e.progress;\n },\n },\n [],\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAAC,2BAAkB,EAAC,CAAC;;EAE3C;EACA,MAAM,CAACC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM,CAACH,UAAU,CAACI,MAAM,CAACC,KAAK,CAAC;EAChE,MAAM,CAACC,eAAe,CAAC,GAAG,IAAAH,eAAQ,EAAC,MAAMH,UAAU,CAACO,QAAQ,CAACF,KAAK,CAAC;EAEnE,MAAMG,gBAAgB,GAAG,IAAAC,qCAAc,EAACP,aAAa,CAAC;EACtD,MAAME,MAAM,GAAG,IAAAK,qCAAc,EAACP,aAAa,CAAC;EAC5C,MAAMK,QAAQ,GAAG,IAAAE,qCAAc,EAACH,eAAe,CAAC;EAChD,MAAMI,QAAQ,GAAG,IAAAD,qCAAc,EAACH,eAAe,KAAK,CAAC,CAAC;EAEtD,IAAAK,yBAAkB,EAChB;IACEC,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACT,MAAM,GAAG,CAAC,EAAE;QAChB;QACAM,QAAQ,CAACL,KAAK,GAAG,KAAK;QACtBG,gBAAgB,CAACH,KAAK,GAAGQ,CAAC,CAACT,MAAM;MACnC;IACF,CAAC;IACDU,MAAM,EAAGD,CAAC,IAAK;MACb,SAAS;;MAETN,QAAQ,CAACF,KAAK,GAAGQ,CAAC,CAACN,QAAQ;MAC3BH,MAAM,CAACC,KAAK,GAAGQ,CAAC,CAACT,MAAM;IACzB,CAAC;IACDW,aAAa,EAAGF,CAAC,IAAK;MACpB,SAAS;;MAETN,QAAQ,CAACF,KAAK,GAAGQ,CAAC,CAACN,QAAQ;MAC3BH,MAAM,CAACC,KAAK,GAAGQ,CAAC,CAACT,MAAM;IACzB,CAAC;IACDY,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETH,QAAQ,CAACL,KAAK,GAAGQ,CAAC,CAACT,MAAM,KAAK,CAAC;MAE/BA,MAAM,CAACC,KAAK,GAAGQ,CAAC,CAACT,MAAM;MACvBG,QAAQ,CAACF,KAAK,GAAGQ,CAAC,CAACN,QAAQ;IAC7B;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEH,MAAM;IAAEG,QAAQ;IAAEC,gBAAgB;IAAEE;EAAS,CAAC;AACzD,CAAC;AAACO,OAAA,CAAAlB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
package/lib/commonjs/context.js
CHANGED
|
@@ -12,7 +12,9 @@ const withSharedValue = value => ({
|
|
|
12
12
|
value,
|
|
13
13
|
addListener: NOOP,
|
|
14
14
|
removeListener: NOOP,
|
|
15
|
-
modify: NOOP
|
|
15
|
+
modify: NOOP,
|
|
16
|
+
get: () => value,
|
|
17
|
+
set: NOOP
|
|
16
18
|
});
|
|
17
19
|
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
18
20
|
const DEFAULT_LAYOUT = withSharedValue(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","NOOP","NESTED_NOOP","withSharedValue","value","addListener","removeListener","modify","DEFAULT_SHARED_VALUE","DEFAULT_LAYOUT","defaultContext","enabled","animated","progress","Animated","Value","height","reanimated","layout","setKeyboardHandlers","setInputHandlers","setEnabled","KeyboardContext","exports","createContext","useKeyboardContext","context","useContext","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { Animated } from \"react-native\";\n\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardHandler,\n} from \"./types\";\nimport type React from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\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 enabled: boolean;\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n layout: SharedValue<FocusedInputLayoutChangedEvent | null>;\n setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;\n setInputHandlers: (handlers: FocusedInputHandler) => () => void;\n setEnabled: React.Dispatch<React.SetStateAction<boolean>>;\n};\nconst NOOP = () => {};\nconst NESTED_NOOP = () => NOOP;\nconst withSharedValue = <T>(value: T): SharedValue<T> => ({\n value,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n});\nconst DEFAULT_SHARED_VALUE = withSharedValue(0);\nconst DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(\n null,\n);\nconst defaultContext: KeyboardAnimationContext = {\n enabled: true,\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 layout: DEFAULT_LAYOUT,\n setKeyboardHandlers: NESTED_NOOP,\n setInputHandlers: NESTED_NOOP,\n setEnabled: NOOP,\n};\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,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AA2BA,MAAME,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,WAAW,GAAGA,CAAA,KAAMD,IAAI;AAC9B,MAAME,eAAe,GAAOC,KAAQ,KAAsB;EACxDA,KAAK;EACLC,WAAW,EAAEJ,IAAI;EACjBK,cAAc,EAAEL,IAAI;EACpBM,MAAM,EAAEN;
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","NOOP","NESTED_NOOP","withSharedValue","value","addListener","removeListener","modify","get","set","DEFAULT_SHARED_VALUE","DEFAULT_LAYOUT","defaultContext","enabled","animated","progress","Animated","Value","height","reanimated","layout","setKeyboardHandlers","setInputHandlers","setEnabled","KeyboardContext","exports","createContext","useKeyboardContext","context","useContext","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { Animated } from \"react-native\";\n\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardHandler,\n} from \"./types\";\nimport type React from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\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 enabled: boolean;\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n layout: SharedValue<FocusedInputLayoutChangedEvent | null>;\n setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;\n setInputHandlers: (handlers: FocusedInputHandler) => () => void;\n setEnabled: React.Dispatch<React.SetStateAction<boolean>>;\n};\nconst NOOP = () => {};\nconst NESTED_NOOP = () => NOOP;\nconst withSharedValue = <T>(value: T): SharedValue<T> => ({\n value,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n get: () => value,\n set: NOOP,\n});\nconst DEFAULT_SHARED_VALUE = withSharedValue(0);\nconst DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(\n null,\n);\nconst defaultContext: KeyboardAnimationContext = {\n enabled: true,\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 layout: DEFAULT_LAYOUT,\n setKeyboardHandlers: NESTED_NOOP,\n setInputHandlers: NESTED_NOOP,\n setEnabled: NOOP,\n};\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,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AA2BA,MAAME,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,WAAW,GAAGA,CAAA,KAAMD,IAAI;AAC9B,MAAME,eAAe,GAAOC,KAAQ,KAAsB;EACxDA,KAAK;EACLC,WAAW,EAAEJ,IAAI;EACjBK,cAAc,EAAEL,IAAI;EACpBM,MAAM,EAAEN,IAAI;EACZO,GAAG,EAAEA,CAAA,KAAMJ,KAAK;EAChBK,GAAG,EAAER;AACP,CAAC,CAAC;AACF,MAAMS,oBAAoB,GAAGP,eAAe,CAAC,CAAC,CAAC;AAC/C,MAAMQ,cAAc,GAAGR,eAAe,CACpC,IACF,CAAC;AACD,MAAMS,cAAwC,GAAG;EAC/CC,OAAO,EAAE,IAAI;EACbC,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,EAAEL,oBAAoB;IAC9BQ,MAAM,EAAER;EACV,CAAC;EACDU,MAAM,EAAET,cAAc;EACtBU,mBAAmB,EAAEnB,WAAW;EAChCoB,gBAAgB,EAAEpB,WAAW;EAC7BqB,UAAU,EAAEtB;AACd,CAAC;AAEM,MAAMuB,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAG,IAAAE,oBAAa,EAACd,cAAc,CAAC;AACrD,MAAMe,kBAAkB,GAAGA,CAAA,KAAM;EACtC,MAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACL,eAAe,CAAC;EAE3C,IAAIM,OAAO,IAAIF,OAAO,KAAKhB,cAAc,EAAE;IACzCmB,OAAO,CAACC,IAAI,CACV,sLACF,CAAC;EACH;EAEA,OAAOJ,OAAO;AAChB,CAAC;AAACH,OAAA,CAAAE,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/lib/module/animated.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint react/jsx-sort-props: off */
|
|
2
2
|
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Animated, Platform, StyleSheet } from "react-native";
|
|
4
|
+
import { controlEdgeToEdgeValues, isEdgeToEdge } from "react-native-is-edge-to-edge";
|
|
4
5
|
import Reanimated, { useSharedValue } from "react-native-reanimated";
|
|
5
6
|
import { KeyboardControllerView } from "./bindings";
|
|
6
7
|
import { KeyboardContext } from "./context";
|
|
@@ -8,6 +9,7 @@ import { focusedInputEventsMap, keyboardEventsMap } from "./event-mappings";
|
|
|
8
9
|
import { useAnimatedValue, useEventHandlerRegistration } from "./internal";
|
|
9
10
|
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
|
|
10
11
|
import { useAnimatedKeyboardHandler, useFocusedInputLayoutHandler } from "./reanimated";
|
|
12
|
+
const IS_EDGE_TO_EDGE = isEdgeToEdge();
|
|
11
13
|
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(Animated.createAnimatedComponent(KeyboardControllerView));
|
|
12
14
|
const styles = StyleSheet.create({
|
|
13
15
|
container: {
|
|
@@ -118,13 +120,19 @@ export const KeyboardProvider = ({
|
|
|
118
120
|
revertMonkeyPatch();
|
|
119
121
|
}
|
|
120
122
|
}, [enabled]);
|
|
123
|
+
if (__DEV__) {
|
|
124
|
+
controlEdgeToEdgeValues({
|
|
125
|
+
statusBarTranslucent,
|
|
126
|
+
navigationBarTranslucent
|
|
127
|
+
});
|
|
128
|
+
}
|
|
121
129
|
return /*#__PURE__*/React.createElement(KeyboardContext.Provider, {
|
|
122
130
|
value: context
|
|
123
131
|
}, /*#__PURE__*/React.createElement(KeyboardControllerViewAnimated, {
|
|
124
132
|
ref: viewTagRef,
|
|
125
133
|
enabled: enabled,
|
|
126
|
-
navigationBarTranslucent: navigationBarTranslucent,
|
|
127
|
-
statusBarTranslucent: statusBarTranslucent,
|
|
134
|
+
navigationBarTranslucent: IS_EDGE_TO_EDGE || navigationBarTranslucent,
|
|
135
|
+
statusBarTranslucent: IS_EDGE_TO_EDGE || statusBarTranslucent,
|
|
128
136
|
style: styles.container
|
|
129
137
|
// on*Reanimated prop must precede animated handlers to work correctly
|
|
130
138
|
,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","useMemo","useRef","useState","Animated","Platform","StyleSheet","Reanimated","useSharedValue","KeyboardControllerView","KeyboardContext","focusedInputEventsMap","keyboardEventsMap","useAnimatedValue","useEventHandlerRegistration","applyMonkeyPatch","revertMonkeyPatch","useAnimatedKeyboardHandler","useFocusedInputLayoutHandler","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","OS","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","enabled","initiallyEnabled","viewTagRef","setEnabled","progress","height","progressSV","heightSV","layout","setKeyboardHandlers","setInputHandlers","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","value","keyboardHandler","onKeyboardMoveStart","onKeyboardMoveInteractive","inputLayoutHandler","onFocusedInputLayoutChanged","e","target","createElement","Provider","ref","onKeyboardMoveReanimated","undefined","onFocusedInputLayoutChangedReanimated","View"],"sources":["animated.tsx"],"sourcesContent":["/* eslint react/jsx-sort-props: off */\nimport React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Animated, Platform, StyleSheet } from \"react-native\";\nimport Reanimated, { useSharedValue } from \"react-native-reanimated\";\n\nimport { KeyboardControllerView } from \"./bindings\";\nimport { KeyboardContext } from \"./context\";\nimport { focusedInputEventsMap, keyboardEventsMap } from \"./event-mappings\";\nimport { useAnimatedValue, useEventHandlerRegistration } from \"./internal\";\nimport { applyMonkeyPatch, revertMonkeyPatch } from \"./monkey-patch\";\nimport {\n useAnimatedKeyboardHandler,\n useFocusedInputLayoutHandler,\n} from \"./reanimated\";\n\nimport type { KeyboardAnimationContext } from \"./context\";\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(KeyboardControllerView),\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 * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\n// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package\n// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details\nconst OS = Platform.OS;\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n // ref\n const viewTagRef = useRef<React.Component<KeyboardControllerProps>>(null);\n // state\n const [enabled, setEnabled] = useState(initiallyEnabled);\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 layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(\n keyboardEventsMap,\n viewTagRef,\n );\n const setInputHandlers = useEventHandlerRegistration<FocusedInputHandler>(\n focusedInputEventsMap,\n viewTagRef,\n );\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n layout,\n setKeyboardHandlers,\n setInputHandlers,\n setEnabled,\n }),\n [enabled],\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(OS)) {\n // eslint-disable-next-line react-compiler/react-compiler\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const keyboardHandler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"ios\"]);\n },\n onKeyboardMove: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\"]);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\", \"ios\"]);\n },\n },\n [],\n );\n const inputLayoutHandler = useFocusedInputLayoutHandler(\n {\n onFocusedInputLayoutChanged: (e) => {\n \"worklet\";\n\n if (e.target !== -1) {\n layout.value = e;\n } else {\n layout.value = null;\n }\n },\n },\n [],\n );\n\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n ref={viewTagRef}\n enabled={enabled}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n style={styles.container}\n // on*Reanimated prop must precede animated handlers to work correctly\n onKeyboardMoveReanimated={keyboardHandler}\n onKeyboardMoveStart={OS === \"ios\" ? onKeyboardMove : undefined}\n onKeyboardMove={OS === \"android\" ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n onFocusedInputLayoutChangedReanimated={inputLayoutHandler}\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":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnE,SAASC,QAAQ,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AAC7D,OAAOC,UAAU,IAAIC,cAAc,QAAQ,yBAAyB;AAEpE,SAASC,sBAAsB,QAAQ,YAAY;AACnD,SAASC,eAAe,QAAQ,WAAW;AAC3C,SAASC,qBAAqB,EAAEC,iBAAiB,QAAQ,kBAAkB;AAC3E,SAASC,gBAAgB,EAAEC,2BAA2B,QAAQ,YAAY;AAC1E,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,gBAAgB;AACpE,SACEC,0BAA0B,EAC1BC,4BAA4B,QACvB,cAAc;AAYrB,MAAMC,8BAA8B,GAAGZ,UAAU,CAACa,uBAAuB,CACvEhB,QAAQ,CAACgB,uBAAuB,CAACX,sBAAsB,CACzD,CAAC;AAOD,MAAMY,MAAM,GAAGf,UAAU,CAACgB,MAAM,CAAS;EACvCC,SAAS,EAAE;IACTC,IAAI,EAAE;EACR,CAAC;EACDC,MAAM,EAAE;IACNC,OAAO,EAAE,MAAM;IACfC,QAAQ,EAAE;EACZ;AACF,CAAC,CAAC;AA+BF;AACA;AACA,MAAMC,EAAE,GAAGvB,QAAQ,CAACuB,EAAE;AAEtB,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,QAAQ;EACRC,oBAAoB;EACpBC,wBAAwB;EACxBC,OAAO,EAAEC,gBAAgB,GA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CAAC,CAAC;IACrB;EACF,CAAC,EAAE,CAACiB,OAAO,CAAC,CAAC;EAEb,oBACElC,KAAA,CAAAoE,aAAA,CAACzD,eAAe,CAAC0D,QAAQ;IAACT,KAAK,EAAEf;EAAQ,gBACvC7C,KAAA,CAAAoE,aAAA,CAAChD,8BAA8B;IAC7BkD,GAAG,EAAElC,UAAW;IAChBF,OAAO,EAAEA,OAAQ;IACjBD,wBAAwB,EAAEA,wBAAyB;IACnDD,oBAAoB,EAAEA,oBAAqB;IAC3CiB,KAAK,EAAE3B,MAAM,CAACE;IACd;IAAA;IACA+C,wBAAwB,EAAEV,eAAgB;IAC1CC,mBAAmB,EAAEjC,EAAE,KAAK,KAAK,GAAGwB,cAAc,GAAGmB,SAAU;IAC/DnB,cAAc,EAAExB,EAAE,KAAK,SAAS,GAAGwB,cAAc,GAAGmB,SAAU;IAC9DT,yBAAyB,EAAEV,cAAe;IAC1CoB,qCAAqC,EAAET;EAAmB,GAEzDjC,QAC6B,CAAC,eACjC/B,KAAA,CAAAoE,aAAA,CAAC/D,QAAQ,CAACqE,IAAI;IACZ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAzB,KAAK,EAAEA;EAAM,CACd,CACuB,CAAC;AAE/B,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","useEffect","useMemo","useRef","useState","Animated","Platform","StyleSheet","controlEdgeToEdgeValues","isEdgeToEdge","Reanimated","useSharedValue","KeyboardControllerView","KeyboardContext","focusedInputEventsMap","keyboardEventsMap","useAnimatedValue","useEventHandlerRegistration","applyMonkeyPatch","revertMonkeyPatch","useAnimatedKeyboardHandler","useFocusedInputLayoutHandler","IS_EDGE_TO_EDGE","KeyboardControllerViewAnimated","createAnimatedComponent","styles","create","container","flex","hidden","display","position","OS","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","enabled","initiallyEnabled","viewTagRef","setEnabled","progress","height","progressSV","heightSV","layout","setKeyboardHandlers","setInputHandlers","context","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","value","keyboardHandler","onKeyboardMoveStart","onKeyboardMoveInteractive","inputLayoutHandler","onFocusedInputLayoutChanged","e","target","__DEV__","createElement","Provider","ref","onKeyboardMoveReanimated","undefined","onFocusedInputLayoutChangedReanimated","View"],"sources":["animated.tsx"],"sourcesContent":["/* eslint react/jsx-sort-props: off */\nimport React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Animated, Platform, StyleSheet } from \"react-native\";\nimport {\n controlEdgeToEdgeValues,\n isEdgeToEdge,\n} from \"react-native-is-edge-to-edge\";\nimport Reanimated, { useSharedValue } from \"react-native-reanimated\";\n\nimport { KeyboardControllerView } from \"./bindings\";\nimport { KeyboardContext } from \"./context\";\nimport { focusedInputEventsMap, keyboardEventsMap } from \"./event-mappings\";\nimport { useAnimatedValue, useEventHandlerRegistration } from \"./internal\";\nimport { applyMonkeyPatch, revertMonkeyPatch } from \"./monkey-patch\";\nimport {\n useAnimatedKeyboardHandler,\n useFocusedInputLayoutHandler,\n} from \"./reanimated\";\n\nimport type { KeyboardAnimationContext } from \"./context\";\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\nconst IS_EDGE_TO_EDGE = isEdgeToEdge();\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(KeyboardControllerView),\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 * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\n// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package\n// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details\nconst OS = Platform.OS;\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n // ref\n const viewTagRef = useRef<React.Component<KeyboardControllerProps>>(null);\n // state\n const [enabled, setEnabled] = useState(initiallyEnabled);\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 layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(\n keyboardEventsMap,\n viewTagRef,\n );\n const setInputHandlers = useEventHandlerRegistration<FocusedInputHandler>(\n focusedInputEventsMap,\n viewTagRef,\n );\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height, -1) },\n reanimated: { progress: progressSV, height: heightSV },\n layout,\n setKeyboardHandlers,\n setInputHandlers,\n setEnabled,\n }),\n [enabled],\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(OS)) {\n // eslint-disable-next-line react-compiler/react-compiler\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const keyboardHandler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"ios\"]);\n },\n onKeyboardMove: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\"]);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\", \"ios\"]);\n },\n },\n [],\n );\n const inputLayoutHandler = useFocusedInputLayoutHandler(\n {\n onFocusedInputLayoutChanged: (e) => {\n \"worklet\";\n\n if (e.target !== -1) {\n layout.value = e;\n } else {\n layout.value = null;\n }\n },\n },\n [],\n );\n\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n if (__DEV__) {\n controlEdgeToEdgeValues({ statusBarTranslucent, navigationBarTranslucent });\n }\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n ref={viewTagRef}\n enabled={enabled}\n navigationBarTranslucent={IS_EDGE_TO_EDGE || navigationBarTranslucent}\n statusBarTranslucent={IS_EDGE_TO_EDGE || statusBarTranslucent}\n style={styles.container}\n // on*Reanimated prop must precede animated handlers to work correctly\n onKeyboardMoveReanimated={keyboardHandler}\n onKeyboardMoveStart={OS === \"ios\" ? onKeyboardMove : undefined}\n onKeyboardMove={OS === \"android\" ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n onFocusedInputLayoutChangedReanimated={inputLayoutHandler}\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":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnE,SAASC,QAAQ,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AAC7D,SACEC,uBAAuB,EACvBC,YAAY,QACP,8BAA8B;AACrC,OAAOC,UAAU,IAAIC,cAAc,QAAQ,yBAAyB;AAEpE,SAASC,sBAAsB,QAAQ,YAAY;AACnD,SAASC,eAAe,QAAQ,WAAW;AAC3C,SAASC,qBAAqB,EAAEC,iBAAiB,QAAQ,kBAAkB;AAC3E,SAASC,gBAAgB,EAAEC,2BAA2B,QAAQ,YAAY;AAC1E,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,gBAAgB;AACpE,SACEC,0BAA0B,EAC1BC,4BAA4B,QACvB,cAAc;AAYrB,MAAMC,eAAe,GAAGb,YAAY,CAAC,CAAC;AAEtC,MAAMc,8BAA8B,GAAGb,UAAU,CAACc,uBAAuB,CACvEnB,QAAQ,CAACmB,uBAAuB,CAACZ,sBAAsB,CACzD,CAAC;AAOD,MAAMa,MAAM,GAAGlB,UAAU,CAACmB,MAAM,CAAS;EACvCC,SAAS,EAAE;IACTC,IAAI,EAAE;EACR,CAAC;EACDC,MAAM,EAAE;IACNC,OAAO,EAAE,MAAM;IACfC,QAAQ,EAAE;EACZ;AACF,CAAC,CAAC;AA+BF;AACA;AACA,MAAMC,EAAE,GAAG1B,QAAQ,CAAC0B,EAAE;AAEtB,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,QAAQ;EACRC,oBAAoB;EACpBC,wBAAwB;EACxB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C,MAAM;MACLC,iBAAiB,CAAC,CAAC;IACrB;EACF,CAAC,EAAE,CAACkB,OAAO,CAAC,CAAC;EAEb,IAAIkC,OAAO,EAAE;IACX/D,uBAAuB,CAAC;MAAE2B,oBAAoB;MAAEC;IAAyB,CAAC,CAAC;EAC7E;EAEA,oBACEpC,KAAA,CAAAwE,aAAA,CAAC3D,eAAe,CAAC4D,QAAQ;IAACV,KAAK,EAAEf;EAAQ,gBACvChD,KAAA,CAAAwE,aAAA,CAACjD,8BAA8B;IAC7BmD,GAAG,EAAEnC,UAAW;IAChBF,OAAO,EAAEA,OAAQ;IACjBD,wBAAwB,EAAEd,eAAe,IAAIc,wBAAyB;IACtED,oBAAoB,EAAEb,eAAe,IAAIa,oBAAqB;IAC9DiB,KAAK,EAAE3B,MAAM,CAACE;IACd;IAAA;IACAgD,wBAAwB,EAAEX,eAAgB;IAC1CC,mBAAmB,EAAEjC,EAAE,KAAK,KAAK,GAAGwB,cAAc,GAAGoB,SAAU;IAC/DpB,cAAc,EAAExB,EAAE,KAAK,SAAS,GAAGwB,cAAc,GAAGoB,SAAU;IAC9DV,yBAAyB,EAAEV,cAAe;IAC1CqB,qCAAqC,EAAEV;EAAmB,GAEzDjC,QAC6B,CAAC,eACjClC,KAAA,CAAAwE,aAAA,CAACnE,QAAQ,CAACyE,IAAI;IACZ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA1B,KAAK,EAAEA;EAAM,CACd,CACuB,CAAC;AAE/B,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
1
2
|
import { useSharedValue } from "react-native-reanimated";
|
|
2
3
|
import { useKeyboardContext } from "../../context";
|
|
3
4
|
import { useKeyboardHandler } from "../../hooks";
|
|
@@ -5,10 +6,14 @@ export const useKeyboardAnimation = () => {
|
|
|
5
6
|
const {
|
|
6
7
|
reanimated
|
|
7
8
|
} = useKeyboardContext();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
|
|
10
|
+
// calculate it only once on mount, to avoid `SharedValue` reads during a render
|
|
11
|
+
const [initialHeight] = useState(() => -reanimated.height.value);
|
|
12
|
+
const [initialProgress] = useState(() => reanimated.progress.value);
|
|
13
|
+
const heightWhenOpened = useSharedValue(initialHeight);
|
|
14
|
+
const height = useSharedValue(initialHeight);
|
|
15
|
+
const progress = useSharedValue(initialProgress);
|
|
16
|
+
const isClosed = useSharedValue(initialProgress === 0);
|
|
12
17
|
useKeyboardHandler({
|
|
13
18
|
onStart: e => {
|
|
14
19
|
"worklet";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSharedValue","useKeyboardContext","useKeyboardHandler","useKeyboardAnimation","reanimated","
|
|
1
|
+
{"version":3,"names":["useState","useSharedValue","useKeyboardContext","useKeyboardHandler","useKeyboardAnimation","reanimated","initialHeight","height","value","initialProgress","progress","heightWhenOpened","isClosed","onStart","e","onMove","onInteractive","onEnd"],"sources":["hooks.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardContext } from \"../../context\";\nimport { useKeyboardHandler } from \"../../hooks\";\n\nexport const useKeyboardAnimation = () => {\n const { reanimated } = useKeyboardContext();\n\n // calculate it only once on mount, to avoid `SharedValue` reads during a render\n const [initialHeight] = useState(() => -reanimated.height.value);\n const [initialProgress] = useState(() => reanimated.progress.value);\n\n const heightWhenOpened = useSharedValue(initialHeight);\n const height = useSharedValue(initialHeight);\n const progress = useSharedValue(initialProgress);\n const isClosed = useSharedValue(initialProgress === 0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n isClosed.value = false;\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 onInteractive: (e) => {\n \"worklet\";\n\n progress.value = e.progress;\n height.value = e.height;\n },\n onEnd: (e) => {\n \"worklet\";\n\n isClosed.value = e.height === 0;\n\n height.value = e.height;\n progress.value = e.progress;\n },\n },\n [],\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,OAAO;AAChC,SAASC,cAAc,QAAQ,yBAAyB;AAExD,SAASC,kBAAkB,QAAQ,eAAe;AAClD,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,OAAO,MAAMC,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAGH,kBAAkB,CAAC,CAAC;;EAE3C;EACA,MAAM,CAACI,aAAa,CAAC,GAAGN,QAAQ,CAAC,MAAM,CAACK,UAAU,CAACE,MAAM,CAACC,KAAK,CAAC;EAChE,MAAM,CAACC,eAAe,CAAC,GAAGT,QAAQ,CAAC,MAAMK,UAAU,CAACK,QAAQ,CAACF,KAAK,CAAC;EAEnE,MAAMG,gBAAgB,GAAGV,cAAc,CAACK,aAAa,CAAC;EACtD,MAAMC,MAAM,GAAGN,cAAc,CAACK,aAAa,CAAC;EAC5C,MAAMI,QAAQ,GAAGT,cAAc,CAACQ,eAAe,CAAC;EAChD,MAAMG,QAAQ,GAAGX,cAAc,CAACQ,eAAe,KAAK,CAAC,CAAC;EAEtDN,kBAAkB,CAChB;IACEU,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACP,MAAM,GAAG,CAAC,EAAE;QAChB;QACAK,QAAQ,CAACJ,KAAK,GAAG,KAAK;QACtBG,gBAAgB,CAACH,KAAK,GAAGM,CAAC,CAACP,MAAM;MACnC;IACF,CAAC;IACDQ,MAAM,EAAGD,CAAC,IAAK;MACb,SAAS;;MAETJ,QAAQ,CAACF,KAAK,GAAGM,CAAC,CAACJ,QAAQ;MAC3BH,MAAM,CAACC,KAAK,GAAGM,CAAC,CAACP,MAAM;IACzB,CAAC;IACDS,aAAa,EAAGF,CAAC,IAAK;MACpB,SAAS;;MAETJ,QAAQ,CAACF,KAAK,GAAGM,CAAC,CAACJ,QAAQ;MAC3BH,MAAM,CAACC,KAAK,GAAGM,CAAC,CAACP,MAAM;IACzB,CAAC;IACDU,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETF,QAAQ,CAACJ,KAAK,GAAGM,CAAC,CAACP,MAAM,KAAK,CAAC;MAE/BA,MAAM,CAACC,KAAK,GAAGM,CAAC,CAACP,MAAM;MACvBG,QAAQ,CAACF,KAAK,GAAGM,CAAC,CAACJ,QAAQ;IAC7B;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEH,MAAM;IAAEG,QAAQ;IAAEC,gBAAgB;IAAEC;EAAS,CAAC;AACzD,CAAC","ignoreList":[]}
|
package/lib/module/context.js
CHANGED
|
@@ -6,7 +6,9 @@ const withSharedValue = value => ({
|
|
|
6
6
|
value,
|
|
7
7
|
addListener: NOOP,
|
|
8
8
|
removeListener: NOOP,
|
|
9
|
-
modify: NOOP
|
|
9
|
+
modify: NOOP,
|
|
10
|
+
get: () => value,
|
|
11
|
+
set: NOOP
|
|
10
12
|
});
|
|
11
13
|
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
12
14
|
const DEFAULT_LAYOUT = withSharedValue(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","Animated","NOOP","NESTED_NOOP","withSharedValue","value","addListener","removeListener","modify","DEFAULT_SHARED_VALUE","DEFAULT_LAYOUT","defaultContext","enabled","animated","progress","Value","height","reanimated","layout","setKeyboardHandlers","setInputHandlers","setEnabled","KeyboardContext","useKeyboardContext","context","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { Animated } from \"react-native\";\n\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardHandler,\n} from \"./types\";\nimport type React from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\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 enabled: boolean;\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n layout: SharedValue<FocusedInputLayoutChangedEvent | null>;\n setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;\n setInputHandlers: (handlers: FocusedInputHandler) => () => void;\n setEnabled: React.Dispatch<React.SetStateAction<boolean>>;\n};\nconst NOOP = () => {};\nconst NESTED_NOOP = () => NOOP;\nconst withSharedValue = <T>(value: T): SharedValue<T> => ({\n value,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n});\nconst DEFAULT_SHARED_VALUE = withSharedValue(0);\nconst DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(\n null,\n);\nconst defaultContext: KeyboardAnimationContext = {\n enabled: true,\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 layout: DEFAULT_LAYOUT,\n setKeyboardHandlers: NESTED_NOOP,\n setInputHandlers: NESTED_NOOP,\n setEnabled: NOOP,\n};\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;AA2BvC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,WAAW,GAAGA,CAAA,KAAMD,IAAI;AAC9B,MAAME,eAAe,GAAOC,KAAQ,KAAsB;EACxDA,KAAK;EACLC,WAAW,EAAEJ,IAAI;EACjBK,cAAc,EAAEL,IAAI;EACpBM,MAAM,EAAEN;
|
|
1
|
+
{"version":3,"names":["createContext","useContext","Animated","NOOP","NESTED_NOOP","withSharedValue","value","addListener","removeListener","modify","get","set","DEFAULT_SHARED_VALUE","DEFAULT_LAYOUT","defaultContext","enabled","animated","progress","Value","height","reanimated","layout","setKeyboardHandlers","setInputHandlers","setEnabled","KeyboardContext","useKeyboardContext","context","__DEV__","console","warn"],"sources":["context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { Animated } from \"react-native\";\n\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardHandler,\n} from \"./types\";\nimport type React from \"react\";\nimport type { SharedValue } from \"react-native-reanimated\";\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 enabled: boolean;\n animated: AnimatedContext;\n reanimated: ReanimatedContext;\n layout: SharedValue<FocusedInputLayoutChangedEvent | null>;\n setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;\n setInputHandlers: (handlers: FocusedInputHandler) => () => void;\n setEnabled: React.Dispatch<React.SetStateAction<boolean>>;\n};\nconst NOOP = () => {};\nconst NESTED_NOOP = () => NOOP;\nconst withSharedValue = <T>(value: T): SharedValue<T> => ({\n value,\n addListener: NOOP,\n removeListener: NOOP,\n modify: NOOP,\n get: () => value,\n set: NOOP,\n});\nconst DEFAULT_SHARED_VALUE = withSharedValue(0);\nconst DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(\n null,\n);\nconst defaultContext: KeyboardAnimationContext = {\n enabled: true,\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 layout: DEFAULT_LAYOUT,\n setKeyboardHandlers: NESTED_NOOP,\n setInputHandlers: NESTED_NOOP,\n setEnabled: NOOP,\n};\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;AA2BvC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,MAAMC,WAAW,GAAGA,CAAA,KAAMD,IAAI;AAC9B,MAAME,eAAe,GAAOC,KAAQ,KAAsB;EACxDA,KAAK;EACLC,WAAW,EAAEJ,IAAI;EACjBK,cAAc,EAAEL,IAAI;EACpBM,MAAM,EAAEN,IAAI;EACZO,GAAG,EAAEA,CAAA,KAAMJ,KAAK;EAChBK,GAAG,EAAER;AACP,CAAC,CAAC;AACF,MAAMS,oBAAoB,GAAGP,eAAe,CAAC,CAAC,CAAC;AAC/C,MAAMQ,cAAc,GAAGR,eAAe,CACpC,IACF,CAAC;AACD,MAAMS,cAAwC,GAAG;EAC/CC,OAAO,EAAE,IAAI;EACbC,QAAQ,EAAE;IACRC,QAAQ,EAAE,IAAIf,QAAQ,CAACgB,KAAK,CAAC,CAAC,CAAC;IAC/BC,MAAM,EAAE,IAAIjB,QAAQ,CAACgB,KAAK,CAAC,CAAC;EAC9B,CAAC;EACDE,UAAU,EAAE;IACVH,QAAQ,EAAEL,oBAAoB;IAC9BO,MAAM,EAAEP;EACV,CAAC;EACDS,MAAM,EAAER,cAAc;EACtBS,mBAAmB,EAAElB,WAAW;EAChCmB,gBAAgB,EAAEnB,WAAW;EAC7BoB,UAAU,EAAErB;AACd,CAAC;AAED,OAAO,MAAMsB,eAAe,gBAAGzB,aAAa,CAACc,cAAc,CAAC;AAC5D,OAAO,MAAMY,kBAAkB,GAAGA,CAAA,KAAM;EACtC,MAAMC,OAAO,GAAG1B,UAAU,CAACwB,eAAe,CAAC;EAE3C,IAAIG,OAAO,IAAID,OAAO,KAAKb,cAAc,EAAE;IACzCe,OAAO,CAACC,IAAI,CACV,sLACF,CAAC;EACH;EAEA,OAAOH,OAAO;AAChB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.3",
|
|
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",
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"registry": "https://registry.npmjs.org/"
|
|
76
76
|
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"react-native-is-edge-to-edge": "^1.1.6"
|
|
79
|
+
},
|
|
77
80
|
"devDependencies": {
|
|
78
81
|
"@commitlint/config-conventional": "^11.0.0",
|
|
79
82
|
"@react-native/eslint-config": "^0.75.3",
|
|
@@ -101,7 +104,7 @@
|
|
|
101
104
|
"react": "18.3.1",
|
|
102
105
|
"react-native": "0.75.3",
|
|
103
106
|
"react-native-builder-bob": "^0.18.0",
|
|
104
|
-
"react-native-reanimated": "3.
|
|
107
|
+
"react-native-reanimated": "3.16.1",
|
|
105
108
|
"react-test-renderer": "18.2.0",
|
|
106
109
|
"release-it": "^14.2.2",
|
|
107
110
|
"typescript": "5.0.4"
|
package/src/animated.tsx
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* eslint react/jsx-sort-props: off */
|
|
2
2
|
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Animated, Platform, StyleSheet } from "react-native";
|
|
4
|
+
import {
|
|
5
|
+
controlEdgeToEdgeValues,
|
|
6
|
+
isEdgeToEdge,
|
|
7
|
+
} from "react-native-is-edge-to-edge";
|
|
4
8
|
import Reanimated, { useSharedValue } from "react-native-reanimated";
|
|
5
9
|
|
|
6
10
|
import { KeyboardControllerView } from "./bindings";
|
|
@@ -23,6 +27,8 @@ import type {
|
|
|
23
27
|
} from "./types";
|
|
24
28
|
import type { ViewStyle } from "react-native";
|
|
25
29
|
|
|
30
|
+
const IS_EDGE_TO_EDGE = isEdgeToEdge();
|
|
31
|
+
|
|
26
32
|
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
27
33
|
Animated.createAnimatedComponent(KeyboardControllerView),
|
|
28
34
|
);
|
|
@@ -189,13 +195,17 @@ export const KeyboardProvider = ({
|
|
|
189
195
|
}
|
|
190
196
|
}, [enabled]);
|
|
191
197
|
|
|
198
|
+
if (__DEV__) {
|
|
199
|
+
controlEdgeToEdgeValues({ statusBarTranslucent, navigationBarTranslucent });
|
|
200
|
+
}
|
|
201
|
+
|
|
192
202
|
return (
|
|
193
203
|
<KeyboardContext.Provider value={context}>
|
|
194
204
|
<KeyboardControllerViewAnimated
|
|
195
205
|
ref={viewTagRef}
|
|
196
206
|
enabled={enabled}
|
|
197
|
-
navigationBarTranslucent={navigationBarTranslucent}
|
|
198
|
-
statusBarTranslucent={statusBarTranslucent}
|
|
207
|
+
navigationBarTranslucent={IS_EDGE_TO_EDGE || navigationBarTranslucent}
|
|
208
|
+
statusBarTranslucent={IS_EDGE_TO_EDGE || statusBarTranslucent}
|
|
199
209
|
style={styles.container}
|
|
200
210
|
// on*Reanimated prop must precede animated handlers to work correctly
|
|
201
211
|
onKeyboardMoveReanimated={keyboardHandler}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
1
2
|
import { useSharedValue } from "react-native-reanimated";
|
|
2
3
|
|
|
3
4
|
import { useKeyboardContext } from "../../context";
|
|
@@ -5,10 +6,15 @@ import { useKeyboardHandler } from "../../hooks";
|
|
|
5
6
|
|
|
6
7
|
export const useKeyboardAnimation = () => {
|
|
7
8
|
const { reanimated } = useKeyboardContext();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
|
|
10
|
+
// calculate it only once on mount, to avoid `SharedValue` reads during a render
|
|
11
|
+
const [initialHeight] = useState(() => -reanimated.height.value);
|
|
12
|
+
const [initialProgress] = useState(() => reanimated.progress.value);
|
|
13
|
+
|
|
14
|
+
const heightWhenOpened = useSharedValue(initialHeight);
|
|
15
|
+
const height = useSharedValue(initialHeight);
|
|
16
|
+
const progress = useSharedValue(initialProgress);
|
|
17
|
+
const isClosed = useSharedValue(initialProgress === 0);
|
|
12
18
|
|
|
13
19
|
useKeyboardHandler(
|
|
14
20
|
{
|
package/src/context.ts
CHANGED
|
@@ -33,6 +33,8 @@ const withSharedValue = <T>(value: T): SharedValue<T> => ({
|
|
|
33
33
|
addListener: NOOP,
|
|
34
34
|
removeListener: NOOP,
|
|
35
35
|
modify: NOOP,
|
|
36
|
+
get: () => value,
|
|
37
|
+
set: NOOP,
|
|
36
38
|
});
|
|
37
39
|
const DEFAULT_SHARED_VALUE = withSharedValue(0);
|
|
38
40
|
const DEFAULT_LAYOUT = withSharedValue<FocusedInputLayoutChangedEvent | null>(
|