@gorhom/bottom-sheet
Version:
A performant interactive bottom sheet with fully configurable options 🚀
87 lines (82 loc) • 3.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNativeGestureHandler = require("react-native-gesture-handler");
var _hooks = require("../../hooks");
var _utilities = require("../../utilities");
var _jsxRuntime = require("react/jsx-runtime");
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); }
const BottomSheetTextInputComponent = /*#__PURE__*/(0, _react.forwardRef)(({
onFocus,
onBlur,
...rest
}, providedRef) => {
//#region refs
const ref = (0, _react.useRef)(null);
//#endregion
//#region hooks
const {
animatedKeyboardState
} = (0, _hooks.useBottomSheetInternal)();
//#endregion
//#region callbacks
const handleOnFocus = (0, _react.useCallback)(args => {
const keyboardState = animatedKeyboardState.get();
animatedKeyboardState.set({
...keyboardState,
target: args.nativeEvent.target
});
if (onFocus) {
onFocus(args);
}
}, [onFocus, animatedKeyboardState]);
const handleOnBlur = (0, _react.useCallback)(args => {
/**
* remove the keyboard state target if it belong
* to the current component.
*/
const keyboardState = animatedKeyboardState.get();
if (keyboardState.target === args.nativeEvent.target) {
animatedKeyboardState.set({
...keyboardState,
target: undefined
});
}
if (onBlur) {
onBlur(args);
}
}, [onBlur, animatedKeyboardState]);
//#endregion
//#region effects
(0, _react.useEffect)(() => {
return () => {
/**
* remove the keyboard state target if it belong
* to the current component.
*/
const componentNode = (0, _utilities.findNodeHandle)(ref.current);
const keyboardState = animatedKeyboardState.get();
if (keyboardState.target === componentNode) {
animatedKeyboardState.set({
...keyboardState,
target: undefined
});
}
};
}, [animatedKeyboardState]);
(0, _react.useImperativeHandle)(providedRef, () => ref.current ?? undefined, []);
//#endregion
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.TextInput, {
ref: ref,
onFocus: handleOnFocus,
onBlur: handleOnBlur,
...rest
});
});
const BottomSheetTextInput = /*#__PURE__*/(0, _react.memo)(BottomSheetTextInputComponent);
BottomSheetTextInput.displayName = 'BottomSheetTextInput';
var _default = exports.default = BottomSheetTextInput;
//# sourceMappingURL=BottomSheetTextInput.js.map
;