2017-11-24 17:21:21 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { View, StyleSheet, Text, Keyboard, LayoutAnimation } from 'react-native';
|
2017-11-24 17:21:21 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../i18n';
|
2017-11-24 17:21:21 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
typing: {
|
|
|
|
transform: [{ scaleY: -1 }],
|
|
|
|
fontWeight: 'bold',
|
|
|
|
paddingHorizontal: 15,
|
|
|
|
height: 25
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
emptySpace: {
|
|
|
|
height: 5
|
2017-11-24 17:21:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
@connect(state => ({
|
|
|
|
username: state.login.user && state.login.user.username,
|
|
|
|
usersTyping: state.room.usersTyping
|
|
|
|
}))
|
2018-01-09 17:12:55 +00:00
|
|
|
export default class Typing extends React.Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return this.props.usersTyping.join() !== nextProps.usersTyping.join();
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
componentWillUpdate() {
|
|
|
|
LayoutAnimation.easeInEaseOut();
|
|
|
|
}
|
2018-01-30 15:07:09 +00:00
|
|
|
onPress = () => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
}
|
2017-11-24 17:21:21 +00:00
|
|
|
get usersTyping() {
|
|
|
|
const users = this.props.usersTyping.filter(_username => this.props.username !== _username);
|
2018-06-01 17:38:13 +00:00
|
|
|
return users.length ? `${ users.join(' ,') } ${ users.length > 1 ? I18n.t('are_typing') : I18n.t('is_typing') }` : '';
|
2017-11-24 17:21:21 +00:00
|
|
|
}
|
|
|
|
render() {
|
2018-04-24 19:34:03 +00:00
|
|
|
const { usersTyping } = this;
|
|
|
|
|
|
|
|
if (!usersTyping) {
|
|
|
|
return <View style={styles.emptySpace} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (<Text style={styles.typing} onPress={() => this.onPress()}>{usersTyping}</Text>);
|
2017-11-24 17:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Typing.propTypes = {
|
|
|
|
username: PropTypes.string,
|
|
|
|
usersTyping: PropTypes.array
|
|
|
|
};
|