UNPKG

@masumdev/rn-fab

Version:

A highly customizable Floating Action Button (FAB) component for React Native. Supports multiple variants including single, extended, stacked, clustered, and doted layouts. Built with smooth animations and optimized for both iOS and Android platforms.

139 lines (137 loc) 5.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); 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 FabExtended = ({ items, style, containerStyle, theme = 'light', isOpen: setIsOpen, plusIcon }) => { const [width, height, borderRadius, isOpen] = [(0, _reactNativeReanimated.useSharedValue)(60), (0, _reactNativeReanimated.useSharedValue)(60), (0, _reactNativeReanimated.useSharedValue)(50), (0, _reactNativeReanimated.useSharedValue)(false)]; const progress = (0, _reactNativeReanimated.useDerivedValue)(() => { 'worklet'; return isOpen.value ? (0, _reactNativeReanimated.withTiming)(1) : (0, _reactNativeReanimated.withTiming)(0); }); const config = (0, _react.useMemo)(() => ({ easing: _reactNativeReanimated.Easing.bezier(0.68, -0.6, 0.32, 1.6), duration: 500 }), []); const handlePress = () => { if (isOpen.value) { width.value = (0, _reactNativeReanimated.withTiming)(60, config); height.value = (0, _reactNativeReanimated.withTiming)(60, config); borderRadius.value = (0, _reactNativeReanimated.withTiming)(50, config); } else { width.value = (0, _reactNativeReanimated.withSpring)(200); height.value = (0, _reactNativeReanimated.withSpring)(250); borderRadius.value = (0, _reactNativeReanimated.withSpring)(10); } isOpen.value = !isOpen.value; setIsOpen?.(!isOpen.value); }; const animatedStyles = { container: (0, _reactNativeReanimated.useAnimatedStyle)(() => ({ width: width.value, height: height.value, borderRadius: borderRadius.value })), plus: (0, _reactNativeReanimated.useAnimatedStyle)(() => ({ transform: [{ rotate: `${progress.value * 45}deg` }] })) }; const backgroundStyle = theme === 'light' ? styles.lightBg : styles.darkBg; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [styles.container, containerStyle], children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeReanimated.default.View, { style: [styles.fabContainer, animatedStyles.container, backgroundStyle, style], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, { style: styles.iconContainer, onPress: handlePress, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [styles.iconContainer, animatedStyles.plus, style], children: plusIcon || /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, { source: require('../assets/PlusIcon.png'), style: [styles.icon, { tintColor: theme === 'light' ? '#fff' : '#000' }] }) }) }), items.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, { style: styles.contentContainer, onPress: () => { item?.onPress?.(); handlePress(); }, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.iconContainer, children: item?.icon }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.text, { color: theme === 'light' ? '#fff' : '#000' }], children: item?.label })] }, index))] }) }); }; const styles = _reactNative.StyleSheet.create({ container: { flex: 1 }, fabContainer: { position: 'absolute', bottom: 30, right: 30, overflow: 'hidden', // Add shadow shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5 }, iconContainer: { width: 60, height: 60, borderRadius: 50, justifyContent: 'center', alignItems: 'center' }, icon: { width: 26, height: 26 }, contentContainer: { flexDirection: 'row', alignItems: 'center', overflow: 'hidden' }, text: { fontSize: 18, marginLeft: 10 }, lightBg: { backgroundColor: '#000' }, darkBg: { backgroundColor: '#fff' } }); var _default = exports.default = /*#__PURE__*/_react.default.memo(FabExtended); //# sourceMappingURL=FabExtended.js.map