Files
jitsi-meet/react/features/recent-list/components/RecentList.native.js

203 lines
6.3 KiB
JavaScript
Raw Normal View History

2017-12-13 11:35:42 +01:00
import React from 'react';
import { ListView, Text, TouchableHighlight, View } from 'react-native';
import { connect } from 'react-redux';
2018-01-29 16:20:38 -06:00
import { Icon } from '../../base/font-icons';
2017-12-13 11:35:42 +01:00
2018-01-29 16:20:38 -06:00
import AbstractRecentList, { _mapStateToProps } from './AbstractRecentList';
2018-01-17 12:19:10 +01:00
import { getRecentRooms } from '../functions';
2018-01-29 16:20:38 -06:00
import styles, { UNDERLAY_COLOR } from './styles';
2018-01-17 12:19:10 +01:00
2017-12-13 11:35:42 +01:00
/**
* The native container rendering the list of the recently joined rooms.
*
* @extends AbstractRecentList
*/
class RecentList extends AbstractRecentList {
2018-01-17 12:19:10 +01:00
/**
* The datasource wrapper to be used for the display.
*/
dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) =>
r1.conference !== r2.conference
&& r1.dateTimeStamp !== r2.dateTimeStamp
});
2017-12-13 11:35:42 +01:00
/**
* Initializes a new {@code RecentList} instance.
2018-01-17 12:19:10 +01:00
*
* @inheritdoc
2017-12-13 11:35:42 +01:00
*/
2018-02-16 10:06:03 -06:00
constructor(props) {
super(props);
2017-12-13 11:35:42 +01:00
2017-12-19 18:49:36 -06:00
// Bind event handlers so they are only bound once per instance.
2017-12-13 11:35:42 +01:00
this._getAvatarStyle = this._getAvatarStyle.bind(this);
this._onSelect = this._onSelect.bind(this);
this._renderConfDuration = this._renderConfDuration.bind(this);
this._renderRow = this._renderRow.bind(this);
this._renderServerInfo = this._renderServerInfo.bind(this);
}
/**
2017-12-19 18:49:36 -06:00
* Implements React's {@link Component#render()}. Renders a list of recently
* joined rooms.
2017-12-13 11:35:42 +01:00
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { enabled, _recentList } = this.props;
2018-02-16 10:06:03 -06:00
if (!_recentList) {
2017-12-13 11:35:42 +01:00
return null;
}
2018-01-29 16:20:38 -06:00
const listViewDataSource
= this.dataSource.cloneWithRows(getRecentRooms(_recentList));
2018-01-17 12:19:10 +01:00
2017-12-13 11:35:42 +01:00
return (
2018-02-16 10:06:03 -06:00
<View
style = { [
styles.container,
enabled ? null : styles.containerDisabled
2018-02-16 10:06:03 -06:00
] }>
2017-12-13 11:35:42 +01:00
<ListView
2018-01-17 12:19:10 +01:00
dataSource = { listViewDataSource }
2017-12-13 11:35:42 +01:00
enableEmptySections = { true }
renderRow = { this._renderRow } />
</View>
);
}
/**
* Assembles the style array of the avatar based on if the conference was
* hosted on the default Jitsi Meet deployment or on a non-default one
* (based on current app setting).
2017-12-19 18:49:36 -06:00
*
* @param {Object} recentListEntry - The recent list entry being rendered.
* @private
* @returns {Array<Object>}
*/
_getAvatarStyle({ baseURL, serverName }) {
2017-12-13 11:35:42 +01:00
const avatarStyles = [ styles.avatar ];
if (baseURL !== this.props._defaultURL) {
avatarStyles.push(this._getColorForServerName(serverName));
2017-12-13 11:35:42 +01:00
}
return avatarStyles;
}
/**
2017-12-19 18:49:36 -06:00
* Returns a style (color) based on the server name, so then the same server
* will always be rendered with the same avatar color.
*
* @param {string} serverName - The recent list entry being rendered.
* @private
* @returns {Object}
*/
2017-12-13 11:35:42 +01:00
_getColorForServerName(serverName) {
let nameHash = 0;
for (let i = 0; i < serverName.length; i++) {
nameHash += serverName.codePointAt(i);
}
return styles[`avatarRemoteServer${(nameHash % 5) + 1}`];
}
/**
2017-12-19 18:49:36 -06:00
* Renders the conference duration if available.
*
* @param {Object} recentListEntry - The recent list entry being rendered.
* @private
* @returns {ReactElement}
*/
_renderConfDuration({ durationString }) {
if (durationString) {
2017-12-13 11:35:42 +01:00
return (
<View style = { styles.infoWithIcon } >
<Icon
2017-12-19 18:49:36 -06:00
name = 'timer'
2017-12-13 11:35:42 +01:00
style = { styles.inlineIcon } />
2017-12-19 18:49:36 -06:00
<Text style = { styles.confLength }>
{ durationString }
2017-12-13 11:35:42 +01:00
</Text>
</View>
);
}
return null;
}
2017-12-19 18:49:36 -06:00
/**
* Renders the list of recently joined rooms.
*
* @param {Object} data - The row data to be rendered.
* @private
* @returns {ReactElement}
*/
_renderRow(data) {
return (
<TouchableHighlight
onPress = { this._onSelect(data.conference) }
underlayColor = { UNDERLAY_COLOR } >
<View style = { styles.row } >
<View style = { styles.avatarContainer } >
<View style = { this._getAvatarStyle(data) } >
<Text style = { styles.avatarContent }>
{ data.initials }
</Text>
</View>
</View>
<View style = { styles.detailsContainer } >
<Text
numberOfLines = { 1 }
style = { styles.roomName }>
{ data.room }
</Text>
<View style = { styles.infoWithIcon } >
<Icon
name = 'event_note'
style = { styles.inlineIcon } />
<Text style = { styles.date }>
{ data.dateString }
</Text>
</View>
{ this._renderConfDuration(data) }
{ this._renderServerInfo(data) }
2017-12-19 18:49:36 -06:00
</View>
</View>
</TouchableHighlight>
);
}
/**
* Renders the server info component based on whether the entry was on a
* different server.
*
* @param {Object} recentListEntry - The recent list entry being rendered.
* @private
* @returns {ReactElement}
*/
_renderServerInfo({ baseURL, serverName }) {
if (baseURL !== this.props._defaultURL) {
return (
<View style = { styles.infoWithIcon } >
<Icon
name = 'public'
style = { styles.inlineIcon } />
<Text style = { styles.serverName }>
{ serverName }
</Text>
</View>
);
}
return null;
}
2017-12-13 11:35:42 +01:00
}
export default connect(_mapStateToProps)(RecentList);