2024-03-27 20:36:03 +05:30
|
|
|
import React from "react";
|
|
|
|
|
import { ImageFieldData } from "../App/common/interface/widgets/widgetData/TitleWidgetData";
|
2024-10-24 11:52:11 +05:30
|
|
|
import { Image, TouchableOpacity } from "react-native";
|
2024-03-27 20:36:03 +05:30
|
|
|
import { CtaData } from "../App/common/interface";
|
2024-09-24 23:09:17 +05:30
|
|
|
import { GenericActionPayload } from "../App/common/actions/GenericAction";
|
2024-03-27 20:36:03 +05:30
|
|
|
|
|
|
|
|
export const StyledImage = ({
|
|
|
|
|
imageFieldData,
|
|
|
|
|
handleClick,
|
2024-09-24 23:09:17 +05:30
|
|
|
handleActions,
|
2024-03-27 20:36:03 +05:30
|
|
|
}: {
|
|
|
|
|
imageFieldData: ImageFieldData;
|
|
|
|
|
handleClick?: (ctaData: CtaData) => void;
|
2024-09-24 23:09:17 +05:30
|
|
|
handleActions?: (
|
|
|
|
|
value: any | undefined | null,
|
|
|
|
|
actionPayloadList: GenericActionPayload | undefined,
|
|
|
|
|
) => void;
|
2024-03-27 20:36:03 +05:30
|
|
|
}) => {
|
2024-05-07 12:21:20 +05:30
|
|
|
if (!imageFieldData?.url) return <></>;
|
|
|
|
|
|
2024-09-24 23:09:17 +05:30
|
|
|
const { cta, actions } = imageFieldData;
|
|
|
|
|
|
2024-09-27 17:47:46 +05:30
|
|
|
const isInteractive = (cta && handleClick) || (actions && handleActions);
|
|
|
|
|
|
2024-09-24 23:09:17 +05:30
|
|
|
const handleImageClick = () => {
|
|
|
|
|
if (actions && handleActions) {
|
|
|
|
|
handleActions(null, actions);
|
|
|
|
|
} else if (cta && handleClick) {
|
|
|
|
|
handleClick(cta);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-27 17:47:46 +05:30
|
|
|
return isInteractive ? (
|
|
|
|
|
<TouchableOpacity activeOpacity={1} onPress={handleImageClick}>
|
2024-03-27 20:36:03 +05:30
|
|
|
<Image
|
|
|
|
|
source={{ uri: imageFieldData?.url }}
|
|
|
|
|
style={imageFieldData?.imageStyle}
|
|
|
|
|
/>
|
|
|
|
|
</TouchableOpacity>
|
2024-09-27 17:47:46 +05:30
|
|
|
) : (
|
|
|
|
|
<Image
|
|
|
|
|
source={{ uri: imageFieldData?.url }}
|
|
|
|
|
style={imageFieldData?.imageStyle}
|
|
|
|
|
/>
|
2024-03-27 20:36:03 +05:30
|
|
|
);
|
|
|
|
|
};
|