Skip to content

Commit af727cd

Browse files
Refactor Avatar component to include conditional rendering for image display (#682)
- Updated Avatar component to render the Animated.Image only when imageUrl is provided, enhancing performance and preventing unnecessary rendering. - Adjusted import statements for Container and Typography components for better modularity.
1 parent 6267216 commit af727cd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: src/components/Avatar.jsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Animated, {
1010
} from "react-native-reanimated";
1111
import { moderateScale } from "react-native-size-matters";
1212

13-
import { Typography, Container } from "@components";
13+
import { Container } from "./Container";
14+
import { Typography } from "./Typography";
1415

1516
/**
1617
* Avatars can be used to represent people in a graphical way.
@@ -97,12 +98,14 @@ export const Avatar = ({
9798
{acronym.toUpperCase()}
9899
</Typography>
99100
</Container>
100-
<Animated.Image
101-
source={{ uri: imageUrl }}
102-
style={profileImageStyle}
103-
onLoad={() => (opacity.value = 1)}
104-
{...rest}
105-
/>
101+
{imageUrl && (
102+
<Animated.Image
103+
source={{ uri: imageUrl }}
104+
style={profileImageStyle}
105+
onLoad={() => (opacity.value = 1)}
106+
{...rest}
107+
/>
108+
)}
106109
</Container>
107110
);
108111
};

0 commit comments

Comments
 (0)