Skip to content

Commit 8ffde00

Browse files
CRNS-54: Adding props onPress and onLongPress in Message component
1 parent 9e3064d commit 8ffde00

File tree

5 files changed

+114
-7
lines changed

5 files changed

+114
-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: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,58 @@ export const MessageContent = themed(
153153
* @param e Event object for onPress event
154154
* @param message Message object which was pressed
155155
*
156+
* @deprecated User 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 component such as handleEdit, handleDelete, showActionSheet
173+
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
174+
* }}
175+
* )
176+
* }
177+
* ```
178+
* @param {Component} thisArg Reference to MessageContent component
179+
* @param message Message object which was pressed
180+
* @param e Event object for onPress event
181+
* */
182+
onPress: PropTypes.func,
183+
/**
184+
* Function that overrides default behaviour when message is long pressed
185+
* e.g. if you would like to open reaction picker on message long press:
186+
*
187+
* ```
188+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
189+
* ...
190+
* const MessageUIComponent = (props) => {
191+
* return (
192+
* <MessageSimple
193+
* {...props}
194+
* onLongPress={(thisArg, message, e) => {
195+
* thisArg.openReactionSelector();
196+
* // Similarly, you can also call other methods available on MessageContent component such as handleEdit, handleDelete, showActionSheet
197+
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
198+
* }}
199+
* )
200+
* }
201+
* ```
202+
*
203+
* @param {Component} thisArg Reference to MessageContent component
204+
* @param message Message object which was long pressed
205+
* @param e Event object for onLongPress event
206+
* */
207+
onLongPress: PropTypes.func,
158208
/**
159209
* Handler to delete a current message.
160210
*/
@@ -358,11 +408,18 @@ export const MessageContent = themed(
358408
</DeletedContainer>
359409
);
360410

411+
const onLongPress = this.props.onLongPress;
361412
const contentProps = {
362413
alignment: pos,
363414
status: message.status,
364-
onPress: this.props.onMessageTouch,
365-
onLongPress: options.length > 1 ? this.showActionSheet : null,
415+
onPress: this.props.onPress
416+
? this.props.onPress.bind(this, this, message)
417+
: this.props.onMessageTouch,
418+
onLongPress: onLongPress
419+
? onLongPress.bind(this, this, message)
420+
: options.length > 1
421+
? this.showActionSheet
422+
: null,
366423
activeOpacity: 0.7,
367424
disabled: readOnly,
368425
hasReactions,
@@ -372,7 +429,7 @@ export const MessageContent = themed(
372429
contentProps.onPress = retrySendMessage.bind(this, Immutable(message));
373430

374431
const context = {
375-
onLongPress: options.length > 1 ? this.showActionSheet : null,
432+
onLongPress: contentProps.onLongPress,
376433
};
377434

378435
return (

src/components/MessageSimple/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,58 @@ export const MessageSimple = themed(
4949
* @param e Event object for onPress event
5050
* @param message Message object which was pressed
5151
*
52+
* @deprecated User 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 component such as handleEdit, handleDelete, showActionSheet
69+
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
70+
* }}
71+
* )
72+
* }
73+
* ```
74+
* @param {Component} thisArg Reference to MessageContent component
75+
* @param message Message object which was pressed
76+
* @param e Event object for onPress event
77+
* */
78+
onPress: PropTypes.func,
79+
/**
80+
* Function that overrides default behaviour when message is long pressed
81+
* e.g. if you would like to open reaction picker on message long press:
82+
*
83+
* ```
84+
* import { MessageSimple } from 'stream-chat-react-native' // or 'stream-chat-expo'
85+
* ...
86+
* const MessageUIComponent = (props) => {
87+
* return (
88+
* <MessageSimple
89+
* {...props}
90+
* onLongPress={(thisArg, message, e) => {
91+
* thisArg.openReactionSelector();
92+
* // Similarly, you can also call other methods available on MessageContent component such as handleEdit, handleDelete, showActionSheet
93+
* // Source - https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/MessageSimple/MessageContent.js
94+
* }}
95+
* )
96+
* }
97+
* ```
98+
*
99+
* @param {Component} thisArg Reference to MessageContent component
100+
* @param message Message object which was long pressed
101+
* @param e Event object for onLongPress event
102+
* */
103+
onLongPress: PropTypes.func,
54104
/**
55105
* Handler to delete a current message.
56106
*/

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,

0 commit comments

Comments
 (0)