Skip to content

Commit

Permalink
Enter used as send button
Browse files Browse the repository at this point in the history
shift + enter used as new line
  • Loading branch information
Jan Romaniak committed Jun 24, 2019
1 parent 63cd29a commit 52ec6a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
32 changes: 22 additions & 10 deletions src/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TextInput
<textarea
testID={this.props.placeholder}
accessible
onKeyDown={e => 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"
Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/GiftedChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ class GiftedChat extends React.Component {
}

resetInputToolbar() {
if (this.textInput) {
this.textInput.clear();
}
this.notifyInputTextReset();
this.setState({
text: this.getTextFromProp(''),
Expand Down
1 change: 1 addition & 0 deletions src/Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 52ec6a2

Please sign in to comment.