From 178be7af012c7cdc10bcfd3f52e41784c7c999cf Mon Sep 17 00:00:00 2001 From: CharlesLouis Date: Sat, 29 Sep 2018 15:40:59 +0200 Subject: [PATCH] Add support for onPress on Bubble 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). --- README.md | 1 + src/Bubble.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index bd85c7e9d..7c11a06bb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Bubble.js b/src/Bubble.js index 0fd2d93ed..66ee940cd 100644 --- a/src/Bubble.js +++ b/src/Bubble.js @@ -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() { @@ -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) &&