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

FilmStrip.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { ScrollView } from 'react-native';
  4. import { Container } from '../../base/react';
  5. import Thumbnail from './Thumbnail';
  6. import { styles } from './_';
  7. /**
  8. * React component for film strip.
  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. visible: React.PropTypes.bool.isRequired
  27. }
  28. /**
  29. * Implements React's {@link Component#render()}.
  30. *
  31. * @inheritdoc
  32. */
  33. render() {
  34. return (
  35. <Container
  36. style = { styles.filmStrip }
  37. visible = { this.props.visible }>
  38. <ScrollView
  39. // eslint-disable-next-line react/jsx-curly-spacing
  40. contentContainerStyle = {
  41. styles.filmStripScrollViewContentContainer
  42. } // eslint-disable-line react/jsx-curly-spacing
  43. horizontal = { true }
  44. showsHorizontalScrollIndicator = { false }
  45. showsVerticalScrollIndicator = { false }>
  46. {
  47. this._sort(this.props._participants)
  48. .map(p =>
  49. <Thumbnail
  50. key = { p.id }
  51. participant = { p } />)
  52. }
  53. </ScrollView>
  54. </Container>
  55. );
  56. }
  57. /**
  58. * Sorts a specific array of <tt>Participant</tt>s in display order.
  59. *
  60. * @param {Participant[]} participants - The array of <tt>Participant</tt>s
  61. * to sort in display order.
  62. * @private
  63. * @returns {Participant[]} A new array containing the elements of the
  64. * specified <tt>participants</tt> array sorted in display order.
  65. */
  66. _sort(participants) {
  67. // XXX Array.prototype.sort() is not appropriate because (1) it operates
  68. // in place and (2) it is not necessarily stable.
  69. const sortedParticipants = [];
  70. // Group the remote participants so that the local participant does not
  71. // appear in between remote participants. Have the remote participants
  72. // from right to left with the newest added/joined to the leftmost side.
  73. for (let i = participants.length - 1; i >= 0; --i) {
  74. const p = participants[i];
  75. p.local || sortedParticipants.push(p);
  76. }
  77. // Have the local participant at the rightmost side.
  78. for (let i = participants.length - 1; i >= 0; --i) {
  79. const p = participants[i];
  80. p.local && sortedParticipants.push(p);
  81. }
  82. return sortedParticipants;
  83. }
  84. }
  85. /**
  86. * Function that maps parts of Redux state tree into component props.
  87. *
  88. * @param {Object} state - Redux state.
  89. * @returns {{
  90. * _participants: Participant[],
  91. * }}
  92. */
  93. function mapStateToProps(state) {
  94. return {
  95. /**
  96. * The participants in the conference.
  97. *
  98. * @private
  99. * @type {Participant[]}
  100. */
  101. _participants: state['features/base/participants']
  102. };
  103. }
  104. export default connect(mapStateToProps)(FilmStrip);