[FIX] Link preview with embed image
This commit is contained in:
parent
a8b3a3b7de
commit
c7d2f306c5
|
@ -94,6 +94,11 @@ const UrlContent = React.memo(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isImage = (url: string) => {
|
||||||
|
const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/);
|
||||||
|
return regExpUrlImage.test(url);
|
||||||
|
};
|
||||||
|
|
||||||
const Url = React.memo(
|
const Url = React.memo(
|
||||||
({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => {
|
({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => {
|
||||||
if (!url || url?.ignoreParse) {
|
if (!url || url?.ignoreParse) {
|
||||||
|
@ -107,6 +112,14 @@ const Url = React.memo(
|
||||||
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let imageUrl;
|
||||||
|
|
||||||
|
if (url.image) {
|
||||||
|
imageUrl = url.image;
|
||||||
|
} else {
|
||||||
|
imageUrl = isImage(url.url) ? url.url : '';
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Touchable
|
<Touchable
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
|
@ -123,8 +136,8 @@ const Url = React.memo(
|
||||||
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<UrlImage image={url.image} />
|
<UrlImage image={imageUrl} />
|
||||||
<UrlContent title={url.title} description={url.description} theme={theme} />
|
{url.title || url.description ? <UrlContent title={url.title} description={url.description} theme={theme} /> : null}
|
||||||
</>
|
</>
|
||||||
</Touchable>
|
</Touchable>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue