diff --git a/components/GroupAvatarSvg.tsx b/components/GroupAvatarSvg.tsx index e7f64aa65..90bcbb4d6 100644 --- a/components/GroupAvatarSvg.tsx +++ b/components/GroupAvatarSvg.tsx @@ -1,6 +1,6 @@ import { actionSecondaryColor, textSecondaryColor } from "@styles/colors"; import { AvatarSizes } from "@styles/sizes"; -import React, { useMemo, useState, useEffect } from "react"; +import React, { useMemo, useState } from "react"; import { useColorScheme, StyleProp, ViewStyle, Image } from "react-native"; import Svg, { Circle, @@ -61,33 +61,16 @@ const SafeSvgImage: React.FC<{ size: number; clipPath: string; }> = ({ uri, x, y, size, clipPath }) => { - const [didError, setDidError] = useState(false); - - useEffect(() => { - let isMounted = true; - - Image.getSize( - uri, - () => { - if (isMounted) { - setDidError(false); - } - }, - () => { - if (isMounted) { - setDidError(true); - } - } - ); - - return () => { - isMounted = false; - }; - }, [uri]); + const [isLoaded, setIsLoaded] = useState(false); return ( <> - {!didError && ( + setIsLoaded(true)} + /> + {isLoaded && ( = ({ [memberCount] ); + const renderMemberAvatar = ( + member: { uri?: string; name?: string }, + pos: { x: number; y: number; size: number }, + index: number + ) => { + const firstLetter = member.name ? member.name.charAt(0).toUpperCase() : ""; + + const placeholderAvatar = ( + + + + {firstLetter} + + + ); + + if (member.uri) { + return ( + + + {placeholderAvatar} + + ); + } + + return placeholderAvatar; + }; + return ( @@ -136,44 +170,7 @@ const GroupAvatarSvg: React.FC = ({ {positions.map((pos, index) => { if (index < 4 && index < memberCount) { - const member = members[index]; - const firstLetter = member.name - ? member.name.charAt(0).toUpperCase() - : ""; - return member.uri ? ( - - ) : ( - - - - {firstLetter} - - - ); + return renderMemberAvatar(members[index], pos, index); } else if (index === 4 && memberCount > 4) { const extraMembersCount = memberCount - 4; return (