Compare commits
18 Commits
develop
...
fix.link-p
Author | SHA1 | Date |
---|---|---|
Reinaldo Neto | 87f88c5b52 | |
Reinaldo Neto | 251223a0c9 | |
Reinaldo Neto | 0c14716815 | |
Reinaldo Neto | 249a056b7d | |
Reinaldo Neto | 34c2c14b03 | |
Reinaldo Neto | 75ca62c3c4 | |
Reinaldo Neto | 6a7da14fdd | |
Reinaldo Neto | d1c288a702 | |
Reinaldo Neto | 986acfd0fc | |
Reinaldo Neto | 2c1a412fce | |
Reinaldo Neto | ae0a218a7a | |
Reinaldo Neto | f891eea9b9 | |
Reinaldo Neto | 8843b4aa6a | |
Reinaldo Neto | f829807092 | |
Reinaldo Neto | 257489d85c | |
Reinaldo Neto | b3e028ce24 | |
Reinaldo Neto | 87d0b6173c | |
Reinaldo Neto | c7d2f306c5 |
File diff suppressed because one or more lines are too long
|
@ -634,6 +634,28 @@ export const URL = () => (
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const URLImagePreview = () => (
|
||||||
|
<>
|
||||||
|
<Message
|
||||||
|
urls={[
|
||||||
|
{
|
||||||
|
url: 'https://www.google.com/logos/doodles/2022/seasonal-holidays-2022-6753651837109831.4-law.gif',
|
||||||
|
title: 'Google',
|
||||||
|
description:
|
||||||
|
"Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for."
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Message
|
||||||
|
urls={[
|
||||||
|
{
|
||||||
|
url: 'https://www.google.com/logos/doodles/2022/seasonal-holidays-2022-6753651837109831.4-law.gif'
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
export const CustomFields = () => (
|
export const CustomFields = () => (
|
||||||
<>
|
<>
|
||||||
<Message
|
<Message
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useContext } from 'react';
|
import React, { useContext, useState } from 'react';
|
||||||
import { StyleSheet, Text, View } from 'react-native';
|
import { StyleSheet, Text, View } from 'react-native';
|
||||||
import Clipboard from '@react-native-clipboard/clipboard';
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
import FastImage from 'react-native-fast-image';
|
import FastImage from 'react-native-fast-image';
|
||||||
|
@ -48,23 +48,16 @@ const styles = StyleSheet.create({
|
||||||
height: 150,
|
height: 150,
|
||||||
borderTopLeftRadius: 4,
|
borderTopLeftRadius: 4,
|
||||||
borderTopRightRadius: 4
|
borderTopRightRadius: 4
|
||||||
|
},
|
||||||
|
imageWithoutContent: {
|
||||||
|
borderRadius: 4
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
height: 0,
|
||||||
|
borderWidth: 0
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const UrlImage = React.memo(
|
|
||||||
({ image }: { image: string }) => {
|
|
||||||
const { baseUrl, user } = useContext(MessageContext);
|
|
||||||
|
|
||||||
if (!image) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
image = image.includes('http') ? image : `${baseUrl}/${image}?rc_uid=${user.id}&rc_token=${user.token}`;
|
|
||||||
return <FastImage source={{ uri: image }} style={styles.image} resizeMode={FastImage.resizeMode.cover} />;
|
|
||||||
},
|
|
||||||
(prevProps, nextProps) => prevProps.image === nextProps.image
|
|
||||||
);
|
|
||||||
|
|
||||||
const UrlContent = React.memo(
|
const UrlContent = React.memo(
|
||||||
({ title, description, theme }: { title: string; description: string; theme: TSupportedThemes }) => (
|
({ title, description, theme }: { title: string; description: string; theme: TSupportedThemes }) => (
|
||||||
<View style={styles.textContainer}>
|
<View style={styles.textContainer}>
|
||||||
|
@ -94,9 +87,14 @@ const UrlContent = React.memo(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type TImageLoadedState = 'loading' | 'done' | 'error';
|
||||||
|
|
||||||
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) {
|
const [imageLoadedState, setImageLoadedState] = useState<TImageLoadedState>('loading');
|
||||||
|
const { baseUrl, user } = useContext(MessageContext);
|
||||||
|
|
||||||
|
if (!url || url?.ignoreParse || imageLoadedState === 'error') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +105,13 @@ const Url = React.memo(
|
||||||
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasContent = url.title || url.description;
|
||||||
|
|
||||||
|
let image = url.image || url.url;
|
||||||
|
if (image) {
|
||||||
|
image = image.includes('http') ? image : `${baseUrl}/${image}?rc_uid=${user.id}&rc_token=${user.token}`;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Touchable
|
<Touchable
|
||||||
onPress={onPress}
|
onPress={onPress}
|
||||||
|
@ -118,13 +123,22 @@ const Url = React.memo(
|
||||||
{
|
{
|
||||||
backgroundColor: themes[theme].chatComponentBackground,
|
backgroundColor: themes[theme].chatComponentBackground,
|
||||||
borderColor: themes[theme].borderColor
|
borderColor: themes[theme].borderColor
|
||||||
}
|
},
|
||||||
|
imageLoadedState === 'loading' && styles.loading
|
||||||
]}
|
]}
|
||||||
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<UrlImage image={url.image} />
|
{image ? (
|
||||||
<UrlContent title={url.title} description={url.description} theme={theme} />
|
<FastImage
|
||||||
|
source={{ uri: image }}
|
||||||
|
style={[styles.image, !hasContent && styles.imageWithoutContent, imageLoadedState === 'loading' && styles.loading]}
|
||||||
|
resizeMode={FastImage.resizeMode.cover}
|
||||||
|
onError={() => setImageLoadedState('error')}
|
||||||
|
onLoad={() => setImageLoadedState('done')}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{hasContent ? <UrlContent title={url.title} description={url.description} theme={theme} /> : null}
|
||||||
</>
|
</>
|
||||||
</Touchable>
|
</Touchable>
|
||||||
);
|
);
|
||||||
|
@ -146,7 +160,6 @@ const Urls = React.memo(
|
||||||
(oldProps, newProps) => dequal(oldProps.urls, newProps.urls)
|
(oldProps, newProps) => dequal(oldProps.urls, newProps.urls)
|
||||||
);
|
);
|
||||||
|
|
||||||
UrlImage.displayName = 'MessageUrlImage';
|
|
||||||
UrlContent.displayName = 'MessageUrlContent';
|
UrlContent.displayName = 'MessageUrlContent';
|
||||||
Url.displayName = 'MessageUrl';
|
Url.displayName = 'MessageUrl';
|
||||||
Urls.displayName = 'MessageUrls';
|
Urls.displayName = 'MessageUrls';
|
||||||
|
|
Loading…
Reference in New Issue