Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for onPress on Bubble #984

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ e.g. System Message
* **`renderBubble`** _(Function)_ - Custom message bubble
* **`renderSystemMessage`** _(Function)_ - Custom system message
* **`onLongPress`** _(Function(`context`, `message`))_ - Callback when a message bubble is long-pressed; default is to show an ActionSheet with "Copy Text" (see [example using `showActionSheetWithOptions()`](https://github.com/FaridSafi/react-native-gifted-chat/blob/master@%7B2017-09-25%7D/src/Bubble.js#L96-L119))
* **`onPress`** _(Function(`context`, `message`))_ - Callback when a message bubble is pressed; This is helpful to implement rich cards chats (when a user receives a set of options and clicks a pre-written question to send it).
* **`inverted`** _(Bool)_ - Reverses display order of `messages`; default is `true`
* **`renderMessage`** _(Function)_ - Custom message container
* **`renderMessageText`** _(Function)_ - Custom message text
Expand Down
7 changes: 7 additions & 0 deletions src/Bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class Bubble extends React.PureComponent {
constructor(props) {
super(props);
this.onLongPress = this.onLongPress.bind(this);
this.onPress = this.onPress.bind(this);
}

onLongPress() {
Expand All @@ -42,6 +43,12 @@ export default class Bubble extends React.PureComponent {
}
}

onPress() {
if (this.props.onPress) {
this.props.onPress(this.context, this.props.currentMessage);
}
}

handleBubbleToNext() {
if (
isSameUser(this.props.currentMessage, this.props.nextMessage) &&
Expand Down