您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RecentList.native.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import React from 'react';
  2. import { ListView, Text, TouchableHighlight, View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { Icon } from '../../base/font-icons';
  5. import AbstractRecentList, { _mapStateToProps } from './AbstractRecentList';
  6. import { getRecentRooms } from '../functions';
  7. import styles, { UNDERLAY_COLOR } from './styles';
  8. /**
  9. * The native container rendering the list of the recently joined rooms.
  10. *
  11. * @extends AbstractRecentList
  12. */
  13. class RecentList extends AbstractRecentList {
  14. /**
  15. * The datasource wrapper to be used for the display.
  16. */
  17. dataSource = new ListView.DataSource({
  18. rowHasChanged: (r1, r2) =>
  19. r1.conference !== r2.conference
  20. && r1.dateTimeStamp !== r2.dateTimeStamp
  21. });
  22. /**
  23. * Initializes a new {@code RecentList} instance.
  24. *
  25. * @inheritdoc
  26. */
  27. constructor(props) {
  28. super(props);
  29. // Bind event handlers so they are only bound once per instance.
  30. this._getAvatarStyle = this._getAvatarStyle.bind(this);
  31. this._onSelect = this._onSelect.bind(this);
  32. this._renderConfDuration = this._renderConfDuration.bind(this);
  33. this._renderRow = this._renderRow.bind(this);
  34. this._renderServerInfo = this._renderServerInfo.bind(this);
  35. }
  36. /**
  37. * Implements React's {@link Component#render()}. Renders a list of recently
  38. * joined rooms.
  39. *
  40. * @inheritdoc
  41. * @returns {ReactElement}
  42. */
  43. render() {
  44. const { enabled, _recentList } = this.props;
  45. if (!_recentList) {
  46. return null;
  47. }
  48. const listViewDataSource
  49. = this.dataSource.cloneWithRows(getRecentRooms(_recentList));
  50. return (
  51. <View
  52. style = { [
  53. styles.container,
  54. enabled ? null : styles.containerDisabled
  55. ] }>
  56. <ListView
  57. dataSource = { listViewDataSource }
  58. enableEmptySections = { true }
  59. renderRow = { this._renderRow } />
  60. </View>
  61. );
  62. }
  63. /**
  64. * Assembles the style array of the avatar based on if the conference was
  65. * hosted on the default Jitsi Meet deployment or on a non-default one
  66. * (based on current app setting).
  67. *
  68. * @param {Object} recentListEntry - The recent list entry being rendered.
  69. * @private
  70. * @returns {Array<Object>}
  71. */
  72. _getAvatarStyle({ baseURL, serverName }) {
  73. const avatarStyles = [ styles.avatar ];
  74. if (baseURL !== this.props._defaultURL) {
  75. avatarStyles.push(this._getColorForServerName(serverName));
  76. }
  77. return avatarStyles;
  78. }
  79. /**
  80. * Returns a style (color) based on the server name, so then the same server
  81. * will always be rendered with the same avatar color.
  82. *
  83. * @param {string} serverName - The recent list entry being rendered.
  84. * @private
  85. * @returns {Object}
  86. */
  87. _getColorForServerName(serverName) {
  88. let nameHash = 0;
  89. for (let i = 0; i < serverName.length; i++) {
  90. nameHash += serverName.codePointAt(i);
  91. }
  92. return styles[`avatarRemoteServer${(nameHash % 5) + 1}`];
  93. }
  94. /**
  95. * Renders the conference duration if available.
  96. *
  97. * @param {Object} recentListEntry - The recent list entry being rendered.
  98. * @private
  99. * @returns {ReactElement}
  100. */
  101. _renderConfDuration({ durationString }) {
  102. if (durationString) {
  103. return (
  104. <View style = { styles.infoWithIcon } >
  105. <Icon
  106. name = 'timer'
  107. style = { styles.inlineIcon } />
  108. <Text style = { styles.confLength }>
  109. { durationString }
  110. </Text>
  111. </View>
  112. );
  113. }
  114. return null;
  115. }
  116. /**
  117. * Renders the list of recently joined rooms.
  118. *
  119. * @param {Object} data - The row data to be rendered.
  120. * @private
  121. * @returns {ReactElement}
  122. */
  123. _renderRow(data) {
  124. return (
  125. <TouchableHighlight
  126. onPress = { this._onSelect(data.conference) }
  127. underlayColor = { UNDERLAY_COLOR } >
  128. <View style = { styles.row } >
  129. <View style = { styles.avatarContainer } >
  130. <View style = { this._getAvatarStyle(data) } >
  131. <Text style = { styles.avatarContent }>
  132. { data.initials }
  133. </Text>
  134. </View>
  135. </View>
  136. <View style = { styles.detailsContainer } >
  137. <Text
  138. numberOfLines = { 1 }
  139. style = { styles.roomName }>
  140. { data.room }
  141. </Text>
  142. <View style = { styles.infoWithIcon } >
  143. <Icon
  144. name = 'event_note'
  145. style = { styles.inlineIcon } />
  146. <Text style = { styles.date }>
  147. { data.dateString }
  148. </Text>
  149. </View>
  150. { this._renderConfDuration(data) }
  151. { this._renderServerInfo(data) }
  152. </View>
  153. </View>
  154. </TouchableHighlight>
  155. );
  156. }
  157. /**
  158. * Renders the server info component based on whether the entry was on a
  159. * different server.
  160. *
  161. * @param {Object} recentListEntry - The recent list entry being rendered.
  162. * @private
  163. * @returns {ReactElement}
  164. */
  165. _renderServerInfo({ baseURL, serverName }) {
  166. if (baseURL !== this.props._defaultURL) {
  167. return (
  168. <View style = { styles.infoWithIcon } >
  169. <Icon
  170. name = 'public'
  171. style = { styles.inlineIcon } />
  172. <Text style = { styles.serverName }>
  173. { serverName }
  174. </Text>
  175. </View>
  176. );
  177. }
  178. return null;
  179. }
  180. }
  181. export default connect(_mapStateToProps)(RecentList);