zl-react-native-gifted-chat
Version:
The most complete chat UI for React Native, based on 'react-native-gifted-chat'
76 lines (69 loc) • 1.61 kB
JavaScript
import React from 'react';
import {
StyleSheet,
View,
} from 'react-native';
import GiftedAvatar from './GiftedAvatar';
export default class Avatar extends React.Component {
renderAvatar() {
if (this.props.renderAvatar) {
const {renderAvatar, ...avatarProps} = this.props;
return this.props.renderAvatar(avatarProps);
}
return (
<GiftedAvatar
avatarStyle={StyleSheet.flatten([styles[this.props.position].image, this.props.imageStyle[this.props.position]])}
user={this.props.currentMessage.user}
/>
);
}
render() {
return (
<View style={[styles[this.props.position].container, this.props.containerStyle[this.props.position]]}>
{this.renderAvatar()}
</View>
);
}
}
const styles = {
left: StyleSheet.create({
container: {
marginRight: 8,
},
image: {
height: 36,
width: 36,
borderRadius: 18,
},
}),
right: StyleSheet.create({
container: {
marginLeft: 8,
},
image: {
height: 36,
width: 36,
borderRadius: 18,
},
}),
};
Avatar.defaultProps = {
containerStyle: {},
imageStyle: {},
isSameDay: () => {},
isSameUser: () => {},
position: 'left',
currentMessage: {
user: null,
},
nextMessage: {},
};
Avatar.propTypes = {
containerStyle: React.PropTypes.object,
imageStyle: React.PropTypes.object,
isSameDay: React.PropTypes.func,
isSameUser: React.PropTypes.func,
position: React.PropTypes.oneOf(['left', 'right']),
currentMessage: React.PropTypes.object,
nextMessage: React.PropTypes.object,
};