You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Filmstrip.js 4.0KB

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