Skip to content

Commit 762f4f3

Browse files
Merge branch 'master' of github.com:GetStream/stream-chat-react-native into vishal/input-and-messagelist-fix
2 parents e7f3517 + d86a8af commit 762f4f3

34 files changed

+1122
-465
lines changed

src/components/Attachment/Attachment.tsx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
useMessagesContext,
1111
} from '../../contexts/messagesContext/MessagesContext';
1212

13-
import type { GestureResponderEvent } from 'react-native';
1413
import type { Attachment as AttachmentType } from 'stream-chat';
1514

1615
import type {
@@ -47,18 +46,6 @@ export type AttachmentPropsWithContext<
4746
* The attachment to render
4847
*/
4948
attachment: AttachmentType<At>;
50-
/**
51-
* onPress override for all attachments
52-
*/
53-
onPressIn?: MessagesContextValue<
54-
At,
55-
Ch,
56-
Co,
57-
Ev,
58-
Me,
59-
Re,
60-
Us
61-
>['onPressInMessage'];
6249
};
6350

6451
const AttachmentWithContext = <
@@ -79,27 +66,26 @@ const AttachmentWithContext = <
7966
FileAttachment,
8067
Gallery,
8168
Giphy,
82-
onPressIn,
8369
UrlPreview,
8470
} = props;
8571

8672
const hasAttachmentActions = !!attachment.actions?.length;
8773

8874
if (attachment.type === 'giphy' || attachment.type === 'imgur') {
89-
return <Giphy attachment={attachment} onPressIn={onPressIn} />;
75+
return <Giphy attachment={attachment} />;
9076
}
9177

9278
if (
9379
(attachment.title_link || attachment.og_scrape_url) &&
9480
(attachment.image_url || attachment.thumb_url)
9581
) {
96-
return <UrlPreview onPressIn={onPressIn} {...attachment} />;
82+
return <UrlPreview {...attachment} />;
9783
}
9884

