@@ -18,7 +18,15 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
1818import { makeImageCompatibleUrl } from '../../utils/utils' ;
1919
2020const styles = StyleSheet . create ( {
21- buttonContainer : { alignItems : 'center' , borderTopWidth : 1 , flex : 1 , justifyContent : 'center' } ,
21+ actionsRow : {
22+ flexDirection : 'row' ,
23+ } ,
24+ buttonContainer : {
25+ alignItems : 'center' ,
26+ borderTopWidth : 1 ,
27+ flex : 1 ,
28+ justifyContent : 'center' ,
29+ } ,
2230 cancel : {
2331 fontSize : 14 ,
2432 fontWeight : '600' ,
@@ -29,8 +37,10 @@ const styles = StyleSheet.create({
2937 width : 270 ,
3038 } ,
3139 giphy : {
40+ alignSelf : 'center' ,
3241 borderRadius : 2 ,
3342 height : 170 ,
43+ maxWidth : 270 ,
3444 width : 270 ,
3545 } ,
3646 giphyContainer : {
@@ -53,7 +63,10 @@ const styles = StyleSheet.create({
5363 left : 8 ,
5464 position : 'absolute' ,
5565 } ,
56- giphyMaskText : { fontSize : 13 , fontWeight : '600' } ,
66+ giphyMaskText : {
67+ fontSize : 13 ,
68+ fontWeight : '600' ,
69+ } ,
5770 header : {
5871 alignItems : 'center' ,
5972 display : 'flex' ,
@@ -62,16 +75,16 @@ const styles = StyleSheet.create({
6275 padding : 8 ,
6376 width : '60%' ,
6477 } ,
65- margin : {
66- margin : 1 ,
67- } ,
68- row : { flexDirection : 'row' } ,
6978 selectionContainer : {
7079 borderBottomLeftRadius : 8 ,
7180 borderWidth : 1 ,
7281 overflow : 'hidden' ,
7382 width : 272 ,
7483 } ,
84+ selectionImageContainer : {
85+ alignSelf : 'center' ,
86+ margin : 1 ,
87+ } ,
7588 send : {
7689 fontSize : 14 ,
7790 fontWeight : '600' ,
@@ -98,7 +111,7 @@ export type GiphyPropsWithContext<
98111 MessageContextValue < StreamChatGenerics > ,
99112 'handleAction' | 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
100113> &
101- Pick < MessagesContextValue < StreamChatGenerics > , 'additionalTouchableProps' > & {
114+ Pick < MessagesContextValue < StreamChatGenerics > , 'giphyVersion' | ' additionalTouchableProps'> & {
102115 attachment : Attachment < StreamChatGenerics > ;
103116 } ;
104117
@@ -117,11 +130,11 @@ const GiphyWithContext = <
117130 preventPress,
118131 } = props ;
119132
120- const { actions, image_url, thumb_url, title, type } = attachment ;
133+ const { actions, giphy : giphyData , image_url, thumb_url, title, type } = attachment ;
121134
122135 const {
123136 theme : {
124- colors : { accent_blue, black, grey, grey_dark, grey_gainsboro, white } ,
137+ colors : { accent_blue, black, grey, grey_dark, grey_gainsboro, label_bg_transparent , white } ,
125138 messageSimple : {
126139 giphy : {
127140 buttonContainer,
@@ -142,7 +155,15 @@ const GiphyWithContext = <
142155 } ,
143156 } = useTheme ( ) ;
144157
145- const uri = image_url || thumb_url ;
158+ let uri = image_url || thumb_url ;
159+ const giphyDimensions : { height ?: number ; width ?: number } = { } ;
160+
161+ if ( type === 'giphy' && giphyData ) {
162+ const giphyVersionInfo = giphyData [ props . giphyVersion ] ;
163+ uri = giphyVersionInfo . url ;
164+ giphyDimensions . height = parseFloat ( giphyVersionInfo . height ) ;
165+ giphyDimensions . width = parseFloat ( giphyVersionInfo . width ) ;
166+ }
146167
147168 if ( ! uri ) return null ;
148169
@@ -161,15 +182,15 @@ const GiphyWithContext = <
161182 style = { [ styles . giphyHeaderTitle , giphyHeaderTitle , { color : grey_dark } ] }
162183 > { `/giphy ${ title } ` } </ Text >
163184 </ View >
164- < View style = { styles . margin } >
185+ < View style = { styles . selectionImageContainer } >
165186 < Image
166- resizeMode = 'cover '
187+ resizeMode = 'contain '
167188 source = { { uri : makeImageCompatibleUrl ( uri ) } }
168- style = { [ styles . giphy , giphy ] }
189+ style = { [ styles . giphy , giphyDimensions , giphy ] }
169190 />
170191 </ View >
171192 < View >
172- < View style = { styles . row } >
193+ < View style = { styles . actionsRow } >
173194 < TouchableOpacity
174195 onPress = { ( ) => {
175196 if ( actions ?. [ 2 ] . name && actions ?. [ 2 ] . value && handleAction ) {
@@ -238,18 +259,24 @@ const GiphyWithContext = <
238259 } ) ;
239260 }
240261 } }
241- style = { [ styles . container , container ] }
242262 testID = 'giphy-attachment'
243263 { ...additionalTouchableProps }
244264 >
245- < View >
265+ < View style = { [ styles . container , container ] } >
246266 < Image
247- resizeMode = 'cover '
267+ resizeMode = 'contain '
248268 source = { { uri : makeImageCompatibleUrl ( uri ) } }
249- style = { [ styles . giphy , giphy ] }
269+ style = { [ styles . giphy , giphyDimensions , giphy ] }
270+ testID = 'giphy-attachment-image'
250271 />
251272 < View style = { [ styles . giphyMask , giphyMask ] } >
252- < View style = { [ styles . giphyContainer , { backgroundColor : grey_dark } , giphyContainer ] } >
273+ < View
274+ style = { [
275+ styles . giphyContainer ,
276+ { backgroundColor : label_bg_transparent } ,
277+ giphyContainer ,
278+ ] }
279+ >
253280 < Lightning height = { 16 } pathFill = { white } width = { 16 } />
254281 < Text style = { [ styles . giphyMaskText , { color : white } , giphyMaskText ] } >
255282 { type ?. toUpperCase ( ) }
@@ -267,9 +294,11 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
267294) => {
268295 const {
269296 attachment : { actions : prevActions , image_url : prevImageUrl , thumb_url : prevThumbUrl } ,
297+ giphyVersion : prevGiphyVersion ,
270298 } = prevProps ;
271299 const {
272300 attachment : { actions : nextActions , image_url : nextImageUrl , thumb_url : nextThumbUrl } ,
301+ giphyVersion : nextGiphyVersion ,
273302 } = nextProps ;
274303
275304 const imageUrlEqual = prevImageUrl === nextImageUrl ;
@@ -278,6 +307,9 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
278307 const thumbUrlEqual = prevThumbUrl === nextThumbUrl ;
279308 if ( ! thumbUrlEqual ) return false ;
280309
310+ const giphyVersionEqual = prevGiphyVersion === nextGiphyVersion ;
311+ if ( ! giphyVersionEqual ) return false ;
312+
281313 const actionsEqual =
282314 Array . isArray ( prevActions ) === Array . isArray ( nextActions ) &&
283315 ( ( Array . isArray ( prevActions ) &&
@@ -294,8 +326,8 @@ const MemoizedGiphy = React.memo(GiphyWithContext, areEqual) as typeof GiphyWith
294326export type GiphyProps <
295327 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
296328> = Partial <
297- Pick < MessageContextValue < StreamChatGenerics > , 'onLongPress' | 'onPressIn' > &
298- Pick < MessagesContextValue < StreamChatGenerics > , 'additionalTouchableProps' >
329+ Pick < MessageContextValue < StreamChatGenerics > , 'isMyMessage' | ' onLongPress' | 'onPressIn' > &
330+ Pick < MessagesContextValue < StreamChatGenerics > , 'giphyVersion' | ' additionalTouchableProps'>
299331> & {
300332 attachment : Attachment < StreamChatGenerics > ;
301333} ;
@@ -310,12 +342,13 @@ export const Giphy = <
310342) => {
311343 const { handleAction, onLongPress, onPress, onPressIn, preventPress } =
312344 useMessageContext < StreamChatGenerics > ( ) ;
313- const { additionalTouchableProps } = useMessagesContext < StreamChatGenerics > ( ) ;
345+ const { additionalTouchableProps, giphyVersion } = useMessagesContext < StreamChatGenerics > ( ) ;
314346
315347 return (
316348 < MemoizedGiphy
317349 { ...{
318350 additionalTouchableProps,
351+ giphyVersion,
319352 handleAction,
320353 onLongPress,
321354 onPress,
0 commit comments