Skip to content

Commit 629fffb

Browse files
Merge pull request #109 from GetStream/vishal/props-fixes
CRNS-54: Adding props onPress and onLongPress in Message component
2 parents dced018 + 95ca558 commit 629fffb

File tree

6 files changed

+128
-7
lines changed

6 files changed

+128
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ cd StreamChatExpoExample
109109
yarn add stream-chat-expo
110110
111111
# If you are using stream-chat-expo <= 0.4.0 and expo <= 34, then you don't need to add @react-native-community/netinfo as dependency. Since previously we used use NetInfo from react-native package.
112-
yarn add @react-native-community/netinfo
112+
expo install @react-native-community/netinfo
113113
```
114114

115115
Please check [Example](https://github.com/GetStream/stream-chat-react-native/blob/master/examples/ExpoMessaging/App.js) to see usage of the components.

src/components/IconSquare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export const IconSquare = ({ icon, onPress }) => {
3131
};
3232

3333
IconSquare.propTypes = {
34-
icon: PropTypes.string,
34+
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
3535
onPress: PropTypes.func,
3636
};

src/components/MessageSimple/MessageContent.js

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,60 @@ export const MessageContent = themed(
153153
* @param e Event object for onPress event
154154
* @param message Message object which was pressed
155155
*
156+
* @deprecated Use onPress instead
156157
* */
157158
onMessageTouch: PropTypes.func,
159+
/**
160+
* Function that overrides default behaviour when message is pressed/touched
161+
* e.g. if you would like to open reaction picker on message press:
162+
*
163+
* ```
164+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
165+
* ...
166+
* const MessageUIComponent = (props) => {
167+
* return (
168+
* <MessageSimple
169+
* {...props}
170+
* onPress={(thisArg, message, e) => {
171+
* 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
175+
* }}
176+
* )
177+
* }
178+
* ```
179+
* @param {Component} thisArg Reference to MessageContent component
180+
* @param message Message object which was pressed
181+
* @param e Event object for onPress event
182+
* */
183+
onPress: PropTypes.func,
184+
/**
185+
* Function that overrides default behaviour when message is long pressed
186+
* e.g. if you would like to open reaction picker on message long press:
187+
*
188+
* ```
189+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
190+
* ...
191+
* const MessageUIComponent = (props) => {
192+
* return (
193+
* <MessageSimple
194+
* {...props}
195+
* onLongPress={(thisArg, message, e) => {
196+
* 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
200+
* }}
201+
* )
202+
* }
203+
* ```
204+
*
205+
* @param {Component} thisArg Reference to MessageContent component
206+
* @param message Message object which was long pressed
207+
* @param e Event object for onLongPress event
208+
* */
209+
onLongPress: PropTypes.func,
158210
/**
159211
* Handler to delete a current message.
160212
*/
@@ -358,11 +410,18 @@ export const MessageContent = themed(
358410
</DeletedContainer>
359411
);
360412

413+
const onLongPress = this.props.onLongPress;
361414
const contentProps = {
362415
alignment: pos,
363416
status: message.status,
364-
onPress: this.props.onMessageTouch,
365-
onLongPress: options.length > 1 ? this.showActionSheet : null,
417+
onPress: this.props.onPress
418+
? this.props.onPress.bind(this, this, message)
419+
: this.props.onMessageTouch,
420+
onLongPress: onLongPress
421+
? onLongPress.bind(this, this, message)
422+
: options.length > 1
423+
? this.showActionSheet
424+
: null,
366425
activeOpacity: 0.7,
367426
disabled: readOnly,
368427
hasReactions,
@@ -372,7 +431,7 @@ export const MessageContent = themed(
372431
contentProps.onPress = retrySendMessage.bind(this, Immutable(message));
373432

374433
const context = {
375-
onLongPress: options.length > 1 ? this.showActionSheet : null,
434+
onLongPress: contentProps.onLongPress,
376435
};
377436

378437
return (

src/components/MessageSimple/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,60 @@ export const MessageSimple = themed(
4949
* @param e Event object for onPress event
5050
* @param message Message object which was pressed
5151
*
52+
* @deprecated Use onPress instead
5253
* */
5354
onMessageTouch: PropTypes.func,
55+
/**
56+
* Function that overrides default behaviour when message is pressed/touched
57+
* e.g. if you would like to open reaction picker on message press:
58+
*
59+
* ```
60+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
61+
* ...
62+
* const MessageUIComponent = (props) => {
63+
* return (
64+
* <MessageSimple
65+
* {...props}
66+
* onPress={(thisArg, message, e) => {
67+
* 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
71+
* }}
72+
* )
73+
* }
74+
* ```
75+
* @param {Component} thisArg Reference to MessageContent component
76+
* @param message Message object which was pressed
77+
* @param e Event object for onPress event
78+
* */
79+
onPress: PropTypes.func,
80+
/**
81+
* Function that overrides default behaviour when message is long pressed
82+
* e.g. if you would like to open reaction picker on message long press:
83+
*
84+
* ```
85+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
86+
* ...
87+
* const MessageUIComponent = (props) => {
88+
* return (
89+
* <MessageSimple
90+
* {...props}
91+
* onLongPress={(thisArg, message, e) => {
92+
* 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
96+
* }}
97+
* )
98+
* }
99+
* ```
100+
*
101+
* @param {Component} thisArg Reference to MessageContent component
102+
* @param message Message object which was long pressed
103+
* @param e Event object for onLongPress event
104+
* */
105+
onLongPress: PropTypes.func,
54106
/**
55107
* Handler to delete a current message.
56108
*/

src/components/SuggestionsProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class SuggestionsProvider extends React.PureComponent {
6060
suggestionsViewActive: false,
6161
suggestionsBottomMargin: 0,
6262
suggestionsLeftMargin: 0,
63-
suggestions: [],
63+
suggestions: {},
6464
suggestionsWidth: 0,
6565
suggestionsBackdropHeight: 0,
6666
suggestionsTitle: '',
@@ -169,7 +169,7 @@ class SuggestionsView extends React.PureComponent {
169169
active: PropTypes.bool,
170170
marginLeft: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
171171
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
172-
suggestions: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
172+
suggestions: PropTypes.object,
173173
backdropHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
174174
handleDismiss: PropTypes.func,
175175
suggestionsTitle: PropTypes.string,

types/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ export interface MessageUIComponentProps
399399
e: GestureResponderEvent,
400400
message: Client.MessageResponse,
401401
): void;
402+
onPress?(
403+
thisArg: React.Component<MessageUIComponentProps>,
404+
message: Client.MessageResponse,
405+
e: GestureResponderEvent,
406+
): any;
407+
onLongPress?(
408+
thisArg: React.Component<MessageUIComponentProps>,
409+
message: Client.MessageResponse,
410+
e: GestureResponderEvent,
411+
): any;
402412
handleReaction(reactionType: string, event?: React.BaseSyntheticEvent): void;
403413
handleDelete?(): void;
404414
handleEdit?(): void;

0 commit comments

Comments
 (0)