import { useEffect, useState, type FC, useRef } from "react"; import { TouchableWithoutFeedback, type ViewStyle, Animated, Easing, View } from "react-native"; import type ITooltipProps from "./type"; import stylesheet, { getTooltipType, useStyles } from "./stylesheet"; import { NCoreUIKitTheme } from "../../core/hooks"; import { X as XIcon } from "lucide-react-native"; import Button from "../button"; import Text from "../text"; const Tooltip: FC = ({ isCloseOnPressActionButton = true, location = { horizontal: "center", vertical: "top" }, isCloseOnPress = false, icon: CustomIcon, type = "neutral", customTheme, isVisible, onClosed, subTitle, children, onClose, onOpen, content, action, style, title }) => { const { radiuses, colors, spaces } = NCoreUIKitTheme.useContext(customTheme); const [ wrapperSize, setWrapperSize ] = useState({ height: 0, width: 0 }); const [ tooltipSize, setTooltipSize ] = useState({ height: 0, width: 0 }); const [ isInternalVisible, setIsInternalVisible ] = useState(false); const opacityAnim = useRef(new Animated.Value(0)).current; const currentType = getTooltipType({ type }); const { containerObject: containerObjectDynamicStyle, contentContainer: contentContainerDynamicStyle, iconContainer: iconContainerDynamicStyle, container: containerDynamicStyle, subTitle: subTitleDynamicStyle, action: actionDynamicStyle, title: titleDynamicStyle, caret: caretDynamicStyle } = useStyles({ currentType, radiuses, colors, spaces, type }); const isShow = isVisible !== undefined ? isVisible : isInternalVisible; useEffect(() => { if(isShow) { if(onOpen) onOpen(); Animated.timing(opacityAnim, { useNativeDriver: true, easing: Easing.linear, duration: 200, toValue: 1 }).start(); } else { Animated.timing(opacityAnim, { useNativeDriver: true, easing: Easing.linear, duration: 200, toValue: 0 }).start(({ finished }) => { if(finished && onClosed) { onClosed(); } }); } }, [ isShow ]); const handleClose = () => { if(isVisible === undefined) { setIsInternalVisible(false); } if(onClose) onClose(); }; const handleToggle = () => { if(isVisible === undefined) { setIsInternalVisible(!isInternalVisible); } if(!isShow && onOpen) { onOpen(); } else if (isShow && onClose) { onClose(); } }; const renderIcon = () => { if(!CustomIcon) { return null; } return ; }; const renderContent = () => { if(content) { if(typeof content === "function") { return content(); } return content; } return { title ? {title} : null } { subTitle ? {subTitle} : null } ; }; const renderAction = () => { if(!action) { return null; } return