feat: fix bug in icons (#29)

This commit is contained in:
IZUMI-Zu 2024-09-29 17:25:40 +08:00 committed by GitHub
parent beb492e540
commit a1295e09ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 21 deletions

View File

@ -12,31 +12,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import React, {useState} from "react";
import {View} from "react-native";
import React from "react";
import {Image} from "expo-image";
const AvatarWithFallback = ({source, fallbackSource, size, style}) => {
const [hasError, setHasError] = useState(false);
const handleImageError = () => {
if (!hasError) {
setHasError(true);
}
};
function AvatarWithFallback({source, fallbackSource, size, style}) {
const [imageSource, setImageSource] = React.useState(source);
return (
<View style={{overflow: "hidden", borderRadius: 9999, width: size, height: size, ...style}}>
<Image
style={{width: "100%", height: "100%"}}
source={hasError ? fallbackSource : source}
onError={handleImageError}
style={{
overflow: "hidden",
borderRadius: 9999,
width: size,
height: size,
...style,
}}
source={imageSource}
onError={() => setImageSource(fallbackSource)}
placeholder={fallbackSource}
placeholderContentFit="cover"
contentFit="cover"
transition={300}
cachePolicy={"memory-disk"}
cachePolicy="memory-disk"
/>
</View>
);
};
}
export default AvatarWithFallback;