Skip to content

Commit a718d78

Browse files
bug-fixes from slack-clone testing
1 parent 1f767ad commit a718d78

File tree

7 files changed

+103
-55
lines changed

7 files changed

+103
-55
lines changed

src/components/Message/MessageSimple/MessageActionSheet.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
66
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
77
import { styled } from '../../../styles/styledComponents';
88
import { MESSAGE_ACTIONS } from '../../../utils/utils';
9-
9+
import type { Message as InsertDatesMessage } from '../../MessageList/utils/insertDates';
10+
import type {
11+
DefaultAttachmentType,
12+
DefaultChannelType,
13+
DefaultCommandType,
14+
DefaultEventType,
15+
DefaultMessageType,
16+
DefaultReactionType,
17+
DefaultUserType,
18+
UnknownType,
19+
} from '../../../types/types';
1020
const ActionSheetButtonContainer = styled.View`
1121
align-items: center;
1222
background-color: #fff;
@@ -62,7 +72,15 @@ export type ActionSheetStyles = {
6272
wrapper?: StyleProp<ViewStyle>;
6373
};
6474

65-
export type MessageActionSheetProps = {
75+
export type MessageActionSheetProps<
76+
At extends UnknownType = DefaultAttachmentType,
77+
Ch extends UnknownType = DefaultChannelType,
78+
Co extends string = DefaultCommandType,
79+
Ev extends UnknownType = DefaultEventType,
80+
Me extends UnknownType = DefaultMessageType,
81+
Re extends UnknownType = DefaultReactionType,
82+
Us extends UnknownType = DefaultUserType
83+
> = {
6684
/**
6785
* Handler to delete a current message
6886
*/
@@ -72,6 +90,8 @@ export type MessageActionSheetProps = {
7290
* The `editing` prop is used by the MessageInput component to switch to edit mode.
7391
*/
7492
handleEdit: () => void;
93+
handleReaction: (reactionType: string) => Promise<void>;
94+
message: InsertDatesMessage<At, Ch, Co, Ev, Me, Re, Us>;
7595
/**
7696
* Function that opens the reaction picker
7797
*/
@@ -97,6 +117,7 @@ export type MessageActionSheetProps = {
97117
* React useState hook setter function that toggles action sheet visibility
98118
*/
99119
setActionSheetVisible: React.Dispatch<React.SetStateAction<boolean>>;
120+
supportedReactions: Array<unknown>;
100121
/**
101122
* Style object for action sheet (used to style message actions)
102123
* Supported styles: https://github.com/beefe/react-native-actionsheet/blob/master/lib/styles.js

src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export type ForwardedMessageProps<
146146
* e.g., user avatar (to which message belongs to) is only showed for last (bottom) message in group.
147147
*/
148148
groupStyles: GroupType[];
149+
disabled?: boolean;
149150
/**
150151
* Custom message footer component
151152
*/
@@ -161,6 +162,7 @@ export type ForwardedMessageProps<
161162
MessageReplies?: React.ComponentType<
162163
MessageRepliesProps<At, Ch, Co, Ev, Me, Re, Us>
163164
>;
165+
textBeforeAttachments?: boolean;
164166
};
165167

166168
/**
@@ -229,9 +231,20 @@ export const MessageContent = <
229231
showActionSheet,
230232
supportedReactions = emojiData,
231233
threadList,
234+
textBeforeAttachments = false,
235+
disabled: disabledFromProps,
232236
} = props;
233237

234-
const { disabled } = useChannelContext<At, Ch, Co, Ev, Me, Re, Us>();
238+
const { disabled: disabledFromContext } = useChannelContext<
239+
At,
240+
Ch,
241+
Co,
242+
Ev,
243+
Me,
244+
Re,
245+
Us
246+
>();
247+
const disabled = disabledFromProps || disabledFromContext;
235248
const {
236249
Attachment: ContextAttachment,
237250
Message,
@@ -344,6 +357,53 @@ export const MessageContent = <
344357
return message.created_at;
345358
};
346359

360+
const renderAttachments = () => (
361+
<>
362+
{Array.isArray(message.attachments) &&
363+
message.attachments.map((attachment, index) => {
364+
// We handle files separately
365+
if (
366+
attachment.type === 'file' ||
367+
(attachment.type === 'image' &&
368+
!attachment.title_link &&
369+
!attachment.og_scrape_url)
370+
) {
371+
return null;
372+
}
373+
374+
return (
375+
<Attachment<At>
376+
actionHandler={handleAction}
377+
alignment={alignment}
378+
attachment={attachment}
379+
AttachmentActions={AttachmentActions}
380+
Card={Card}
381+
CardCover={CardCover}
382+
CardFooter={CardFooter}
383+
CardHeader={CardHeader}
384+
FileAttachment={FileAttachment}
385+
Giphy={Giphy}
386+
key={`${message.id}-${index}`}
387+
UrlPreview={UrlPreview}
388+
/>
389+
);
390+
})}
391+
{files.length > 0 && (
392+
<FileAttachmentGroup<At>
393+
alignment={alignment}
394+
AttachmentActions={AttachmentActions}
395+
AttachmentFileIcon={AttachmentFileIcon}
396+
FileAttachment={FileAttachment}
397+
files={files}
398+
handleAction={handleAction}
399+
messageId={message.id}
400+
/>
401+
)}
402+
{images.length > 0 && (
403+
<Gallery<At> alignment={alignment} images={images} />
404+
)}
405+
</>
406+
);
347407
return (
348408
<MessageContentProvider value={context}>
349409
<Container
@@ -401,49 +461,7 @@ export const MessageContent = <
401461
{MessageHeader && <MessageHeader testID='message-header' {...props} />}
402462
{/* TODO: Look at this in production: Reason for collapsible: https://github.com/facebook/react-native/issues/12966 */}
403463
<ContainerInner alignment={alignment} collapsable={false}>
404-
{Array.isArray(message.attachments) &&
405-
message.attachments.map((attachment, index) => {
406-
// We handle files separately
407-
if (
408-
attachment.type === 'file' ||
409-
(attachment.type === 'image' &&
410-
!attachment.title_link &&
411-
!attachment.og_scrape_url)
412-
) {
413-
return null;
414-
}
415-
416-
return (
417-
<Attachment<At>
418-
actionHandler={handleAction}
419-
alignment={alignment}
420-
attachment={attachment}
421-
AttachmentActions={AttachmentActions}
422-
Card={Card}
423-
CardCover={CardCover}
424-
CardFooter={CardFooter}
425-
CardHeader={CardHeader}
426-
FileAttachment={FileAttachment}
427-
Giphy={Giphy}
428-
key={`${message.id}-${index}`}
429-
UrlPreview={UrlPreview}
430-
/>
431-
);
432-
})}
433-
{files.length > 0 && (
434-
<FileAttachmentGroup<At>
435-
alignment={alignment}
436-
AttachmentActions={AttachmentActions}
437-
AttachmentFileIcon={AttachmentFileIcon}
438-
FileAttachment={FileAttachment}
439-
files={files}
440-
handleAction={handleAction}
441-
messageId={message.id}
442-
/>
443-
)}
444-
{images.length > 0 && (
445-
<Gallery<At> alignment={alignment} images={images} />
446-
)}
464+
{!textBeforeAttachments && renderAttachments()}
447465
<MessageTextContainer<At, Ch, Co, Ev, Me, Re, Us>
448466
alignment={alignment}
449467
disabled={message.status === 'failed' || message.type === 'error'}
@@ -456,6 +474,7 @@ export const MessageContent = <
456474
MessageText={MessageText}
457475
openThread={onOpenThread}
458476
/>
477+
{textBeforeAttachments && renderAttachments()}
459478
</ContainerInner>
460479
{repliesEnabled && (
461480
<MessageReplies<At, Ch, Co, Ev, Me, Re, Us>
@@ -484,13 +503,16 @@ export const MessageContent = <
484503
canEditMessage={canEditMessage}
485504
handleDelete={handleDelete}
486505
handleEdit={handleEdit}
506+
handleReaction={handleReaction}
507+
message={message}
487508
messageActions={messageActions}
488509
openReactionPicker={openReactionPicker}
489510
openThread={onOpenThread}
490511
reactionsEnabled={reactionsEnabled}
491512
ref={actionSheetRef}
492513
repliesEnabled={repliesEnabled}
493514
setActionSheetVisible={setActionSheetVisible}
515+
supportedReactions={emojiData}
494516
threadList={threadList}
495517
/>
496518
)}

src/components/Message/MessageSimple/MessageSimple.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export type MessageSimpleProps<
358358
icon: string;
359359
id: string;
360360
}[];
361+
textBeforeAttachment?: boolean;
361362
/**
362363
* Custom UI component to display enriched url preview.
363364
* Defaults to https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/Attachment/Card.tsx

src/components/Message/MessageSimple/utils/renderText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const renderText = <
7676

7777
for (const urlInfo of urls) {
7878
const displayLink = truncate(urlInfo.encoded.replace(/^(www\.)/, ''), {
79-
length: 20,
79+
length: 200,
8080
omission: '...',
8181
});
8282
const markdown = `[${displayLink}](${urlInfo.protocol}${urlInfo.encoded})`;

src/components/MessageList/TypingIndicator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
} from '../../types/types';
2323

2424
const Container = styled.View`
25-
align-items: center;
25+
align-items: flex-end;
2626
flex-direction: row;
2727
justify-content: flex-start;
2828
${({ theme }) => theme.typingIndicator.container.css};
@@ -70,7 +70,7 @@ export const TypingIndicator = <
7070
image={user.image}
7171
key={`${user.id}${idx}`}
7272
name={user.name || user.id}
73-
size={24}
73+
size={20}
7474
testID={`typing-avatar-${idx}`}
7575
/>
7676
))}

