UNPKG

react-native-keyboard-controller

Version:

Keyboard manager which works in identical way on both iOS and Android

63 lines (59 loc) • 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useFrozenPadding = useFrozenPadding; var _reactNativeReanimated = require("react-native-reanimated"); var _hooks = require("../../../hooks"); var _reanimated = require("../../../reanimated"); var _helpers = require("../useChatKeyboard/helpers"); /** * Hook that reconciles keyboard padding after a frozen interval. * * `useChatKeyboard` handlers skip all writes while `freeze` is enabled, so if * the keyboard opens or closes during the frozen interval `padding` keeps a * stale value (e.g. the open-keyboard height after a frozen dismissal). This * hook observes keyboard events independently of `freeze` and recomputes the * padding from the latest observed keyboard height as soon as `freeze` * transitions back to `false`. * * @param options - Keyboard padding shared values plus the scroll view `offset`. * @param options.freeze - When `true`, keyboard-driven layout writes are skipped. * @param options.offset - The distance between the bottom of the screen and the `ScrollView`. * @param options.padding - Keyboard-driven padding managed by `useChatKeyboard`. * @example * ```ts * useFrozenPadding({ freeze, offset, padding }); * ``` */ function useFrozenPadding({ freeze, offset, padding }) { const lastHeight = (0, _reactNativeReanimated.useSharedValue)(0); const targetKeyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0); (0, _hooks.useKeyboardHandler)({ onStart: e => { "worklet"; if (e.height > 0) { // eslint-disable-next-line react-compiler/react-compiler targetKeyboardHeight.value = e.height; } }, onMove: e => { "worklet"; lastHeight.value = e.height; }, onEnd: e => { "worklet"; lastHeight.value = e.height; } }, []); (0, _reanimated.useAnimatedReaction)(() => freeze.value, (isFrozen, wasFrozen) => { if (!isFrozen && wasFrozen === true) { padding.value = (0, _helpers.getEffectiveHeight)(lastHeight.value, targetKeyboardHeight.value, offset); } }, [offset]); } //# sourceMappingURL=index.js.map