Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Filmstrip.native.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 isNarrowAspectRatio_ = isNarrowAspectRatio(this);
  49. const filmstripStyle
  50. = isNarrowAspectRatio_
  51. ? styles.filmstripNarrow
  52. : styles.filmstripWide;
  53. return (
  54. <Container
  55. style = { filmstripStyle }
  56. visible = { this.props._visible }>
  57. <ScrollView
  58. horizontal = { isNarrowAspectRatio_ }
  59. showsHorizontalScrollIndicator = { false }
  60. showsVerticalScrollIndicator = { false }>
  61. {
  62. /* eslint-disable react/jsx-wrap-multilines */
  63. this._sort(this.props._participants)
  64. .map(p =>
  65. <Thumbnail
  66. key = { p.id }
  67. participant = { p } />)
  68. /* eslint-enable react/jsx-wrap-multilines */
  69. }
  70. </ScrollView>
  71. </Container>
  72. );
  73. }
  74. /**
  75. * Sorts a specific array of {@code Participant}s in display order.
  76. *
  77. * @param {Participant[]} participants - The array of {@code Participant}s
  78. * to sort in display order.
  79. * @private
  80. * @returns {Participant[]} A new array containing the elements of the
  81. * specified {@code participants} array sorted in display order.
  82. */
  83. _sort(participants) {
  84. // XXX Array.prototype.sort() is not appropriate because (1) it operates
  85. // in place and (2) it is not necessarily stable.
  86. const sortedParticipants = [];
  87. // Group the remote participants so that the local participant does not
  88. // appear in between remote participants. Have the remote participants
  89. // from right to left with the newest added/joined to the leftmost side.
  90. for (let i = participants.length - 1; i >= 0; --i) {
  91. const p = participants[i];
  92. p.local || sortedParticipants.push(p);
  93. }
  94. // Have the local participant at the rightmost side.
  95. for (let i = participants.length - 1; i >= 0; --i) {
  96. const p = participants[i];
  97. p.local && sortedParticipants.push(p);
  98. }
  99. return sortedParticipants;
  100. }
  101. }
  102. /**
  103. * Function that maps parts of Redux state tree into component props.
  104. *
  105. * @param {Object} state - Redux state.
  106. * @private
  107. * @returns {{
  108. * _participants: Participant[],
  109. * _visible: boolean
  110. * }}
  111. */
  112. function _mapStateToProps(state) {
  113. const participants = state['features/base/participants'];
  114. return {
  115. /**
  116. * The participants in the conference.
  117. *
  118. * @private
  119. * @type {Participant[]}
  120. */
  121. _participants: participants,
  122. /**
  123. * The indicator which determines whether the filmstrip is visible. The
  124. * mobile/react-native Filmstrip is visible when there are at least 2
  125. * 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));