src/components/Reaction/ReactionPicker.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import type {
2020

2121
const Container = styled.TouchableOpacity<{ leftAlign: boolean }>`
2222
align-items: ${({ leftAlign }) => (leftAlign ? 'flex-start' : 'flex-end')};
23+
border-color: pink;
24+
border-width: 10px;
2325
flex: 1;
2426
${({ theme }) => theme.message.reactionPicker.container.css}
2527
`;
@@ -28,7 +30,8 @@ const ContainerView = styled.View`
2830
background-color: black;
2931
border-radius: 30px;
3032
flex-direction: row;
31-
height: 60px;
33+
flex-wrap: wrap;
34+
height: 100px;
3235
padding-horizontal: 20px;
3336
${({ theme }) => theme.message.reactionPicker.containerView.css}
3437
`;
@@ -87,6 +90,7 @@ export type ReactionPickerProps<
8790
| MessageWithDates<At, Ch, Co, Me, Re, Us>['reaction_counts']
8891
| null;
8992
reactionPickerVisible?: boolean;
93+
rpBottom?: number;
9094
rpLeft?: number;
9195
rpRight?: number;
9296
rpTop?: number;
@@ -114,15 +118,15 @@ export const ReactionPicker = <
114118
reactionPickerVisible,
115119
rpLeft,
116120
rpRight,
117-
rpTop = 40,
121+
rpTop,
118122
supportedReactions = emojiData,
119123
} = props;
120124

