import React, { useRef } from 'react'; import { Pressable, View, Animated, Text, StyleSheet } from 'react-native'; import { useTheme } from '../../theme/useTheme'; import type { FABProps, FABSize, FABPosition } from './FAB.types'; const sizeMap: Record = { sm: 48, md: 56, lg: 64, }; const positionMap: Record< FABPosition, { bottom: number; left?: number; right?: number; alignItems?: 'center' } > = { 'bottom-right': { bottom: 24, right: 24 }, 'bottom-left': { bottom: 24, left: 24 }, 'bottom-center': { bottom: 24, left: 0, right: 0, alignItems: 'center' }, }; export const FAB: React.FC = ({ size = 'md', color = 'primary', position = 'bottom-right', label, icon, style, onPressIn, onPressOut, ...pressableProps }) => { const theme = useTheme(); const scaleAnim = useRef(new Animated.Value(1)).current; const colorValue = theme.colors[color]; const dimension = sizeMap[size]; const positionStyle = positionMap[position]; const handlePressIn = (e: any) => { Animated.timing(scaleAnim, { toValue: 0.92, duration: 100, useNativeDriver: true, }).start(); onPressIn?.(e); }; const handlePressOut = (e: any) => { Animated.timing(scaleAnim, { toValue: 1, duration: 150, useNativeDriver: true, }).start(); onPressOut?.(e); }; const isExtended = Boolean(label); return ( {icon} {label && ( {label} )} ); }; const styles = StyleSheet.create({ wrapper: { position: 'absolute', }, fab: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }, content: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }, iconWrapper: { alignItems: 'center', justifyContent: 'center', }, label: {}, });