Compare commits

...

18 Commits

Author SHA1 Message Date
Reinaldo Neto 87f88c5b52 merge urlimage inside url 2023-03-07 11:26:21 -03:00
Reinaldo Neto 251223a0c9 remove react memo from urlImage 2023-03-07 11:15:17 -03:00
Reinaldo Neto 0c14716815 minor tweak, pass hasContent and imageLoadedState instead of style 2023-03-06 22:38:00 -03:00
Reinaldo Neto 249a056b7d update storyshot 2023-02-15 20:13:59 -03:00
Reinaldo Neto 34c2c14b03 refactor 2023-02-15 20:11:03 -03:00
Reinaldo Neto 75ca62c3c4 keep the same behavior for android and ios 2023-01-25 00:06:09 -03:00
Reinaldo Neto 6a7da14fdd
Merge branch 'develop' into fix.link-preview 2023-01-24 22:43:03 -03:00
Reinaldo Neto d1c288a702 update tests 2023-01-17 20:49:45 -03:00
Reinaldo Neto 986acfd0fc refactor how to test if it's an image 2023-01-17 17:57:22 -03:00
Reinaldo Neto 2c1a412fce fix the MessageURl showing when there isn't hasContent or imageUrl 2023-01-11 17:07:43 -03:00
Reinaldo Neto ae0a218a7a image test 2023-01-03 22:00:20 -03:00
Reinaldo Neto f891eea9b9
Merge branch 'develop' into fix.link-preview 2023-01-03 13:56:50 -03:00
Reinaldo Neto 8843b4aa6a minor tweak 2022-12-19 16:23:16 -03:00
Reinaldo Neto f829807092 refactor and added test 2022-12-19 16:06:06 -03:00
Reinaldo Neto 257489d85c refactor the location 2022-12-19 12:34:47 -03:00
Reinaldo Neto b3e028ce24
Merge branch 'develop' into fix.link-preview 2022-12-19 12:12:28 -03:00
Reinaldo Neto 87d0b6173c
Merge branch 'develop' into fix.link-preview 2022-12-06 11:54:05 -03:00
Reinaldo Neto c7d2f306c5 [FIX] Link preview with embed image 2022-12-01 19:44:44 -03:00
3 changed files with 58 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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';