9985
if (attachment.type === 'image') {
10086
return (
10187
<>
102-
<Gallery images={[attachment]} onPressIn={onPressIn} />
88+
<Gallery images={[attachment]} />
10389
{hasAttachmentActions && (
10490
<AttachmentActions
10591
key={`key-actions-${attachment.id}`}
@@ -121,22 +107,22 @@ const AttachmentWithContext = <
121107
) {
122108
return (
123109
// TODO: Put in video component
124-
<Card onPressIn={onPressIn} {...attachment} />
110+
<Card {...attachment} />
125111
);
126112
}
127113

128114
if (hasAttachmentActions) {
129115
return (
130116
<>
131-
<Card onPressIn={onPressIn} {...attachment} />
117+
<Card {...attachment} />
132118
<AttachmentActions
133119
key={`key-actions-${attachment.id}`}
134120
{...attachment}
135121
/>
136122
</>
137123
);
138124
} else {
139-
return <Card onPressIn={onPressIn} {...attachment} />;
125+
return <Card {...attachment} />;
140126
}
141127
};
142128

@@ -187,15 +173,7 @@ export type AttachmentProps<
187173
| 'UrlPreview'
188174
>
189175
> &
190-
Pick<AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>, 'attachment'> & {
191-
/**
192-
* onPress override for all attachments
193-
*/
194-
onPressIn?: (
195-
event: GestureResponderEvent,
196-
defaultOnPress?: () => void,
197-
) => void;
198-
};
176+
Pick<AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>, 'attachment'>;
199177

200178
/**
201179
* Attachment - The message attachment
@@ -218,7 +196,6 @@ export const Attachment = <
218196
FileAttachment: PropFileAttachment,
219197
Gallery: PropGallery,
220198
Giphy: PropGiphy,
221-
onPressIn: propOnPressIn,
222199
UrlPreview: PropUrlPreview,
223200
} = props;
224201

@@ -228,7 +205,6 @@ export const Attachment = <
228205
FileAttachment: ContextFileAttachment,
229206
Gallery: ContextGallery,
230207
Giphy: ContextGiphy,
231-
onPressInMessage,
232208
UrlPreview: ContextUrlPreview,
233209
} = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
234210

@@ -245,7 +221,6 @@ export const Attachment = <
245221
PropFileAttachment || ContextFileAttachment || FileAttachmentDefault;
246222
const Gallery = PropGallery || ContextGallery || GalleryDefault;
247223
const Giphy = PropGiphy || ContextGiphy || GiphyDefault;
248-
const onPressIn = propOnPressIn || onPressInMessage;
249224
const UrlPreview = PropUrlPreview || ContextUrlPreview || CardDefault;
250225

251226
return (
@@ -257,7 +232,6 @@ export const Attachment = <
257232
FileAttachment,
258233
Gallery,
259234
Giphy,
260-
onPressIn,
261235
UrlPreview,
262236
}}
263237
/>

src/components/Attachment/Card.tsx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import {
3-
GestureResponderEvent,
43
Image,
54
ImageStyle,
65
Linking,
@@ -98,15 +97,14 @@ export type CardPropsWithContext<
9897
Re extends UnknownType = DefaultReactionType,
9998
Us extends UnknownType = DefaultUserType
10099
> = Attachment<At> &
101-
Pick<MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'onLongPress'> &
100+
Pick<
101+
MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>,
102+
'onLongPress' | 'onPress' | 'onPressIn'
103+
> &
102104
Pick<
103105
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
104106
'additionalTouchableProps' | 'CardCover' | 'CardFooter' | 'CardHeader'
105107
> & {
106-
onPressIn?: (
107-
event: GestureResponderEvent,
108-
defaultOnPress?: () => void,
109-
) => void;
110108
styles?: Partial<{
111109
authorName: StyleProp<TextStyle>;
112110
authorNameContainer: StyleProp<ViewStyle>;
@@ -141,6 +139,7 @@ const CardWithContext = <
141139
image_url,
142140
og_scrape_url,
143141
onLongPress,
142+
onPress,
144143
onPressIn,
145144
styles: stylesProp = {},
146145
text,
@@ -173,15 +172,25 @@ const CardWithContext = <
173172

174173
return (
175174
<TouchableOpacity
176-
onLongPress={onLongPress}
177-
onPress={() => {
178-
if (!onPressIn) {
179-
defaultOnPress();
180-
}
175+
onLongPress={(event) => {
176+
onLongPress({
177+
emitter: 'card',
178+
event,
179+
});
180+
}}
181+
onPress={(event) => {
182+
onPress({
183+
defaultHandler: defaultOnPress,
184+
emitter: 'card',
185+
event,
186+
});
181187
}}
182188
onPressIn={(event) => {
183189
if (onPressIn) {
184-
onPressIn(event, defaultOnPress);
190+
onPressIn({
191+
emitter: 'card',
192+
event,
193+
});
185194
}
186195
}}
187196
style={[styles.container, container, stylesProp.container]}
@@ -300,17 +309,15 @@ export type CardProps<
300309
Us extends UnknownType = DefaultUserType
301310
> = Attachment<At> &
302311
Partial<
303-
Pick<MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'onLongPress'> &
312+
Pick<
313+
MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>,
314+
'onLongPress' | 'onPress' | 'onPressIn'
315+
> &
304316
Pick<
305317
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
306318
'additionalTouchableProps' | 'CardCover' | 'CardFooter' | 'CardHeader'
307319
>
308-
> & {
309-
onPressIn?: (
310-
event: GestureResponderEvent,
311-
defaultOnPress?: () => void,
312-
) => void;
313-
};
320+
>;
314321

315322
/**
316323
* UI component for card in attachments.
@@ -326,13 +333,20 @@ export const Card = <
326333
>(
327334
props: CardProps<At, Ch, Co, Ev, Me, Re, Us>,
328335
) => {
329-
const { onLongPress } = useMessageContext<At, Ch, Co, Ev, Me, Re, Us>();
336+
const { onLongPress, onPress, onPressIn } = useMessageContext<
337+
At,
338+
Ch,
339+
Co,
340+
Ev,
341+
Me,
342+
Re,
343+
Us
344+
>();
330345
const {
331346
additionalTouchableProps,
332347
CardCover,
333348
CardFooter,
334349
CardHeader,
335-
onPressInMessage: onPressIn,
336350
} = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
337351

338352
return (
@@ -343,6 +357,7 @@ export const Card = <
343357
CardFooter,
344358
CardHeader,
345359
onLongPress,
360+
onPress,
346361
onPressIn,
347362
}}
348363
{...props}

src/components/Attachment/FileAttachment.tsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import {
3-
GestureResponderEvent,
43
Linking,
54
StyleProp,
65
StyleSheet,
@@ -65,18 +64,17 @@ export type FileAttachmentPropsWithContext<
6564
Me extends UnknownType = DefaultMessageType,
6665
Re extends UnknownType = DefaultReactionType,
6766
Us extends UnknownType = DefaultUserType
68-
> = Pick<MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'onLongPress'> &
67+
> = Pick<
68+
MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>,
69+
'onLongPress' | 'onPress' | 'onPressIn'
70+
> &
6971
Pick<
7072
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
7173
'additionalTouchableProps' | 'AttachmentActions' | 'FileAttachmentIcon'
7274
> & {
7375
/** The attachment to render */
7476
attachment: Attachment<At>;
7577
attachmentSize?: number;
76-
onPressIn?: (
77-
event: GestureResponderEvent,
78-
defaultOnPress?: () => void,
79-
) => void;
8078
styles?: Partial<{
8179
container: StyleProp<ViewStyle>;
8280
details: StyleProp<ViewStyle>;
@@ -103,6 +101,7 @@ const FileAttachmentWithContext = <
103101
AttachmentActions,
104102
FileAttachmentIcon,
105103
onLongPress,
104+
onPress,
106105
onPressIn,
107106
styles: stylesProp = {},
108107
} = props;
@@ -120,15 +119,28 @@ const FileAttachmentWithContext = <
120119

121120
return (
122121
<TouchableOpacity
123-
onLongPress={onLongPress}
124-
onPress={() => {
122+
onLongPress={(event) => {
123+
onLongPress({
124+
emitter: 'fileAttachment',
125+
event,
126+
});
127+
}}
128+
onPress={(event) => {
125129
if (!onPressIn) {
126-
defaultOnPress();
130+
onPress({
131+
defaultHandler: defaultOnPress,
132+
emitter: 'fileAttachment',
133+
event,
134+
});
127135
}
128136
}}
129137
onPressIn={(event) => {
130138
if (onPressIn) {
131-
onPressIn(event, defaultOnPress);
139+
onPressIn({
140+
defaultHandler: defaultOnPress,
141+
emitter: 'fileAttachment',
142+
event,
143+
});
132144
}
133145
}}
134146
testID='file-attachment'
@@ -181,12 +193,7 @@ export type FileAttachmentProps<
181193
Pick<
182194
FileAttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
183195
'attachment'
184-
> & {
185-
onPressIn?: (
186-
event: GestureResponderEvent,
187-
defaultOnPress?: () => void,
188-
) => void;
189-
};
196+
>;
190197

191198
export const FileAttachment = <
192199
At extends DefaultAttachmentType = DefaultAttachmentType,
@@ -199,12 +206,19 @@ export const FileAttachment = <
199206
>(
200207
props: FileAttachmentProps<At, Ch, Co, Ev, Me, Re, Us>,
201208
) => {
202-
const { onLongPress } = useMessageContext<At, Ch, Co, Ev, Me, Re, Us>();
209+
const { onLongPress, onPress, onPressIn } = useMessageContext<
210+
At,
211+
Ch,
212+
Co,
213+
Ev,
214+
Me,
215+
Re,
216+
Us
217+
>();
203218
const {
204219
additionalTouchableProps,
205220
AttachmentActions = AttachmentActionsDefault,
206221
FileAttachmentIcon = FileIconDefault,
207-
onPressInMessage: onPressIn,
208222
} = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
209223

210224
return (
@@ -214,6 +228,7 @@ export const FileAttachment = <
214228
AttachmentActions,
215229
FileAttachmentIcon,
216230
onLongPress,
231+
onPress,
217232
onPressIn,
218233
}}
219234
{...props}

0 commit comments

Comments
 (0)