import throttle from "lodash/throttle"; import { useCallback } from "react"; import { StyleSheet, TouchableOpacity, View, ViewStyle } from "react-native"; import { GenericActionPayload } from "../../App/common/actions/GenericAction"; import { CtaData } from "../../App/common/interface"; import { TitleWithAssetsWidgetData } from "../../App/common/interface/widgets/widgetData/TitleWithAssetsWidgetData"; import Colors from "../../assets/colors/colors"; import { StyledImage } from "../StyledImage"; import { StyledLottie } from "./styled-lottie/StyledLottie"; import { StyledText } from "./styled-text/StyledText"; const TitleWithAssetsWidget = ({ widgetData, widgetStyle, handleActions, widgetIndex, handleClick, }: { widgetData: TitleWithAssetsWidgetData; widgetStyle: ViewStyle; handleActions: ( value?: any | undefined | null, actionPayload?: GenericActionPayload, ) => void; widgetIndex?: number; handleClick?: (ctaData: CtaData) => void; }) => { const throttledHandleActions = useCallback( throttle(() => handleActions(null, widgetData?.actions), 700, { leading: true, trailing: false, }), [widgetData], ); return ( { const { cta, actions } = widgetData || {}; if (actions && throttledHandleActions) { throttledHandleActions(); } else if (cta && handleClick) { handleClick(cta); } }} activeOpacity={1} > {widgetData?.leftIcon && ( )} {widgetData?.leftLottie && ( )} {widgetData?.title && ( )} {widgetData?.rightIcon && ( )} {widgetData?.rightLottie && ( )} ); }; const styles = StyleSheet.create({ container: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", borderWidth: 1, borderColor: Colors.hawkesBlue, borderRadius: 32, paddingHorizontal: 16, paddingVertical: 9, backgroundColor: Colors.powderBlue, }, }); export default TitleWithAssetsWidget;