Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Filmstrip.native.js 4.4KB

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