Skip to content

Commit

Permalink
feat(send): the restriction mechanism for send message (#37)
Browse files Browse the repository at this point in the history
* feat(send): the restriction mechanism for send message

* feat(send): ass shouldScrollToBottom flag
  • Loading branch information
denistakeda authored Nov 27, 2017
1 parent 16e6b25 commit 4b60e3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/GiftedChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class GiftedChat extends React.Component {
)
}

onSend(messages = [], shouldResetInputToolbar = false) {
onSend(messages = []) {
if (!Array.isArray(messages)) {
messages = [messages];
}
Expand All @@ -344,17 +344,20 @@ class GiftedChat extends React.Component {
};
});

if (shouldResetInputToolbar === true) {
if (this.props.shouldResetInputToolbar) {
this.setIsTypingDisabled(true);
this.resetInputToolbar();
}

this.props.onSend(messages);
this.scrollToBottom();

if (shouldResetInputToolbar === true) {
if (this.props.shouldScrollToBottom) {
this.scrollToBottom();
}

if (this.props.shouldResetInputToolbar) {
setTimeout(() => {
if (this.getIsMounted() === true) {
if (this.getIsMounted()) {
this.setIsTypingDisabled(false);
}
}, 100);
Expand Down Expand Up @@ -579,6 +582,7 @@ GiftedChat.defaultProps = {
}),
onInputTextChanged: null,
maxInputLength: null,
shouldResetInputToolbar: true,
};

GiftedChat.propTypes = {
Expand All @@ -602,6 +606,8 @@ GiftedChat.propTypes = {
shouldHideInputToolbar: PropTypes.bool,
onPressAvatar: PropTypes.func,
renderAvatarOnTop: PropTypes.bool,
shouldResetInputToolbar: PropTypes.bool,
shouldScrollToBottom: PropTypes.bool,
renderBubble: PropTypes.func,
onLongPress: PropTypes.func,
renderMessage: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion src/Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class Send extends React.Component {
<TouchableOpacity
style={[styles.container, this.props.containerStyle]}
onPress={() => {
this.props.onSend({text: this.props.text.trim()}, true);
this.props.onSend({text: this.props.text.trim()});
}}
accessibilityLabel={'sendButton'}
accessibilityTraits="button"
Expand Down

0 comments on commit 4b60e3b

Please sign in to comment.