2018-12-21 10:55:35 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-10-31 18:40:08 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {
|
2019-03-27 20:06:57 +00:00
|
|
|
View, Text, StyleSheet, ScrollView
|
2018-10-31 18:40:08 +00:00
|
|
|
} from 'react-native';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
|
|
|
import equal from 'deep-equal';
|
|
|
|
|
|
|
|
import I18n from '../../../i18n';
|
2018-11-19 18:18:15 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { isIOS } from '../../../utils/deviceInfo';
|
2019-03-25 20:20:24 +00:00
|
|
|
import { headerIconSize } from '../../../containers/HeaderButton';
|
2019-03-27 20:06:57 +00:00
|
|
|
import Icon from './Icon';
|
2019-03-29 19:36:07 +00:00
|
|
|
import { COLOR_TEXT_DESCRIPTION, HEADER_TITLE, COLOR_WHITE } from '../../../constants/colors';
|
2018-10-31 18:40:08 +00:00
|
|
|
|
2019-03-29 19:36:07 +00:00
|
|
|
const TITLE_SIZE = 16;
|
2018-10-31 18:40:08 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2019-03-27 20:06:57 +00:00
|
|
|
flex: 1,
|
|
|
|
height: '100%'
|
2018-10-31 18:40:08 +00:00
|
|
|
},
|
|
|
|
titleContainer: {
|
2019-03-27 20:06:57 +00:00
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row'
|
2018-10-31 18:40:08 +00:00
|
|
|
},
|
|
|
|
title: {
|
2018-11-19 18:18:15 +00:00
|
|
|
...sharedStyles.textSemibold,
|
2019-03-29 19:36:07 +00:00
|
|
|
color: HEADER_TITLE,
|
2018-11-19 18:18:15 +00:00
|
|
|
fontSize: TITLE_SIZE
|
2018-10-31 18:40:08 +00:00
|
|
|
},
|
2019-03-27 20:06:57 +00:00
|
|
|
scroll: {
|
|
|
|
alignItems: 'center'
|
2018-10-31 18:40:08 +00:00
|
|
|
},
|
|
|
|
typing: {
|
2018-11-19 18:18:15 +00:00
|
|
|
...sharedStyles.textRegular,
|
2019-03-29 19:36:07 +00:00
|
|
|
color: isIOS ? COLOR_TEXT_DESCRIPTION : COLOR_WHITE,
|
2019-03-27 20:06:57 +00:00
|
|
|
fontSize: 12,
|
|
|
|
marginBottom: 2
|
2018-10-31 18:40:08 +00:00
|
|
|
},
|
|
|
|
typingUsers: {
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textSemibold
|
2018-10-31 18:40:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
@responsive
|
|
|
|
@connect((state) => {
|
|
|
|
let status = '';
|
|
|
|
let title = '';
|
2018-11-05 12:00:58 +00:00
|
|
|
const roomType = state.room.t;
|
|
|
|
if (roomType === 'd') {
|
|
|
|
if (state.login.user && state.login.user.id) {
|
|
|
|
const { id: loggedUserId } = state.login.user;
|
|
|
|
const userId = state.room.rid.replace(loggedUserId, '').trim();
|
|
|
|
if (userId === loggedUserId) {
|
|
|
|
status = state.login.user.status; // eslint-disable-line
|
|
|
|
} else {
|
|
|
|
const user = state.activeUsers[userId];
|
|
|
|
status = (user && user.status) || 'offline';
|
|
|
|
}
|
2018-10-31 18:40:08 +00:00
|
|
|
}
|
|
|
|
title = state.settings.UI_Use_Real_Name ? state.room.fname : state.room.name;
|
|
|
|
} else {
|
|
|
|
title = state.room.name;
|
|
|
|
}
|
|
|
|
|
2018-11-05 12:00:58 +00:00
|
|
|
let otherUsersTyping = [];
|
|
|
|
if (state.login.user && state.login.user.username) {
|
|
|
|
const { username } = state.login.user;
|
|
|
|
const { usersTyping } = state.room;
|
|
|
|
otherUsersTyping = usersTyping.filter(_username => _username !== username);
|
|
|
|
}
|
2018-10-31 18:40:08 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
usersTyping: otherUsersTyping,
|
2018-11-05 12:00:58 +00:00
|
|
|
type: roomType,
|
2018-10-31 18:40:08 +00:00
|
|
|
title,
|
|
|
|
status
|
|
|
|
};
|
|
|
|
})
|
2018-12-21 10:55:35 +00:00
|
|
|
export default class RoomHeaderView extends Component {
|
2018-10-31 18:40:08 +00:00
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
|
|
|
window: PropTypes.object,
|
|
|
|
usersTyping: PropTypes.array,
|
|
|
|
status: PropTypes.string
|
|
|
|
};
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
const {
|
|
|
|
type, title, status, usersTyping, window
|
|
|
|
} = this.props;
|
|
|
|
if (nextProps.type !== type) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.title !== title) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.status !== status) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.window.width !== window.width) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.window.height !== window.height) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!equal(nextProps.usersTyping, usersTyping)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-27 20:06:57 +00:00
|
|
|
// componentDidUpdate(prevProps) {
|
|
|
|
// if (isIOS) {
|
|
|
|
// const { usersTyping } = this.props;
|
|
|
|
// if (!equal(prevProps.usersTyping, usersTyping)) {
|
|
|
|
// LayoutAnimation.easeInEaseOut();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2018-10-31 18:40:08 +00:00
|
|
|
|
|
|
|
get typing() {
|
|
|
|
const { usersTyping } = this.props;
|
|
|
|
let usersText;
|
|
|
|
if (!usersTyping.length) {
|
|
|
|
return null;
|
|
|
|
} else if (usersTyping.length === 2) {
|
|
|
|
usersText = usersTyping.join(` ${ I18n.t('and') } `);
|
|
|
|
} else {
|
|
|
|
usersText = usersTyping.join(', ');
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text style={styles.typing} numberOfLines={1}>
|
|
|
|
<Text style={styles.typingUsers}>{usersText} </Text>
|
2018-11-19 18:18:15 +00:00
|
|
|
{ usersTyping.length > 1 ? I18n.t('are_typing') : I18n.t('is_typing') }...
|
2018-10-31 18:40:08 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-03-27 20:06:57 +00:00
|
|
|
window, title, usersTyping, type, status
|
2018-10-31 18:40:08 +00:00
|
|
|
} = this.props;
|
|
|
|
const portrait = window.height > window.width;
|
2019-03-25 20:20:24 +00:00
|
|
|
const widthScrollView = window.width - 6.5 * headerIconSize;
|
2018-10-31 18:40:08 +00:00
|
|
|
let scale = 1;
|
|
|
|
|
|
|
|
if (!portrait) {
|
|
|
|
if (usersTyping.length > 0) {
|
|
|
|
scale = 0.8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-03-12 16:23:06 +00:00
|
|
|
<View style={styles.container}>
|
2019-03-25 20:20:24 +00:00
|
|
|
<View style={[styles.titleContainer, { width: widthScrollView }]}>
|
|
|
|
<ScrollView
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
horizontal
|
|
|
|
bounces={false}
|
2019-03-27 20:06:57 +00:00
|
|
|
contentContainerStyle={styles.scroll}
|
2019-03-25 20:20:24 +00:00
|
|
|
>
|
2019-03-27 20:06:57 +00:00
|
|
|
<Icon type={type} status={status} />
|
2019-03-25 20:20:24 +00:00
|
|
|
<Text style={[styles.title, { fontSize: TITLE_SIZE * scale }]} numberOfLines={1}>{title}</Text>
|
|
|
|
</ScrollView>
|
2018-10-31 18:40:08 +00:00
|
|
|
</View>
|
|
|
|
{this.typing}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|