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.

OverflowMenu.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  4. import { BottomSheet, hideDialog, isDialogOpen } from '../../../base/dialog';
  5. import { getFeatureFlag, REACTIONS_ENABLED } from '../../../base/flags';
  6. import { connect } from '../../../base/redux';
  7. import { StyleType } from '../../../base/styles';
  8. import { SharedDocumentButton } from '../../../etherpad';
  9. import { InviteButton } from '../../../invite';
  10. import { AudioRouteButton } from '../../../mobile/audio-mode';
  11. import { ParticipantsPaneButton } from '../../../participants-pane/components/native';
  12. import { ReactionMenu } from '../../../reactions/components';
  13. import { LiveStreamButton, RecordButton } from '../../../recording';
  14. import SecurityDialogButton from '../../../security/components/security-dialog/SecurityDialogButton';
  15. import { SharedVideoButton } from '../../../shared-video/components';
  16. import { ClosedCaptionButton } from '../../../subtitles';
  17. import { TileViewButton } from '../../../video-layout';
  18. import { getMovableButtons } from '../../functions.native';
  19. import HelpButton from '../HelpButton';
  20. import MuteEveryoneButton from '../MuteEveryoneButton';
  21. import MuteEveryonesVideoButton from '../MuteEveryonesVideoButton';
  22. import AudioOnlyButton from './AudioOnlyButton';
  23. import RaiseHandButton from './RaiseHandButton';
  24. import ScreenSharingButton from './ScreenSharingButton.js';
  25. import ToggleCameraButton from './ToggleCameraButton';
  26. /**
  27. * The type of the React {@code Component} props of {@link OverflowMenu}.
  28. */
  29. type Props = {
  30. /**
  31. * The color-schemed stylesheet of the dialog feature.
  32. */
  33. _bottomSheetStyles: StyleType,
  34. /**
  35. * True if the overflow menu is currently visible, false otherwise.
  36. */
  37. _isOpen: boolean,
  38. /**
  39. * Whether the recoding button should be enabled or not.
  40. */
  41. _recordingEnabled: boolean,
  42. /**
  43. * The width of the screen.
  44. */
  45. _width: number,
  46. /**
  47. * Whether or not the reactions feature is enabled.
  48. */
  49. _reactionsEnabled: boolean,
  50. /**
  51. * Used for hiding the dialog when the selection was completed.
  52. */
  53. dispatch: Function
  54. };
  55. type State = {
  56. /**
  57. * True if the bottom scheet is scrolled to the top.
  58. */
  59. scrolledToTop: boolean
  60. }
  61. /**
  62. * The exported React {@code Component}. We need it to execute
  63. * {@link hideDialog}.
  64. *
  65. * XXX It does not break our coding style rule to not utilize globals for state,
  66. * because it is merely another name for {@code export}'s {@code default}.
  67. */
  68. let OverflowMenu_; // eslint-disable-line prefer-const
  69. /**
  70. * Implements a React {@code Component} with some extra actions in addition to
  71. * those in the toolbar.
  72. */
  73. class OverflowMenu extends PureComponent<Props, State> {
  74. /**
  75. * Initializes a new {@code OverflowMenu} instance.
  76. *
  77. * @inheritdoc
  78. */
  79. constructor(props: Props) {
  80. super(props);
  81. this.state = {
  82. scrolledToTop: true
  83. };
  84. // Bind event handlers so they are only bound once per instance.
  85. this._onCancel = this._onCancel.bind(this);
  86. this._renderReactionMenu = this._renderReactionMenu.bind(this);
  87. }
  88. /**
  89. * Implements React's {@link Component#render()}.
  90. *
  91. * @inheritdoc
  92. * @returns {ReactElement}
  93. */
  94. render() {
  95. const { _bottomSheetStyles, _width, _reactionsEnabled } = this.props;
  96. const toolbarButtons = getMovableButtons(_width);
  97. const buttonProps = {
  98. afterClick: this._onCancel,
  99. showLabel: true,
  100. styles: _bottomSheetStyles.buttons
  101. };
  102. const topButtonProps = {
  103. afterClick: this._onCancel,
  104. showLabel: true,
  105. styles: {
  106. ..._bottomSheetStyles.buttons,
  107. style: {
  108. ..._bottomSheetStyles.buttons.style,
  109. borderTopLeftRadius: 16,
  110. borderTopRightRadius: 16,
  111. paddingTop: 16
  112. }
  113. }
  114. };
  115. return (
  116. <BottomSheet
  117. onCancel = { this._onCancel }
  118. renderFooter = { _reactionsEnabled && !toolbarButtons.has('raisehand')
  119. ? this._renderReactionMenu
  120. : null }>
  121. <AudioRouteButton { ...topButtonProps } />
  122. <ParticipantsPaneButton { ...buttonProps } />
  123. {!toolbarButtons.has('invite') && <InviteButton { ...buttonProps } />}
  124. <AudioOnlyButton { ...buttonProps } />
  125. {!_reactionsEnabled && !toolbarButtons.has('raisehand') && <RaiseHandButton { ...buttonProps } />}
  126. <SecurityDialogButton { ...buttonProps } />
  127. <ScreenSharingButton { ...buttonProps } />
  128. {!toolbarButtons.has('togglecamera') && <ToggleCameraButton { ...buttonProps } />}
  129. {!toolbarButtons.has('tileview') && <TileViewButton { ...buttonProps } />}
  130. <RecordButton { ...buttonProps } />
  131. <LiveStreamButton { ...buttonProps } />
  132. <SharedVideoButton { ...buttonProps } />
  133. <ClosedCaptionButton { ...buttonProps } />
  134. <SharedDocumentButton { ...buttonProps } />
  135. <MuteEveryoneButton { ...buttonProps } />
  136. <MuteEveryonesVideoButton { ...buttonProps } />
  137. <HelpButton { ...buttonProps } />
  138. </BottomSheet>
  139. );
  140. }
  141. _onCancel: () => boolean;
  142. /**
  143. * Hides this {@code OverflowMenu}.
  144. *
  145. * @private
  146. * @returns {boolean}
  147. */
  148. _onCancel() {
  149. if (this.props._isOpen) {
  150. this.props.dispatch(hideDialog(OverflowMenu_));
  151. return true;
  152. }
  153. return false;
  154. }
  155. _renderReactionMenu: () => React$Element<any>;
  156. /**
  157. * Functoin to render the reaction menu as the footer of the bottom sheet.
  158. *
  159. * @returns {React$Element}
  160. */
  161. _renderReactionMenu() {
  162. return (<ReactionMenu
  163. onCancel = { this._onCancel }
  164. overflowMenu = { true } />);
  165. }
  166. }
  167. /**
  168. * Function that maps parts of Redux state tree into component props.
  169. *
  170. * @param {Object} state - Redux state.
  171. * @private
  172. * @returns {Props}
  173. */
  174. function _mapStateToProps(state) {
  175. return {
  176. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  177. _isOpen: isDialogOpen(state, OverflowMenu_),
  178. _width: state['features/base/responsive-ui'].clientWidth,
  179. _reactionsEnabled: getFeatureFlag(state, REACTIONS_ENABLED, false)
  180. };
  181. }
  182. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  183. export default OverflowMenu_;