Skip to content

Commit a419e7f

Browse files
CRNS-54: Adding some more typescript and prop types for message related components
1 parent 95ca558 commit a419e7f

File tree

7 files changed

+176
-29
lines changed

7 files changed

+176
-29
lines changed

src/components/Chat.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export const Chat = themed(
2828
static propTypes = {
2929
/** The StreamChat client object */
3030
client: PropTypes.object.isRequired,
31-
/** Theme object */
31+
/**
32+
* Theme object
33+
*
34+
* @ref https://getstream.io/chat/react-native-chat/tutorial/#custom-styles
35+
* */
3236
style: PropTypes.object,
3337
logger: PropTypes.func,
3438
};

src/components/MessageSimple/MessageAvatar.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import styled from '@stream-io/styled-components';
33
import { Avatar } from '../Avatar';
4+
import PropTypes from 'prop-types';
45

56
const Container = styled.View`
67
margin-right: ${({ alignment }) => (alignment === 'left' ? 8 : 0)};
@@ -33,3 +34,21 @@ export const MessageAvatar = ({ message, isMyMessage, groupStyles }) => {
3334
</Container>
3435
);
3536
};
37+
38+
MessageAvatar.propTypes = {
39+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
40+
message: PropTypes.object,
41+
/**
42+
* Returns true if message (param) belongs to current user, else false
43+
*
44+
* @param message
45+
* */
46+
isMyMessage: PropTypes.func,
47+
/**
48+
* Position of message in group - top, bottom, middle, single.
49+
*
50+
* Message group is a group of consecutive messages from same user. groupStyles can be used to style message as per their position in message group
51+
* e.g., user avatar (to which message belongs to) is only showed for last (bottom) message in group.
52+
*/
53+
groupStyles: PropTypes.array,
54+
};

src/components/MessageSimple/MessageContent.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,16 @@ export const MessageContent = themed(
169169
* {...props}
170170
* onPress={(thisArg, message, e) => {
171171
* thisArg.openReactionSelector();
172-
* // Similarly, you can also call other methods available on MessageContent
173-
* // component such as handleEdit, handleDelete, showActionSheet
174-
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
175172
* }}
176173
* )
177174
* }
178175
* ```
176+
*
177+
* Similarly, you can also call other methods available on MessageContent
178+
* component such as handleEdit, handleDelete, showActionSheet etc.
179+
*
180+
* Source - [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js)
181+
*
179182
* @param {Component} thisArg Reference to MessageContent component
180183
* @param message Message object which was pressed
181184
* @param e Event object for onPress event
@@ -194,12 +197,16 @@ export const MessageContent = themed(
194197
* {...props}
195198
* onLongPress={(thisArg, message, e) => {
196199
* thisArg.openReactionSelector();
197-
* // Similarly, you can also call other methods available on MessageContent
198-
* // component such as handleEdit, handleDelete, showActionSheet
199-
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
200200
* }}
201201
* )
202202
* }
203+
*
204+
* Similarly, you can also call other methods available on MessageContent
205+
* component such as handleEdit, handleDelete, showActionSheet etc.
206+
*
207+
* Source - [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js)
208+
*
209+
* By default we show action sheet with all the message actions on long press.
203210
* ```
204211
*
205212
* @param {Component} thisArg Reference to MessageContent component
@@ -222,6 +229,13 @@ export const MessageContent = themed(
222229
handleAction: PropTypes.func,
223230
/** Position of message. 'right' | 'left' */
224231
alignment: PropTypes.string,
232+
/**
233+
* Position of message in group - top, bottom, middle, single.
234+
*
235+
* Message group is a group of consecutive messages from same user. groupStyles can be used to style message as per their position in message group
236+
* e.g., user avatar (to which message belongs to) is only showed for last (bottom) message in group.
237+
*/
238+
groupStyles: PropTypes.array,
225239
/**
226240
* Style object for actionsheet (used to message actions).
227241
* Supported styles: https://github.com/beefe/react-native-actionsheet/blob/master/lib/styles.js

src/components/MessageSimple/MessageReplies.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import styled from '@stream-io/styled-components';
3+
import PropTypes from 'prop-types';
34

45
import iconPath from '../../images/icons/icon_path.png';
56

@@ -40,3 +41,14 @@ export const MessageReplies = ({ message, isThreadList, openThread, pos }) => {
4041
</Container>
4142
);
4243
};
44+
45+
MessageReplies.propTypes = {
46+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
47+
message: PropTypes.object,
48+
/** Boolean if current message is part of thread */
49+
isThreadList: PropTypes.bool,
50+
/** @see See [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext) */
51+
openThread: PropTypes.func,
52+
/** right | left */
53+
pos: PropTypes.string,
54+
};

src/components/MessageSimple/MessageStatus.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from '@stream-io/styled-components';
33
import loadingGif from '../../images/loading.gif';
44
import iconDeliveredUnseen from '../../images/icons/delivered_unseen.png';
55
import { Avatar } from '../Avatar';
6+
import PropTypes from 'prop-types';
67

78
const Spacer = styled.View`
89
height: 10;
@@ -111,3 +112,16 @@ export const MessageStatus = ({
111112

112113
return <StatusContainer>{renderStatus()}</StatusContainer>;
113114
};
115+
116+
MessageStatus.propTypes = {
117+
/** @see See [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext) */
118+
client: PropTypes.object,
119+
/** A list of users who have read the message */
120+
readBy: PropTypes.array,
121+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
122+
message: PropTypes.object,
123+
/** Latest message id on current channel */
124+
lastReceivedId: PropTypes.string,
125+
/** Boolean if current message is part of thread */
126+
isThreadList: PropTypes.bool,
127+
};

src/components/MessageSimple/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ export const MessageSimple = themed(
6565
* {...props}
6666
* onPress={(thisArg, message, e) => {
6767
* thisArg.openReactionSelector();
68-
* // Similarly, you can also call other methods available on MessageContent
69-
* // component such as handleEdit, handleDelete, showActionSheet
70-
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
7168
* }}
7269
* )
7370
* }
7471
* ```
72+
*
73+
* Similarly, you can also call other methods available on MessageContent
74+
* component such as handleEdit, handleDelete, showActionSheet etc.
75+
*
76+
* Source - [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js)
77+
*
7578
* @param {Component} thisArg Reference to MessageContent component
7679
* @param message Message object which was pressed
7780
* @param e Event object for onPress event
@@ -90,14 +93,18 @@ export const MessageSimple = themed(
9093
* {...props}
9194
* onLongPress={(thisArg, message, e) => {
9295
* thisArg.openReactionSelector();
93-
* // Similarly, you can also call other methods available on MessageContent
94-
* // component such as handleEdit, handleDelete, showActionSheet
95-
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
9696
* }}
9797
* )
9898
* }
99+
*
100+
* Similarly, you can also call other methods available on MessageContent
101+
* component such as handleEdit, handleDelete, showActionSheet etc.
102+
*
103+
* Source - [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js)
99104
* ```
100105
*
106+
* By default we show action sheet with all the message actions on long press.
107+
*
101108
* @param {Component} thisArg Reference to MessageContent component
102109
* @param message Message object which was long pressed
103110
* @param e Event object for onLongPress event

