UNPKG

@nexara/nativeflow

Version:

Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.

125 lines (124 loc) 4.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../../constants/index.js"); var _Portal = _interopRequireDefault(require("../Portal/Portal.js")); var _index2 = require("../../hooks/index.js"); var _index3 = require("../../helpers/index.js"); var _jsxRuntime = require("react/jsx-runtime"); 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); } const Dialog = /*#__PURE__*/(0, _react.forwardRef)(({ variant = 'classic', size = 'lg', fullScreen, backdropColor, portalKey, onClose, containerStyle, children }, ref) => { const uniqueId = (0, _react.useId)(); const [dialogVisible, setDialogVisible] = (0, _react.useState)(false); const scale = (0, _react.useRef)(new _reactNative.Animated.Value(0.9)).current; const opacity = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current; const theme = (0, _index2.useTheme)(); (0, _react.useEffect)(() => { _reactNative.Animated.timing(opacity, { toValue: dialogVisible ? 1 : 0, duration: 300, useNativeDriver: true }).start(); _reactNative.Animated.spring(scale, { toValue: dialogVisible ? 1 : 0.9, damping: 10, stiffness: 90, useNativeDriver: true }).start(); }, [dialogVisible]); (0, _react.useEffect)(() => { const handler = _reactNative.BackHandler.addEventListener('hardwareBackPress', hardwareBackPress); return () => handler.remove(); }, [dialogVisible]); const hardwareBackPress = () => { onClose?.(); setDialogVisible(false); return dialogVisible; }; (0, _react.useImperativeHandle)(ref, () => ({ open: () => setDialogVisible(true), close: () => setDialogVisible(false) })); const backdropAnimatedStyles = { opacity: opacity, backgroundColor: backdropColor ?? theme?.colors.background.backdrop }; const modalContAnimatedStyles = { transform: [{ scale }], opacity: opacity }; const dynamicModalContStyles = { minHeight: fullScreen ? '100%' : 'auto', maxHeight: fullScreen ? '100%' : '80%', width: `${_index.dialogSizes[size]}%`, backgroundColor: theme?.colors.background.elevated, borderColor: theme?.colors.border.default, borderRadius: (0, _index3.verticalScale)(40) }; const renderChildrenWithVariant = () => { return _react.default.Children.map(children, child => { if (/*#__PURE__*/_react.default.isValidElement(child)) { return /*#__PURE__*/(0, _react.cloneElement)(child, { variant }); } return child; }); }; const handleStartShouldSetResponder = () => { _reactNative.Keyboard.dismiss(); onClose?.(); setDialogVisible(false); return true; }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Portal.default, { name: portalKey ?? `dialog-${uniqueId}`, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, { style: [STYLES.BACKDROP_CONT, backdropAnimatedStyles], pointerEvents: dialogVisible ? 'auto' : 'none', onStartShouldSetResponder: handleStartShouldSetResponder, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, { style: [STYLES.MODAL_CONT, dynamicModalContStyles, modalContAnimatedStyles, containerStyle], onStartShouldSetResponder: () => true, children: renderChildrenWithVariant() }) }) }) }); }); var _default = exports.default = Dialog; const STYLES = _reactNative.StyleSheet.create({ BACKDROP_CONT: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, justifyContent: 'center', alignItems: 'center' }, MODAL_CONT: { // backgroundColor: '#fff', borderRadius: 5, borderWidth: 1 // borderColor: '#d4d4d4' } }); //# sourceMappingURL=Dialog.js.map