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