From 52ec6a2eeceab2d2571fe87768a9106929dc7801 Mon Sep 17 00:00:00 2001 From: Jan Romaniak Date: Mon, 24 Jun 2019 17:18:45 +0200 Subject: [PATCH] Enter used as send button shift + enter used as new line --- package.json | 2 +- src/Composer.js | 32 ++++++++++++++++++++++---------- src/GiftedChat.js | 3 --- src/Send.js | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 9d801d4e5..871b8b820 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-web-gifted-chat", - "version": "0.6.6", + "version": "0.6.7", "description": "The most complete chat UI for React Web", "main": "dist/index.js", "repository": { diff --git a/src/Composer.js b/src/Composer.js index ae30c1908..c5df3313c 100644 --- a/src/Composer.js +++ b/src/Composer.js @@ -28,20 +28,27 @@ export default class Composer extends React.Component { this.props.onTextChanged(text); } + onKeyDown(e) { + const { text, onSend } = this.props; + if (e.keyCode === 13 && e.shiftKey === false) { + onSend({ text: text.trim() }, true); + e.preventDefault(); + } + return false; + } + render() { return ( - this.onKeyDown(e)} accessibilityLabel={this.props.placeholder} placeholder={this.props.placeholder} placeholderTextColor={this.props.placeholderTextColor} multiline={this.props.multiline} - onChange={e => this.onContentSizeChange(e)} - onContentSizeChange={e => this.onContentSizeChange(e)} - onChangeText={text => this.onChangeText(text)} - style={[styles.textInput, this.props.textInputStyle, { height: this.props.composerHeight - 1 }]} - autoFocus={this.props.textInputAutoFocus} + onChange={event => this.onChangeText(event.target.value)} + style={{ ...styles.textInput, ...this.props.textInputStyle }} value={this.props.text} enablesReturnKeyAutomatically underlineColorAndroid="transparent" @@ -52,17 +59,22 @@ export default class Composer extends React.Component { } } -const styles = StyleSheet.create({ +const styles = { textInput: { - flex: 1, marginLeft: 10, fontSize: 16, - lineHeight: 16, + lineHeight: '16px', paddingTop: 3, paddingBottom: 3, outline: 'none', + border: 'none', + overflow: 'auto', + boxShadow: 'none', + resize: 'none', + width: '100%', }, -}); +}; + Composer.defaultProps = { composerHeight: MIN_COMPOSER_HEIGHT, diff --git a/src/GiftedChat.js b/src/GiftedChat.js index d3bace351..2e0b94f81 100644 --- a/src/GiftedChat.js +++ b/src/GiftedChat.js @@ -237,9 +237,6 @@ class GiftedChat extends React.Component { } resetInputToolbar() { - if (this.textInput) { - this.textInput.clear(); - } this.notifyInputTextReset(); this.setState({ text: this.getTextFromProp(''), diff --git a/src/Send.js b/src/Send.js index e5151f03b..0eb06b0ef 100644 --- a/src/Send.js +++ b/src/Send.js @@ -15,6 +15,7 @@ export default function Send({ text, containerStyle, onSend, children, textStyle accessibilityLabel="send" style={{ ...styles.container, ...containerStyle }} onPress={() => { + console.log('asdasdasd') onSend({ text: text.trim() }, true); }} accessibilityTraits="button"