Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RecentList.native.js 6.2KB

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