Skip to content

Commit 0e3c003

Browse files
authored
Merge pull request #1387 from GetStream/Enigma-I-am/link-preview-component
fix: consistent link preview component
2 parents 066d08a + 08d5799 commit 0e3c003

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

package/src/components/Attachment/Card.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import {
3-
Image,
3+
ImageBackground,
44
ImageStyle,
55
StyleProp,
66
StyleSheet,
@@ -24,6 +24,7 @@ import {
2424
useMessagesContext,
2525
} from '../../contexts/messagesContext/MessagesContext';
2626
import { useTheme } from '../../contexts/themeContext/ThemeContext';
27+
import { Play } from '../../icons/Play';
2728
import type { DefaultStreamChatGenerics } from '../../types/types';
2829
import { makeImageCompatibleUrl } from '../../utils/utils';
2930

@@ -41,13 +42,15 @@ const styles = StyleSheet.create({
4142
},
4243
authorNameMask: {
4344
bottom: 0,
44-
left: 8,
45+
left: 2,
4546
position: 'absolute',
4647
},
4748
cardCover: {
49+
alignItems: 'center',
4850
borderRadius: 8,
4951
height: 140,
50-
marginHorizontal: 8,
52+
justifyContent: 'center',
53+
marginHorizontal: 2,
5154
},
5255
cardFooter: {
5356
flexDirection: 'row',
@@ -62,6 +65,14 @@ const styles = StyleSheet.create({
6265
fontSize: 12,
6366
marginHorizontal: 8,
6467
},
68+
playButtonStyle: {
69+
alignItems: 'center',
70+
borderRadius: 50,
71+
elevation: 2,
72+
height: 36,
73+
justifyContent: 'center',
74+
width: 36,
75+
},
6576
title: {
6677
fontSize: 12,
6778
marginHorizontal: 8,
@@ -116,11 +127,12 @@ const CardWithContext = <
116127
text,
117128
thumb_url,
118129
title,
130+
type,
119131
} = props;
120132

121133
const {
122134
theme: {
123-
colors: { accent_blue, black, blue_alice, transparent },
135+
colors: { accent_blue, black, blue_alice, transparent, white },
124136
messageSimple: {
125137
card: {
126138
authorName,
@@ -132,6 +144,8 @@ const CardWithContext = <
132144
cover,
133145
footer: { description, title: titleStyle, ...footerStyle },
134146
noURI,
147+
playButtonStyle: { roundedView },
148+
playIcon: { height, width },
135149
},
136150
},
137151
},
@@ -141,6 +155,8 @@ const CardWithContext = <
141155

142156
const defaultOnPress = () => openUrlSafely(og_scrape_url || uri);
143157

158+
const isVideoCard = type === 'video' && og_scrape_url;
159+
144160
return (
145161
<TouchableOpacity
146162
disabled={preventPress}
@@ -181,11 +197,18 @@ const CardWithContext = <
181197
{CardCover && <CardCover {...props} />}
182198
{uri && !CardCover && (
183199
<View>
184-
<Image
200+
<ImageBackground
201+
imageStyle={styles.cardCover}
185202
resizeMode='cover'
186203
source={{ uri: makeImageCompatibleUrl(uri) }}
187204
style={[styles.cardCover, cover, stylesProp.cardCover]}
188-
/>
205+
>
206+
{isVideoCard ? (
207+
<View style={[styles.playButtonStyle, roundedView, { backgroundColor: white }]}>
208+
<Play height={height} pathFill={black} width={width} />
209+
</View>
210+
) : null}
211+
</ImageBackground>
189212
{author_name && (
190213
<View style={[styles.authorNameMask, authorNameMask, stylesProp.authorNameMask]}>
191214
<View

package/src/components/Reply/Reply.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ const getMessageType = <
8888

8989
const isLastAttachmentVideo = lastAttachment.type === 'video';
9090

91-
const isLastAttachmentGiphy = lastAttachment.type === 'giphy' || lastAttachment.type === 'imgur';
91+
const isLastAttachmentGiphy =
92+
lastAttachment?.type === 'giphy' || lastAttachment?.type === 'imgur';
9293

9394
const isLastAttachmentImageOrGiphy =
94-
lastAttachment.type === 'image' && !lastAttachment.title_link && !lastAttachment.og_scrape_url;
95+
lastAttachment?.type === 'image' &&
96+
!lastAttachment?.title_link &&
97+
!lastAttachment?.og_scrape_url;
9598

96-
const isLastAttachmentImage = lastAttachment.image_url || lastAttachment.thumb_url;
99+
const isLastAttachmentImage = lastAttachment?.image_url || lastAttachment?.thumb_url;
97100

98101
if (isLastAttachmentFile) {
99102
messageType = 'file';

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ export type Theme = {
377377
title: TextStyle;
378378
};
379379
noURI: ViewStyle;
380+
playButtonStyle: {
381+
durationTextStyle: TextStyle;
382+
roundedView: ViewStyle;
383+
videoContainer: ViewStyle;
384+
};
385+
playIcon: IconProps;
380386
};
381387
container: ViewStyle;
382388
content: {
@@ -859,6 +865,15 @@ export const defaultTheme: Theme = {
859865
borderLeftWidth: 2,
860866
paddingLeft: 8,
861867
},
868+
playButtonStyle: {
869+
durationTextStyle: {},
870+
roundedView: {},
871+
videoContainer: {},
872+
},
873+
playIcon: {
874+
height: 24,
875+
width: 24,
876+
},
862877
},
863878
container: {},
864879
content: {

0 commit comments

Comments
 (0)