Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Filmstrip.native.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 { Container } from '../../base/react';
  7. import {
  8. isNarrowAspectRatio,
  9. makeAspectRatioAware
  10. } from '../../base/responsive-ui';
  11. import { styles } from './_';
  12. import Thumbnail from './Thumbnail';
  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 isNarrowAspectRatio_ = isNarrowAspectRatio(this);
  49. const filmstripStyle
  50. = isNarrowAspectRatio_
  51. ? styles.filmstripNarrow
  52. : styles.filmstripWide;
  53. const {
  54. _participants: participants,
  55. _visible: visible } = this.props;
  56. return (
  57. <Container
  58. style = { filmstripStyle }
  59. visible = { visible }>
  60. <ScrollView
  61. horizontal = { isNarrowAspectRatio_ }
  62. showsHorizontalScrollIndicator = { false }
  63. showsVerticalScrollIndicator = { false }>
  64. {
  65. /* eslint-disable react/jsx-wrap-multilines */
  66. this._sort(participants, isNarrowAspectRatio_)
  67. .map(p =>
  68. <Thumbnail
  69. key = { p.id }
  70. participant = { p } />)
  71. /* eslint-enable react/jsx-wrap-multilines */
  72. }
  73. </ScrollView>
  74. </Container>
  75. );
  76. }
  77. /**
  78. * Sorts a specific array of {@code Participant}s in display order.
  79. *
  80. * @param {Participant[]} participants - The array of {@code Participant}s
  81. * to sort in display order.
  82. * @param {boolean} isNarrowAspectRatio_ - Indicates if the aspect ratio is
  83. * wide or narrow.
  84. * @private
  85. * @returns {Participant[]} A new array containing the elements of the
  86. * specified {@code participants} array sorted in display order.
  87. */
  88. _sort(participants, isNarrowAspectRatio_) {
  89. // XXX Array.prototype.sort() is not appropriate because (1) it operates
  90. // in place and (2) it is not necessarily stable.
  91. const sortedParticipants = [
  92. // First put the local participant.
  93. ...participants.filter(p => p.local),
  94. // Then the remote participants, which are sorted by join order.
  95. ...participants.filter(p => !p.local)
  96. ];
  97. if (isNarrowAspectRatio_) {
  98. // When the narrow aspect ratio is used, we want to have the remote
  99. // participants from right to left with the newest added/joined to
  100. // the leftmost side. The local participant is the leftmost item.
  101. sortedParticipants.reverse();
  102. }
  103. return sortedParticipants;
  104. }
  105. }
  106. /**
  107. * Function that maps parts of Redux state tree into component props.
  108. *
  109. * @param {Object} state - Redux state.
  110. * @private
  111. * @returns {{
  112. * _participants: Participant[],
  113. * _visible: boolean
  114. * }}
  115. */
  116. function _mapStateToProps(state) {
  117. const participants = state['features/base/participants'];
  118. const { visible } = state['features/filmstrip'];
  119. return {
  120. /**
  121. * The participants in the conference.
  122. *
  123. * @private
  124. * @type {Participant[]}
  125. */
  126. _participants: participants,
  127. /**
  128. * The indicator which determines whether the filmstrip is visible. The
  129. * mobile/react-native Filmstrip is visible when there are at least 2
  130. * participants in the conference (including the local one).
  131. *
  132. * @private
  133. * @type {boolean}
  134. */
  135. _visible: visible && participants.length > 1
  136. };
  137. }
  138. export default connect(_mapStateToProps)(makeAspectRatioAware(Filmstrip));