import React from 'react'; import { Animated, TouchableOpacity, View } from 'react-native'; import type { StyleProp, ViewStyle, ColorValue } from 'react-native'; import { AnimatableView, AnimatedView, ChildrenView } from '../../components'; import { DEFAULT_COLOR_WHITE, getSpinnerStyle, useAnimatedValues, useRippleButton } from '../../utils'; import type { SpinnerButtonProps } from './SpinnerButtonTypes'; import { SpinnerButtonStyle } from '../../styles'; const AnimatedTouchablesOpacity: Animated.AnimatedComponent< typeof TouchableOpacity > = Animated.createAnimatedComponent(TouchableOpacity); const SpinnerButton: React.FC = ({ animationType, buttonContainer, buttonStyle, borderStyle, spinnerColor = DEFAULT_COLOR_WHITE, spinnerType = 'BallIndicator', onPress, children, indicatorCount, size = 16, spinnerOptions, gradientName, gradientType, gradientColors, gradientColoroffset, gradientColorAngle, gradientRadialRadius, gradientButtonHeight, radialRadiusx, radialRadiusy, radialRadiusRX, radialRadiusRY, rippleColor = 'rgba(255, 255, 255, .25)', animatedDuration = 300, customSpinnerComponent, animateWidth, animateHeight, animateRadius, isLoading = false, isConnected = true, disabled = false, disableStyle, disableGradientColors, }: SpinnerButtonProps) => { const isDisable: boolean = disabled || !isConnected; const isAnimationType: boolean = animationType !== null && animationType !== undefined; const gradientColor: ColorValue[] | undefined = isDisable ? disableGradientColors || gradientColors : gradientColors; const style: StyleProp = [ SpinnerButtonStyle.defaultButton, SpinnerButtonStyle.centerAlign, buttonStyle, borderStyle, isDisable && disableStyle, ]; const { height } = getSpinnerStyle(style, SpinnerButtonStyle.defaultButton); const { handleLayout, animatedStyles, animatedChildHideStyle, animatedChildShowStyle, } = useAnimatedValues({ isLoading, style, animatedDuration, animateWidth, animateHeight, animateRadius, animationType }); const { handleRipplePress, handleRippleLayout, animatedStyle } = useRippleButton({ onPress, animatedDuration, }); return ( ]} onPress={onPress} disabled={isDisable || isLoading}> {isAnimationType && animationType === 'ripple-effect' && ( {children} )} {isAnimationType && typeof animationType === 'string' && animationType !== 'ripple-effect' && ( )} {!isAnimationType && ( )} } /> ); }; export default SpinnerButton;