import React, { memo, useEffect, useRef } from 'react' import type { StyleProp, ViewStyle } from 'react-native' import { ActivityIndicator, Animated, Easing, StyleSheet, TouchableOpacity, View } from 'react-native' import { ChevronDown, XCircle } from 'react-native-feather' interface RightButtonProps { inputHeight?: number onClearPress?: () => void onChevronPress?: () => void isOpened?: boolean showChevron?: boolean showClear?: boolean loading?: boolean enableLoadingIndicator?: boolean buttonsContainerStyle?: StyleProp ChevronIconComponent?: React.ReactNode ClearIconComponent?: React.ReactNode RightIconComponent?: React.ReactNode onRightIconComponentPress?: () => void } export const RightButton: React.FC = memo( ({ inputHeight, onClearPress, onChevronPress, isOpened, showChevron, showClear, loading, enableLoadingIndicator, buttonsContainerStyle, ChevronIconComponent, ClearIconComponent, RightIconComponent, onRightIconComponentPress, }) => { const isOpenedAnimationValue = useRef(new Animated.Value(0)).current useEffect(() => { Animated.timing(isOpenedAnimationValue, { duration: 350, toValue: isOpened ? 1 : 0, useNativeDriver: true, easing: Easing.bezier(0.3, 0.58, 0.25, 0.99), }).start() }, [isOpened, isOpenedAnimationValue]) const chevronSpin = isOpenedAnimationValue.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '180deg'], }) return ( {(!enableLoadingIndicator || !loading) && showClear && ( {ClearIconComponent ?? } )} {enableLoadingIndicator && loading && } {RightIconComponent && ( {RightIconComponent} )} {showChevron && ( {ChevronIconComponent ?? } )} ) }, ) const styles = StyleSheet.create({ container: { position: 'relative', flex: 0, flexDirection: 'row', right: 8, zIndex: 10, justifyContent: 'center', alignItems: 'center', backgroundColor: 'transparent', }, clearButton: { width: 26, alignItems: 'center', }, chevronButton: { width: 26, alignItems: 'center', height: '100%', justifyContent: 'center', }, })