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

Filmstrip.native.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { ScrollView } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { Container } from '../../base/react';
  6. import Thumbnail from './Thumbnail';
  7. import { styles } from './_';
  8. /**
  9. * Implements a React {@link Component} which represents the filmstrip on
  10. * mobile/React Native.
  11. *
  12. * @extends Component
  13. */
  14. class Filmstrip extends Component {
  15. /**
  16. * Filmstrip component's property types.
  17. *
  18. * @static
  19. */
  20. static propTypes = {
  21. /**
  22. * The participants in the conference.
  23. *
  24. * @private
  25. * @type {Participant[]}
  26. */
  27. _participants: React.PropTypes.array,
  28. /**
  29. * The indicator which determines whether the filmstrip is visible.
  30. *
  31. * @private
  32. * @type {boolean}
  33. */
  34. _visible: React.PropTypes.bool.isRequired
  35. };
  36. /**
  37. * Implements React's {@link Component#render()}.
  38. *
  39. * @inheritdoc
  40. * @returns {ReactElement}
  41. */
  42. render() {
  43. return (
  44. <Container
  45. style = { styles.filmstrip }
  46. visible = { this.props._visible }>
  47. <ScrollView
  48. // eslint-disable-next-line react/jsx-curly-spacing
  49. contentContainerStyle = {
  50. styles.filmstripScrollViewContentContainer
  51. } // eslint-disable-line react/jsx-curly-spacing
  52. horizontal = { true }
  53. showsHorizontalScrollIndicator = { false }
  54. showsVerticalScrollIndicator = { false }>
  55. {
  56. this._sort(this.props._participants)
  57. .map(p =>
  58. <Thumbnail
  59. key = { p.id }
  60. participant = { p } />)
  61. }
  62. </ScrollView>
  63. </Container>
  64. );
  65. }
  66. /**
  67. * Sorts a specific array of <tt>Participant</tt>s in display order.
  68. *
  69. * @param {Participant[]} participants - The array of <tt>Participant</tt>s
  70. * to sort in display order.
  71. * @private
  72. * @returns {Participant[]} A new array containing the elements of the
  73. * specified <tt>participants</tt> array sorted in display order.
  74. */
  75. _sort(participants) {
  76. // XXX Array.prototype.sort() is not appropriate because (1) it operates
  77. // in place and (2) it is not necessarily stable.
  78. const sortedParticipants = [];
  79. // Group the remote participants so that the local participant does not
  80. // appear in between remote participants. Have the remote participants
  81. // from right to left with the newest added/joined to the leftmost side.
  82. for (let i = participants.length - 1; i >= 0; --i) {
  83. const p = participants[i];
  84. p.local || sortedParticipants.push(p);
  85. }
  86. // Have the local participant at the rightmost side.
  87. for (let i = participants.length - 1; i >= 0; --i) {
  88. const p = participants[i];
  89. p.local && sortedParticipants.push(p);
  90. }
  91. return sortedParticipants;
  92. }
  93. }
  94. /**
  95. * Function that maps parts of Redux state tree into component props.
  96. *
  97. * @param {Object} state - Redux state.
  98. * @private
  99. * @returns {{
  100. * _participants: Participant[],
  101. * _visible: boolean
  102. * }}
  103. */
  104. function _mapStateToProps(state) {
  105. return {
  106. /**
  107. * The participants in the conference.
  108. *
  109. * @private
  110. * @type {Participant[]}
  111. */
  112. _participants: state['features/base/participants'],
  113. /**
  114. * The indicator which determines whether the filmstrip is visible.
  115. *
  116. * XXX The React Component Filmstrip is used on mobile only at the time
  117. * of this writing and on mobile the filmstrip is visible when the
  118. * toolbar is not.
  119. *
  120. * @private
  121. * @type {boolean}
  122. */
  123. _visible: !state['features/toolbox'].visible
  124. };
  125. }
  126. export default connect(_mapStateToProps)(Filmstrip);