react-native-keyboard-controller
Version:
Keyboard manager which works in identical way on both iOS and Android
61 lines (59 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useKeyboardContext = exports.KeyboardContext = void 0;
var _react = require("react");
var _reactNative = require("react-native");
const NOOP = () => {};
const NESTED_NOOP = () => NOOP;
const withSharedValue = value => ({
value,
addListener: NOOP,
removeListener: NOOP,
modify: NOOP,
get: () => value,
set: NOOP
});
const DEFAULT_SHARED_VALUE = withSharedValue(0);
const DEFAULT_LAYOUT = withSharedValue(null);
const defaultContext = {
enabled: true,
animated: {
progress: new _reactNative.Animated.Value(0),
height: new _reactNative.Animated.Value(0)
},
reanimated: {
progress: DEFAULT_SHARED_VALUE,
height: DEFAULT_SHARED_VALUE
},
layout: DEFAULT_LAYOUT,
setKeyboardHandlers: NESTED_NOOP,
setInputHandlers: NESTED_NOOP,
setEnabled: NOOP
};
const KeyboardContext = exports.KeyboardContext = /*#__PURE__*/(0, _react.createContext)(defaultContext);
/**
* A hook that returns a reference to {@link KeyboardAnimationContext} object.
*
* @returns Object {@link KeyboardAnimationContext|containing} keyboard-controller context.
* @example
* ```ts
* const context = useKeyboardContext();
*
* useLayoutEffect(() => {
* const cleanup = context.setInputHandlers(handler);
*
* return () => cleanup();
* }, deps);
* ```
*/
const useKeyboardContext = () => {
const context = (0, _react.useContext)(KeyboardContext);
if (__DEV__ && context === defaultContext) {
console.warn("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.");
}
return context;
};
exports.useKeyboardContext = useKeyboardContext;
//# sourceMappingURL=context.js.map