121125
if (!reactionPickerVisible) return null;
122126

123127
return (
124128
<Modal
125-
animationType='fade'
129+
animationType='slide'
126130
onRequestClose={handleDismiss}
127131
testID='reaction-picker'
128132
transparent

src/components/Thread/Thread.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ export const Thread = <
171171
const headerComponent = (
172172
<>
173173
<DefaultMessage<At, Ch, Co, Ev, Me, Re, Us>
174-
{...additionalParentMessageProps}
175174
groupStyles={['single']}
176175
message={thread}
177176
Message={Message}
178177
threadList
178+
{...additionalParentMessageProps}
179179
/>
180180
<NewThread>
181181
<NewThreadText>{t('Start of a new thread')}</NewThreadText>
@@ -186,15 +186,15 @@ export const Thread = <
186186
return (
187187
<React.Fragment key={`thread-${thread.id}-${channel?.cid || ''}`}>
188188
<MessageList<At, Ch, Co, Ev, Me, Re, Us>
189-
{...additionalMessageListProps}
190189
HeaderComponent={headerComponent}
191190
Message={Message}
192191
threadList
192+
{...additionalMessageListProps}
193193
/>
194194
<MessageInput<At, Ch, Co, Ev, Me, Re, Us>
195-
{...additionalMessageInputProps}
196195
additionalTextInputProps={{ autoFocus, editable: !disabled }}
197196
parent_id={thread.id as StreamMessage<At, Me, Us>['parent_id']}
197+
{...additionalMessageInputProps}
198198
/>
199199
</React.Fragment>
200200
);

0 commit comments

Comments
 (0)