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.7KB

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