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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import React, { PureComponent } from 'react';
  2. import { ViewStyle } from 'react-native';
  3. import { Divider } from 'react-native-paper';
  4. import { connect } from 'react-redux';
  5. import { IReduxState, IStore } from '../../../app/types';
  6. import { hideSheet } from '../../../base/dialog/actions';
  7. import BottomSheet from '../../../base/dialog/components/native/BottomSheet';
  8. import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
  9. import SettingsButton from '../../../base/settings/components/native/SettingsButton';
  10. import BreakoutRoomsButton
  11. from '../../../breakout-rooms/components/native/BreakoutRoomsButton';
  12. import SharedDocumentButton from '../../../etherpad/components/SharedDocumentButton.native';
  13. import ReactionMenu from '../../../reactions/components/native/ReactionMenu';
  14. import { shouldDisplayReactionsButtons } from '../../../reactions/functions.any';
  15. import LiveStreamButton from '../../../recording/components/LiveStream/native/LiveStreamButton';
  16. import RecordButton from '../../../recording/components/Recording/native/RecordButton';
  17. import SecurityDialogButton
  18. from '../../../security/components/security-dialog/native/SecurityDialogButton';
  19. import SharedVideoButton from '../../../shared-video/components/native/SharedVideoButton';
  20. import SpeakerStatsButton from '../../../speaker-stats/components/native/SpeakerStatsButton';
  21. import { isSpeakerStatsDisabled } from '../../../speaker-stats/functions';
  22. import ClosedCaptionButton from '../../../subtitles/components/native/ClosedCaptionButton';
  23. import TileViewButton from '../../../video-layout/components/TileViewButton';
  24. import styles from '../../../video-menu/components/native/styles';
  25. import WhiteboardButton from '../../../whiteboard/components/native/WhiteboardButton';
  26. import { customOverflowMenuButtonPressed } from '../../actions.native';
  27. import { getMovableButtons } from '../../functions.native';
  28. import AudioOnlyButton from './AudioOnlyButton';
  29. import CustomOptionButton from './CustomOptionButton';
  30. import LinkToSalesforceButton from './LinkToSalesforceButton';
  31. import OpenCarmodeButton from './OpenCarmodeButton';
  32. import RaiseHandButton from './RaiseHandButton';
  33. import ScreenSharingButton from './ScreenSharingButton';
  34. /**
  35. * The type of the React {@code Component} props of {@link OverflowMenu}.
  36. */
  37. interface IProps {
  38. /**
  39. * Custom Toolbar buttons.
  40. */
  41. _customToolbarButtons?: Array<{ backgroundColor?: string; icon: string; id: string; text: string; }>;
  42. /**
  43. * True if breakout rooms feature is available, false otherwise.
  44. */
  45. _isBreakoutRoomsSupported?: boolean;
  46. /**
  47. * True if the overflow menu is currently visible, false otherwise.
  48. */
  49. _isOpen: boolean;
  50. /**
  51. * Whether or not speaker stats is disable.
  52. */
  53. _isSpeakerStatsDisabled?: boolean;
  54. /**
  55. * Whether the recoding button should be enabled or not.
  56. */
  57. _recordingEnabled: boolean;
  58. /**
  59. * Whether or not any reactions buttons should be displayed.
  60. */
  61. _shouldDisplayReactionsButtons: boolean;
  62. /**
  63. * The width of the screen.
  64. */
  65. _width: number;
  66. /**
  67. * Used for hiding the dialog when the selection was completed.
  68. */
  69. dispatch: IStore['dispatch'];
  70. }
  71. interface IState {
  72. /**
  73. * True if the bottom sheet is scrolled to the top.
  74. */
  75. scrolledToTop: boolean;
  76. }
  77. /**
  78. * Implements a React {@code Component} with some extra actions in addition to
  79. * those in the toolbar.
  80. */
  81. class OverflowMenu extends PureComponent<IProps, IState> {
  82. /**
  83. * Initializes a new {@code OverflowMenu} instance.
  84. *
  85. * @inheritdoc
  86. */
  87. constructor(props: IProps) {
  88. super(props);
  89. this.state = {
  90. scrolledToTop: true
  91. };
  92. // Bind event handlers so they are only bound once per instance.
  93. this._onCancel = this._onCancel.bind(this);
  94. this._renderReactionMenu = this._renderReactionMenu.bind(this);
  95. }
  96. /**
  97. * Implements React's {@link Component#render()}.
  98. *
  99. * @inheritdoc
  100. * @returns {ReactElement}
  101. */
  102. render() {
  103. const {
  104. _isBreakoutRoomsSupported,
  105. _isSpeakerStatsDisabled,
  106. _shouldDisplayReactionsButtons,
  107. _width,
  108. dispatch
  109. } = this.props;
  110. const toolbarButtons = getMovableButtons(_width);
  111. const buttonProps = {
  112. afterClick: this._onCancel,
  113. showLabel: true,
  114. styles: bottomSheetStyles.buttons
  115. };
  116. const topButtonProps = {
  117. afterClick: this._onCancel,
  118. dispatch,
  119. showLabel: true,
  120. styles: {
  121. ...bottomSheetStyles.buttons,
  122. style: {
  123. ...bottomSheetStyles.buttons.style,
  124. borderTopLeftRadius: 16,
  125. borderTopRightRadius: 16
  126. }
  127. }
  128. };
  129. return (
  130. <BottomSheet
  131. renderFooter = { _shouldDisplayReactionsButtons && !toolbarButtons.has('raisehand')
  132. ? this._renderReactionMenu
  133. : undefined }>
  134. { this._renderCustomOverflowMenuButtons(topButtonProps) }
  135. <OpenCarmodeButton { ...topButtonProps } />
  136. <AudioOnlyButton { ...buttonProps } />
  137. {
  138. !_shouldDisplayReactionsButtons && !toolbarButtons.has('raisehand')
  139. && <RaiseHandButton { ...buttonProps } />
  140. }
  141. {/* @ts-ignore */}
  142. <Divider style = { styles.divider as ViewStyle } />
  143. <SecurityDialogButton { ...buttonProps } />
  144. <RecordButton { ...buttonProps } />
  145. <LiveStreamButton { ...buttonProps } />
  146. <LinkToSalesforceButton { ...buttonProps } />
  147. <WhiteboardButton { ...buttonProps } />
  148. {/* @ts-ignore */}
  149. <Divider style = { styles.divider as ViewStyle } />
  150. <SharedVideoButton { ...buttonProps } />
  151. {!toolbarButtons.has('screensharing') && <ScreenSharingButton { ...buttonProps } />}
  152. {!_isSpeakerStatsDisabled && <SpeakerStatsButton { ...buttonProps } />}
  153. {!toolbarButtons.has('tileview') && <TileViewButton { ...buttonProps } />}
  154. {_isBreakoutRoomsSupported && <BreakoutRoomsButton { ...buttonProps } />}
  155. {/* @ts-ignore */}
  156. <Divider style = { styles.divider as ViewStyle } />
  157. <ClosedCaptionButton { ...buttonProps } />
  158. <SharedDocumentButton { ...buttonProps } />
  159. <SettingsButton { ...buttonProps } />
  160. </BottomSheet>
  161. );
  162. }
  163. /**
  164. * Hides this {@code OverflowMenu}.
  165. *
  166. * @private
  167. * @returns {void}
  168. */
  169. _onCancel() {
  170. this.props.dispatch(hideSheet());
  171. }
  172. /**
  173. * Function to render the reaction menu as the footer of the bottom sheet.
  174. *
  175. * @returns {React.ReactElement}
  176. */
  177. _renderReactionMenu() {
  178. return (
  179. <ReactionMenu
  180. onCancel = { this._onCancel }
  181. overflowMenu = { true } />
  182. );
  183. }
  184. /**
  185. * Function to render the custom buttons for the overflow menu.
  186. *
  187. * @param {Object} topButtonProps - Button properties.
  188. * @returns {React.ReactElement}
  189. */
  190. _renderCustomOverflowMenuButtons(topButtonProps: Object) {
  191. const { _customToolbarButtons, dispatch } = this.props;
  192. if (!_customToolbarButtons?.length) {
  193. return;
  194. }
  195. return (
  196. <>
  197. {
  198. _customToolbarButtons.map(({ id, text, icon, ...rest }) => (
  199. <CustomOptionButton
  200. { ...rest }
  201. { ...topButtonProps }
  202. /* eslint-disable react/jsx-no-bind */
  203. handleClick = { () =>
  204. dispatch(customOverflowMenuButtonPressed(id, text))
  205. }
  206. icon = { icon }
  207. key = { id }
  208. text = { text } />
  209. ))
  210. }
  211. <Divider style = { styles.divider as ViewStyle } />
  212. </>
  213. );
  214. }
  215. }
  216. /**
  217. * Function that maps parts of Redux state tree into component props.
  218. *
  219. * @param {Object} state - Redux state.
  220. * @private
  221. * @returns {IProps}
  222. */
  223. function _mapStateToProps(state: IReduxState) {
  224. const { conference } = state['features/base/conference'];
  225. const { customToolbarButtons } = state['features/base/config'];
  226. return {
  227. _customToolbarButtons: customToolbarButtons,
  228. _isBreakoutRoomsSupported: conference?.getBreakoutRooms()?.isSupported(),
  229. _isSpeakerStatsDisabled: isSpeakerStatsDisabled(state),
  230. _shouldDisplayReactionsButtons: shouldDisplayReactionsButtons(state),
  231. _width: state['features/base/responsive-ui'].clientWidth
  232. };
  233. }
  234. export default connect(_mapStateToProps)(OverflowMenu);