import { Colors } from '@/constants/theme'; import { isPromise } from '@/utils/tsutils'; import { ActivityIndicator, Icon } from '@ant-design/react-native'; import { type IconNames } from '@ant-design/react-native/lib/icon'; import { clsx } from 'clsx'; import { Href, Link } from "expo-router"; import React, { useCallback, useEffect, useMemo, useState } from "react"; import { Pressable, Text, View, ViewStyle } from "react-native"; interface UIButtonProps { children?: string | React.ReactNode; title?: string | React.ReactNode; onPress?: () => PromiseLike | unknown; disabled?: boolean; className?: string; textClassName?: string; href?: Href type?: 'primary' | 'second' | 'link' icon?: IconNames | React.ReactNode; style?: ViewStyle; loading?: boolean; } function ButtonTextChild({ type, disabled, textClassName, children, loading }: UIButtonProps) { return loading ? {children} : {children} } export default function UIButton({ onPress, href, type, icon, className, style, disabled, children, title, textClassName, loading }: UIButtonProps) { const [ding, setDing] = useState(loading); useEffect(() => { setDing(loading); }, [loading]) children = children || title; const handlePress = useCallback(() => { const res = onPress?.() as Promise || undefined; if (isPromise(res)) { setDing(true); res.finally(() => { setDing(false); }) } }, []); const inner = useMemo(() => {typeof icon === 'string' ? : icon} {typeof children == 'string' ? {children} : children} , [children, className, disabled, icon, onPress, style, textClassName, type]) if (typeof href !== 'undefined') { return {inner} } return inner; }