Skip to content

Commit f126b99

Browse files
committed
Fix image position, Add hideTextInput prop
1 parent 987d78f commit f126b99

File tree

3 files changed

+68
-36
lines changed

3 files changed

+68
-36
lines changed

GiftedMessenger.js

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var GiftedMessenger = React.createClass({
4545
sendButtonText: 'Send',
4646
onImagePress: null,
4747
inverted: true,
48+
hideTextInput: false,
4849
};
4950
},
5051

@@ -69,13 +70,19 @@ var GiftedMessenger = React.createClass({
6970
sendButtonText: React.PropTypes.string,
7071
onImagePress: React.PropTypes.func,
7172
inverted: React.PropTypes.bool,
73+
hideTextInput: React.PropTypes.bool,
7274
},
7375

7476
getInitialState: function() {
7577
this._data = [];
7678
this._rowIds = [];
7779

78-
this.listViewMaxHeight = this.props.maxHeight - 44; // 44 is height of textInput
80+
var textInputHeight = 0;
81+
if (this.props.hideTextInput === false) {
82+
textInputHeight = 44;
83+
}
84+
85+
this.listViewMaxHeight = this.props.maxHeight - textInputHeight;
7986

8087
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => {
8188
if (typeof r1.status !== 'undefined') {
@@ -173,18 +180,33 @@ var GiftedMessenger = React.createClass({
173180

174181
renderImage(rowData = {}, rowID = null) {
175182
if (rowData.image !== null) {
176-
if (typeof this.props.onImagePress === 'function') {
177-
return (
178-
<TouchableHighlight
179-
underlayColor='transparent'
180-
onPress={() => this.props.onImagePress(rowData, rowID)}
181-
>
182-
<Image source={rowData.image} style={[this.styles.image, (rowData.position === 'left' ? this.styles.imageLeft : this.styles.imageRight)]}/>
183-
</TouchableHighlight>
184-
);
183+
184+
var diffMessage = null;
185+
if (this.props.inverted === false) {
186+
diffMessage = null; // force rendering
187+
} else {
188+
diffMessage = this.getNextMessage(rowID);
189+
}
190+
191+
if (diffMessage === null || (this._data[rowID].name !== diffMessage.name || this._data[rowID].id !== diffMessage.id)) {
192+
if (typeof this.props.onImagePress === 'function') {
193+
return (
194+
<TouchableHighlight
195+
underlayColor='transparent'
196+
onPress={() => this.props.onImagePress(rowData, rowID)}
197+
style={this.styles.imagePosition}
198+
>
199+
<Image source={rowData.image} style={[this.styles.imagePosition, this.styles.image, (rowData.position === 'left' ? this.styles.imageLeft : this.styles.imageRight)]}/>
200+
</TouchableHighlight>
201+
);
202+
} else {
203+
return (
204+
<Image source={rowData.image} style={[this.styles.imagePosition, this.styles.image, (rowData.position === 'left' ? this.styles.imageLeft : this.styles.imageRight)]}/>
205+
);
206+
}
185207
} else {
186208
return (
187-
<Image source={rowData.image} style={[this.styles.image, (rowData.position === 'left' ? this.styles.imageLeft : this.styles.imageRight)]}/>
209+
<View style={this.styles.imagePosition}/>
188210
);
189211
}
190212
}
@@ -516,25 +538,28 @@ var GiftedMessenger = React.createClass({
516538
},
517539

518540
renderTextInput() {
519-
return (
520-
<View style={this.styles.textInputContainer}>
521-
<TextInput
522-
style={this.styles.textInput}
523-
placeholder={this.props.placeholder}
524-
ref='textInput'
525-
onChangeText={this.onChangeText}
526-
value={this.state.text}
527-
autoFocus={this.props.autoFocus}
528-
/>
529-
<Button
530-
style={this.styles.sendButton}
531-
onPress={this.onSend}
532-
disabled={this.state.disabled}
533-
>
534-
{this.props.sendButtonText}
535-
</Button>
536-
</View>
537-
);
541+
if (this.props.hideTextInput === false) {
542+
return (
543+
<View style={this.styles.textInputContainer}>
544+
<TextInput
545+
style={this.styles.textInput}
546+
placeholder={this.props.placeholder}
547+
ref='textInput'
548+
onChangeText={this.onChangeText}
549+
value={this.state.text}
550+
autoFocus={this.props.autoFocus}
551+
/>
552+
<Button
553+
style={this.styles.sendButton}
554+
onPress={this.onSend}
555+
disabled={this.state.disabled}
556+
>
557+
{this.props.sendButtonText}
558+
</Button>
559+
</View>
560+
);
561+
}
562+
return null;
538563
},
539564

540565
componentWillMount() {
@@ -585,13 +610,16 @@ var GiftedMessenger = React.createClass({
585610
flexDirection: 'row',
586611
marginBottom: 10,
587612
},
588-
image: {
613+
imagePosition: {
589614
height: 30,
590615
width: 30,
591-
borderRadius: 15,
592616
alignSelf: 'flex-end',
593617
marginLeft: 8,
594-
marginRight: 8,
618+
marginRight: 8,
619+
},
620+
image: {
621+
alignSelf: 'center',
622+
borderRadius: 15,
595623
},
596624
imageLeft: {
597625
},

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Ready-to-use chat interface for iOS and Android React-Native apps
44
![](https://raw.githubusercontent.com/FaridSafi/react-native-gifted-messenger/master/screenshots/messenger-1.png)
55
![](https://raw.githubusercontent.com/FaridSafi/react-native-gifted-messenger/master/screenshots/messenger-2.png)
66

7+
### Changelog
8+
- 0.0.3 Fix image position, Add hideTextInput prop
9+
710
### Example
811

912
```js
@@ -35,7 +38,7 @@ var GiftedMessengerExample = React.createClass({
3538
ref='GiftedMessenger'
3639
initialMessages={this.getInitialMessages()}
3740
handleSend={this.handleSend}
38-
maxHeight={Dimensions.get('window').height - navBarHeight} // 64 for the navBar
41+
maxHeight={Dimensions.get('window').height - 64} // 64 for the navBar
3942

4043
styles={{
4144
bubbleLeft: {
@@ -88,8 +91,9 @@ See [GiftedMessengerExample/GiftedMessengerExample.js](https://raw.githubusercon
8891
| handlePhonePress | Function | Called when a parsed phone number is pressed | iOS | (phone) => {} |
8992
| handleEmailPress | Function | Called when a parsed email is pressed | iOS | (email) => {} |
9093
| inverted | Boolean | Invert vertically the orientation of the chat | Both | true |
94+
| hideTextInput | Boolean | Hide or not the text input | Both | false |
9195

92-
* In Android React-Native 0.14.2, I recommend to use inverted={false} until issue [#3557](https://github.com/facebook/react-native/issues/3557) is fixed
96+
* In React-Native 0.14.2, I recommend to use inverted={false} only in Android until issue [#3557](https://github.com/facebook/react-native/issues/3557) is fixed
9397

9498

9599
### API

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-gifted-messenger",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "The chat of your next React-Native Apps",
55
"main": "GiftedMessenger.js",
66
"scripts": {

0 commit comments

Comments
 (0)