types/index.d.ts

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ export interface KeyboardContextValue {
118118
//================================================================================================
119119
//================================================================================================
120120
export interface ChatProps {
121+
/** The StreamChat client object */
121122
client: Client.StreamChat;
123+
/**
124+
* Theme object
125+
*
126+
* @ref https://getstream.io/chat/react-native-chat/tutorial/#custom-styles
127+
* */
122128
style?: object;
123129
}
124130

@@ -131,16 +137,17 @@ export interface ChannelProps extends ChatContextValue {
131137
Attachment?: React.ElementType<AttachmentProps>;
132138
}
133139

134-
export interface EmptyStateIndicatorProps {
135-
listType?: 'channel' | 'message' | 'default';
136-
}
140+
export type listType = 'channel' | 'message' | 'default';
137141

138142
export interface LoadingErrorIndicatorProps {
139-
listType?: 'channel' | 'message' | 'default';
143+
listType?: listType;
144+
}
145+
export interface EmptyStateIndicatorProps {
146+
listType?: listType;
140147
}
141148

142149
export interface LoadingIndicatorProps {
143-
listType: 'channel' | 'message' | 'default';
150+
listType?: listType;
144151
}
145152
export interface DateSeparatorProps {
146153
message: Client.MessageResponse;
@@ -435,9 +442,57 @@ export interface MessageUIComponentProps
435442
AttachmentFileIcon?: React.ElementType<FileIconUIComponentProps>;
436443
}
437444

445+
export interface MessageRepliesUIComponentProps {
446+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
447+
message: Client.MessageResponse;
448+
/** Boolean if current message is part of thread */
449+
isThreadList: boolean;
450+
/** @see See [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext) */
451+
openThread?(message: Client.Message, event: React.SyntheticEvent): void;
452+
/** right | left */
453+
pos: string;
454+
}
455+
456+
export interface MessageStatusUIComponentProps {
457+
/** @see See [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext) */
458+
client: Client.StreamChat;
459+
/** A list of users who have read the message */
460+
readBy: Array<Client.UserResponse>;
461+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
462+
message: Client.MessageResponse;
463+
/** Latest message id on current channel */
464+
lastReceivedId: string;
465+
/** Boolean if current message is part of thread */
466+
isThreadList: boolean;
467+
}
468+
469+
export interface MessageAvatarUIComponentProps {
470+
/** Current [message object](https://getstream.io/chat/docs/#message_format) */
471+
message: Client.MessageResponse;
472+
/**
473+
* Returns true if message (param) belongs to current user, else false
474+
*
475+
* @param message
476+
* */
477+
isMyMessage?(message: Client.MessageResponse): boolean;
478+
/**
479+
* Position of message in group - top, bottom, middle, single.
480+
*
481+
* Message group is a group of consecutive messages from same user. groupStyles can be used to style message as per their position in message group
482+
* e.g., user avatar (to which message belongs to) is only showed for last (bottom) message in group.
483+
*/
484+
groupStyles: [];
485+
}
486+
487+
export interface MessageContentUIComponentProps
488+
extends MessageUIComponentProps {
489+
alignment: string;
490+
}
491+
438492
export interface MessageTextProps {
439493
message: Client.MessageResponse;
440494
}
495+
441496
export interface ThreadProps extends ChannelContextValue {
442497
/** the thread (the parent message object) */
443498
thread: SeamlessImmutable.Immutable<Client.MessageResponse>;
@@ -462,7 +517,7 @@ export interface FileIconUIComponentProps {
462517

463518
export interface AutoCompleteInputProps {
464519
value: string;
465-
openSuggestions?(title: string, component: React.ElementType<any, any>): void;
520+
openSuggestions?(title: string, component: React.ElementType<any>): void;
466521
closeSuggestions?(): void;
467522
updateSuggestions?(param: object): void;
468523
triggerSettings: object;
@@ -493,24 +548,18 @@ export interface DateSeparatorProps {
493548
message: Client.MessageResponse;
494549
formatDate?(date: Date): string;
495550
}
496-
export interface EmptyStateIndicatorProps {
497-
listType?: 'string';
498-
}
499-
export interface EventIndicatorProps {
500-
event: Client.Event;
501-
}
502551
export interface FileAttachmentGroupProps {
503552
messageId: string;
504553
files: [];
505554
handleAction?(): void;
506555
alignment: 'right' | 'left';
507-
AttachmentFileIcon: React.ElementType<any, any>;
556+
AttachmentFileIcon: React.ElementType<any>;
508557
}
509558
export interface FileUploadPreviewProps {
510559
fileUploads: [];
511560
removeFile?(id: string): void;
512561
retryUpload?(id: string): Promise<any>;
513-
AttachmentFileIcon: React.ElementType<any, any>;
562+
AttachmentFileIcon: React.ElementType<any>;
514563
}
515564
export interface GalleryProps {
516565
images: Client.Attachment[];
@@ -533,11 +582,22 @@ export interface ImageUploadPreviewProps {
533582
retryUpload?(id: string): Promise<any>;
534583
}
535584
export interface KeyboardCompatibleViewProps {}
585+
586+
export interface EmptyStateIndicatorProps {
587+
listType?: listType;
588+
}
589+
export interface EventIndicatorProps {
590+
event:
591+
| Client.Event<Client.MemberAddedEvent>
592+
| Client.Event<Client.MemberRemovedEvent>
593+
| null;
594+
}
595+
536596
export interface LoadingErrorIndicatorProps {
537-
listType: string;
597+
listType?: listType;
538598
}
539599
export interface LoadingIndicatorProps {
540-
listType: 'channel' | 'message' | 'default';
600+
listType?: listType;
541601
}
542602
export interface MentionsItemProps {
543603
item: {
@@ -714,6 +774,23 @@ export class MessageSimple extends React.PureComponent<
714774
MessageUIComponentProps,
715775
any
716776
> {}
777+
export class MessageContent extends React.PureComponent<
778+
MessageContentUIComponentProps,
779+
any
780+
> {}
781+
export class MessageReplies extends React.PureComponent<
782+
MessageRepliesUIComponentProps,
783+
any
784+
> {}
785+
export class MessageStatus extends React.PureComponent<
786+
MessageStatusUIComponentProps,
787+
any
788+
> {}
789+
export class MessageAvatar extends React.PureComponent<
790+
MessageAvatarUIComponentProps,
791+
any
792+
> {}
793+
717794
export class ChannelList extends React.PureComponent<ChannelListProps, any> {}
718795

719796
export class Thread extends React.PureComponent<ThreadProps, any> {}

0 commit comments

Comments
 (0)