UNPKG

@nexara/nativeflow

Version:

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

120 lines (119 loc) 4.51 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 _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const Dialog = /*#__PURE__*/(0, _react.forwardRef)(({ variant = 'default', size = 'lg', fullScreen, backdropColor = 'rgba(0, 0, 0, 0.5)', // backdropColor = 'red', // animationDuration = 800, onClose, containerStyle, children }, ref) => { 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; (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 }; const modalContAnimatedStyles = { transform: [{ scale }], opacity: opacity }; const dynamicModalContStyles = { minHeight: fullScreen ? '100%' : 'auto', maxHeight: fullScreen ? '100%' : '80%', width: `${_index.dialogSizes[size]}%` }; 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: "dialog", 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