import { isValidElement, ReactElement } from "react"; import { Image, ImageSourcePropType, ImageURISource, StyleSheet, View } from "react-native"; import { SvgProps } from "react-native-svg"; import { useIOTheme } from "../../context"; import { IOColors, IOListItemVisualParams, IOSpacer, IOVisualCostants } from "../../core"; import { useIOFontDynamicScale } from "../../utils/accessibility"; import { WithTestID } from "../../utils/types"; import { Badge } from "../badge"; import { IOIconSizeScale, IOIcons, Icon } from "../icons"; import { HStack, VStack } from "../layout"; import { LoadingSpinner } from "../loadingSpinner"; import { IOSkeleton } from "../skeleton"; import { BodySmall, LabelMini } from "../typography"; import { ModuleStatic } from "./ModuleStatic"; import { PressableModuleBase, PressableModuleBaseProps } from "./PressableModuleBase"; type LoadingProps = { isLoading: true; loadingAccessibilityLabel?: string; }; type ImageProps = | { icon: IOIcons; image?: never } | { icon?: never; image: ImageURISource | ImageSourcePropType | ReactElement; }; type BaseProps = { isLoading?: false; title: string; subtitle?: string; badge?: Badge; isFetching?: boolean; rightIcon?: IOIcons; iconColor?: IOColors; } & ImageProps & PressableModuleBaseProps; type ModuleNavigationAltProps = LoadingProps | BaseProps; export const ModuleNavigationAlt = ( props: WithTestID ) => { const theme = useIOTheme(); const { hugeFontEnabled } = useIOFontDynamicScale(); const graphicWrapperSize: IOIconSizeScale = 48; if (props.isLoading) { return ( ); } const { testID, icon, iconColor = theme["interactiveElem-default"], image, title, subtitle, onPress, badge, isFetching, rightIcon, ...pressableProps } = props; const iconComponent = icon && ( ); const imageComponent = () => { if (!image) { return null; } if (isValidElement(image)) { return image; } else { return ( ); } }; const endComponent = () => { if (isFetching) { return ( ); } if (onPress) { return ( ); } return null; }; return ( {!hugeFontEnabled && ( {iconComponent ?? imageComponent()} )} {badge ? : null} {title} {subtitle && ( {subtitle} )} {endComponent()} ); }; const ModuleNavigationAltSkeleton = ({ loadingAccessibilityLabel }: Pick) => ( } endBlock={ } /> ); const styles = StyleSheet.create({ image: { width: "100%", height: "auto", resizeMode: "contain" } });