UNPKG

@attio/react-native-bottom-sheet-toolbox-text-input

Version:
61 lines (60 loc) 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OverlayTextInputContainer = OverlayTextInputContainer; var _reactNative = require("react-native"); var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated")); var _reactNativeBottomSheetToolbox = require("@attio/react-native-bottom-sheet-toolbox"); 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 styles = _reactNative.StyleSheet.create({ container: { bottom: 0, opacity: 0, position: "absolute", width: "100%" } }); function OverlayTextInputContainer({ children, style, minTextInputHeightSharedValue, topInsetSharedValue, keyboardAwareSafeAreaBottomInsetFallback }) { const { isReadySharedValue, currentPositionSharedValue } = (0, _reactNativeBottomSheetToolbox.useBottomSheetToolboxInternalContext)(); const keyboardAwareSafeAreaBottomInsetSharedValue = (0, _reactNativeBottomSheetToolbox.useKeyboardAwareSafeAreaBottomInset)(keyboardAwareSafeAreaBottomInsetFallback); const keyboardHeightSharedValue = (0, _reactNativeBottomSheetToolbox.useKeyboardHeightSharedValue)(); const bottomSharedValue = (0, _reactNativeReanimated.useDerivedValue)(() => { const bottomInset = keyboardAwareSafeAreaBottomInsetSharedValue.get(); const keyboardHeight = keyboardHeightSharedValue.get(); const minTextInputHeight = minTextInputHeightSharedValue.get(); const topInset = topInsetSharedValue.get(); if (minTextInputHeight === null || topInset === null) return null; const unclampedClosingOffset = currentPositionSharedValue.get() - minTextInputHeight - keyboardHeight - topInset - bottomInset; const closingOffset = Math.min(0, unclampedClosingOffset); const bottom = keyboardHeight + closingOffset; return bottomInset - bottom; }, [keyboardAwareSafeAreaBottomInsetSharedValue, keyboardHeightSharedValue, currentPositionSharedValue, minTextInputHeightSharedValue, topInsetSharedValue]); const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { const bottom = bottomSharedValue.get(); if (bottom === null || !isReadySharedValue.get()) return {}; const bottomInset = keyboardAwareSafeAreaBottomInsetSharedValue.get(); return { opacity: 1, paddingBottom: bottomInset, transform: [{ translateY: bottom }] }; }, [isReadySharedValue, keyboardAwareSafeAreaBottomInsetSharedValue]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [styles.container, style, animatedStyle], children: children }); } //# sourceMappingURL=overlay-text-input-container.js.map