react-native-irano
Version:
A customizable cross-platform toast notification library for React Native.
174 lines (172 loc) • 5.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Alert = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeSvg = require("react-native-svg");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _jsxRuntime = require("react/jsx-runtime");
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 AnimatedPath = _reactNativeReanimated.default.createAnimatedComponent(_reactNativeSvg.Path);
const Alert = ({
title,
subtitle,
onClose,
visible,
preset,
animatedViewProps,
pathAnimatedProps,
titleStyle,
subtitleStyle,
cardStyle,
overlayStyle,
loadingIndicatorStyle,
autoHide = true,
autoHideDelay = 5000,
delay = 400,
duration = 400
}) => {
const strokeDashoffset = (0, _reactNativeReanimated.useSharedValue)(22);
const handleDialogClose = (0, _react.useCallback)(() => {
strokeDashoffset.value = 22;
onClose();
}, [onClose, strokeDashoffset]);
(0, _react.useEffect)(() => {
if (visible) {
// Start checkmark animation after a delay
setTimeout(() => {
strokeDashoffset.value = (0, _reactNativeReanimated.withTiming)(0, {
duration: duration,
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.ease)
});
}, delay); // Delay after fade-in animation
let autoCloseTimeout;
if (autoHide) {
autoCloseTimeout = setTimeout(() => {
handleDialogClose();
}, autoHideDelay);
}
return () => clearTimeout(autoCloseTimeout);
}
return; // Ensure all code paths return a value
}, [autoHide, autoHideDelay, delay, duration, handleDialogClose, strokeDashoffset, visible]);
const animatedProps = (0, _reactNativeReanimated.useAnimatedProps)(() => ({
strokeDashoffset: strokeDashoffset.value
}));
const renderContent = () => {
if (preset === 'loading') {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
style: styles.loadingIndicator,
size: "large",
...loadingIndicatorStyle
});
} else if (preset === 'error') {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Svg, {
style: styles.svgStyle,
width: "120",
height: "120",
viewBox: "0 0 24 24",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedPath, {
d: "M6 18L18 6M6 6l12 12" // X Path for error
,
stroke: "gray",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeDasharray: "22",
fill: "none",
...pathAnimatedProps,
animatedProps: animatedProps
})
});
} else {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Svg, {
style: styles.svgStyle,
width: "120",
height: "120",
viewBox: "0 0 24 24",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedPath, {
d: "M5 12.5l5 5 10-10" // Checkmark Path
,
stroke: "gray",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeDasharray: "22",
fill: "none",
...pathAnimatedProps,
animatedProps: animatedProps
})
});
}
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
visible: visible,
transparent: true,
animationType: !visible ? 'fade' : 'none',
onRequestClose: handleDialogClose,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [styles.modalOverlay, overlayStyle],
onTouchEnd: handleDialogClose,
children: visible && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeReanimated.default.View, {
entering: _reactNativeReanimated.ZoomIn.springify(),
exiting: _reactNativeReanimated.ZoomOut.duration(220).easing(_reactNativeReanimated.Easing.linear),
style: [styles.card, cardStyle],
onTouchEnd: handleDialogClose,
...animatedViewProps,
children: [renderContent(), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.title, titleStyle],
children: title
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [styles.subtitle, subtitleStyle],
children: subtitle
})]
})
})
});
};
exports.Alert = Alert;
const styles = _reactNative.StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#000'
},
modalOverlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.6)',
justifyContent: 'center',
alignItems: 'center'
},
card: {
backgroundColor: '#F5F5F5',
borderRadius: 12,
padding: 20,
alignItems: 'center',
width: 250
},
title: {
fontSize: 24,
fontWeight: 'bold',
color: '#333',
marginTop: 10,
textAlign: 'center'
},
subtitle: {
fontSize: 14,
color: '#666',
marginTop: 5,
textAlign: 'center'
},
svgStyle: {
padding: 20
},
loadingIndicator: {
margin: 20
}
});
//# sourceMappingURL=alert.js.map