import { ReactNode, useMemo } from "react"; import { Image, ImageSourcePropType, ImageURISource, StyleSheet } from "react-native"; import { useIOTheme } from "../../context"; import { IOListItemVisualParams, IOSelectionListItemVisualParams, IOSpacer, IOVisualCostants } from "../../core"; import { useIOFontDynamicScale } from "../../utils/accessibility"; import { WithTestID } from "../../utils/types"; import { Badge } from "../badge"; import { IOIcons, Icon } from "../icons"; import { HSpacer } from "../layout"; import { HStack } from "../layout/Stack"; import { LoadingSpinner } from "../loadingSpinner"; import { IOSkeleton } from "../skeleton"; import { BodySmall } from "../typography"; import { ModuleStatic } from "./ModuleStatic"; import { PressableModuleBase, PressableModuleBaseProps } from "./PressableModuleBase"; type ImageProps = | { icon: IOIcons; image?: never } | { icon?: never; image: ImageURISource | ImageSourcePropType } | { icon?: never; image?: never }; type LoadingModuleProps = { isLoading: true; loadingAccessibilityLabel?: string; }; type BaseModuleProps = { isLoading?: false; label: string; badge?: Badge; isFetching?: boolean; }; type ModuleCredentialProps = | BaseModuleProps & ImageProps & PressableModuleBaseProps; const ModuleCredential = ( props: WithTestID ) => props.isLoading ? ( ) : ( ); const ModuleContent = ({ icon, image, label, endComponent }: Pick & Pick & { endComponent: ReactNode; }) => { const theme = useIOTheme(); const { hugeFontEnabled } = useIOFontDynamicScale(); return ( {/* Graphical assets */} {icon && !hugeFontEnabled ? ( ) : ( image && ( ) )} {label} {endComponent} ); }; const ModuleCredentialContent = ({ testID, icon, image, label, onPress, badge, isFetching, ...pressableProps }: WithTestID) => { const theme = useIOTheme(); const endComponent = useMemo(() => { const activityIndicatorTestID = testID ? `${testID}_activityIndicator` : undefined; const chevronTestID = testID ? `${testID}_icon` : undefined; const badgeTestID = testID ? `${testID}_badge` : undefined; return badge || onPress ? ( {badge && } {onPress && (isFetching ? ( <> ) : ( ))} ) : null; }, [testID, theme, isFetching, badge, onPress]); return onPress ? ( ) : ( ); }; const ModuleCredentialSkeleton = ({ loadingAccessibilityLabel }: Pick) => ( } endBlock={ } /> ); const styles = StyleSheet.create({ image: { width: IOSelectionListItemVisualParams.iconSize, height: IOSelectionListItemVisualParams.iconSize, resizeMode: "contain" } }); export { ModuleCredential };