UNPKG

react-native-keyboard-controller

Version:

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

93 lines (92 loc) • 3.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _constants = require("../../constants"); var _module = require("../../module"); var _KeyboardStickyView = _interopRequireDefault(require("../KeyboardStickyView")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const translucentStack = []; let currentTranslucent = false; const applyTranslucent = () => { const next = translucentStack.length > 0 ? translucentStack[translucentStack.length - 1].translucent : false; if (next !== currentTranslucent) { currentTranslucent = next; _module.KeyboardController.setTranslucent(next); } }; const pushTranslucentEntry = entry => { translucentStack.push(entry); applyTranslucent(); }; const removeTranslucentEntry = entry => { const index = translucentStack.indexOf(entry); if (index !== -1) { translucentStack.splice(index, 1); } applyTranslucent(); }; /** * A component that renders content behind the keyboard. Since the keyboard * is translucent, the content (colors, gradients, animations) will blend * through and create visual effects on the keyboard. * * On iOS 26+ the keyboard has rounded corners, and the effect view * automatically matches that shape. * * @returns A view component positioned behind the keyboard. * @example * ```tsx * <KeyboardEffects> * <View style={{ flex: 1, backgroundColor: "purple" }} /> * </KeyboardEffects> * ``` */ const KeyboardEffects = /*#__PURE__*/(0, _react.forwardRef)(({ translucent, rounded = true, children, ...props }, ref) => { const stackEntry = (0, _react.useRef)({ translucent: Boolean(translucent) }).current; const containerStyle = (0, _react.useMemo)(() => [styles.container, _constants.KEYBOARD_HAS_ROUNDED_CORNERS && rounded && styles.rounded], [rounded]); (0, _react.useEffect)(() => { pushTranslucentEntry(stackEntry); return () => { removeTranslucentEntry(stackEntry); }; }, [stackEntry]); (0, _react.useEffect)(() => { stackEntry.translucent = Boolean(translucent); applyTranslucent(); }, [stackEntry, translucent]); return /*#__PURE__*/_react.default.createElement(_KeyboardStickyView.default, _extends({ ref: ref }, props), /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: containerStyle }, children)); }); const styles = _reactNative.StyleSheet.create({ container: { position: "absolute", bottom: 0, top: 0, left: 0, right: 0, height: 999 }, rounded: { borderTopLeftRadius: _constants.KEYBOARD_BORDER_RADIUS, borderTopRightRadius: _constants.KEYBOARD_BORDER_RADIUS, overflow: "hidden" } }); var _default = exports.default = KeyboardEffects; //# sourceMappingURL=index.js.map