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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { Platform } from 'react-native';
  4. import Collapsible from 'react-native-collapsible';
  5. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  6. import { BottomSheet, hideDialog, isDialogOpen } from '../../../base/dialog';
  7. import { CHAT_ENABLED, IOS_RECORDING_ENABLED, getFeatureFlag } from '../../../base/flags';
  8. import { connect } from '../../../base/redux';
  9. import { StyleType } from '../../../base/styles';
  10. import { SharedDocumentButton } from '../../../etherpad';
  11. import { InfoDialogButton, InviteButton } from '../../../invite';
  12. import { AudioRouteButton } from '../../../mobile/audio-mode';
  13. import { LiveStreamButton, RecordButton } from '../../../recording';
  14. import { RoomLockButton } from '../../../room-lock';
  15. import { ClosedCaptionButton } from '../../../subtitles';
  16. import { TileViewButton } from '../../../video-layout';
  17. import HelpButton from '../HelpButton';
  18. import AudioOnlyButton from './AudioOnlyButton';
  19. import MoreOptionsButton from './MoreOptionsButton';
  20. import RaiseHandButton from './RaiseHandButton';
  21. import ToggleCameraButton from './ToggleCameraButton';
  22. /**
  23. * The type of the React {@code Component} props of {@link OverflowMenu}.
  24. */
  25. type Props = {
  26. /**
  27. * The color-schemed stylesheet of the dialog feature.
  28. */
  29. _bottomSheetStyles: StyleType,
  30. /**
  31. * Whether the chat feature has been enabled. The meeting info button will be displayed in its place when disabled.
  32. */
  33. _chatEnabled: boolean,
  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. * Used for hiding the dialog when the selection was completed.
  44. */
  45. dispatch: Function
  46. };
  47. type State = {
  48. /**
  49. * True if the bottom scheet is scrolled to the top.
  50. */
  51. scrolledToTop: boolean,
  52. /**
  53. * True if the 'more' button set needas to be rendered.
  54. */
  55. showMore: boolean
  56. }
  57. /**
  58. * The exported React {@code Component}. We need it to execute
  59. * {@link hideDialog}.
  60. *
  61. * XXX It does not break our coding style rule to not utilize globals for state,
  62. * because it is merely another name for {@code export}'s {@code default}.
  63. */
  64. let OverflowMenu_; // eslint-disable-line prefer-const
  65. /**
  66. * Implements a React {@code Component} with some extra actions in addition to
  67. * those in the toolbar.
  68. */
  69. class OverflowMenu extends PureComponent<Props, State> {
  70. /**
  71. * Initializes a new {@code OverflowMenu} instance.
  72. *
  73. * @inheritdoc
  74. */
  75. constructor(props: Props) {
  76. super(props);
  77. this.state = {
  78. scrolledToTop: true,
  79. showMore: false
  80. };
  81. // Bind event handlers so they are only bound once per instance.
  82. this._onCancel = this._onCancel.bind(this);
  83. this._onSwipe = this._onSwipe.bind(this);
  84. this._onToggleMenu = this._onToggleMenu.bind(this);
  85. }
  86. /**
  87. * Implements React's {@link Component#render()}.
  88. *
  89. * @inheritdoc
  90. * @returns {ReactElement}
  91. */
  92. render() {
  93. const { _bottomSheetStyles } = this.props;
  94. const { showMore } = this.state;
  95. const buttonProps = {
  96. afterClick: this._onCancel,
  97. showLabel: true,
  98. styles: _bottomSheetStyles.buttons
  99. };
  100. const moreOptionsButtonProps = {
  101. ...buttonProps,
  102. afterClick: this._onToggleMenu,
  103. visible: !showMore
  104. };
  105. return (
  106. <BottomSheet
  107. onCancel = { this._onCancel }
  108. onSwipe = { this._onSwipe }>
  109. <AudioRouteButton { ...buttonProps } />
  110. <ToggleCameraButton { ...buttonProps } />
  111. <AudioOnlyButton { ...buttonProps } />
  112. <MoreOptionsButton { ...moreOptionsButtonProps } />
  113. <Collapsible collapsed = { !showMore }>
  114. <RoomLockButton { ...buttonProps } />
  115. <ClosedCaptionButton { ...buttonProps } />
  116. {
  117. this.props._recordingEnabled
  118. && <RecordButton { ...buttonProps } />
  119. }
  120. <LiveStreamButton { ...buttonProps } />
  121. <TileViewButton { ...buttonProps } />
  122. <InviteButton { ...buttonProps } />
  123. {
  124. this.props._chatEnabled
  125. && <InfoDialogButton { ...buttonProps } />
  126. }
  127. <RaiseHandButton { ...buttonProps } />
  128. <SharedDocumentButton { ...buttonProps } />
  129. <HelpButton { ...buttonProps } />
  130. </Collapsible>
  131. </BottomSheet>
  132. );
  133. }
  134. _onCancel: () => boolean;
  135. /**
  136. * Hides this {@code OverflowMenu}.
  137. *
  138. * @private
  139. * @returns {boolean}
  140. */
  141. _onCancel() {
  142. if (this.props._isOpen) {
  143. this.props.dispatch(hideDialog(OverflowMenu_));
  144. return true;
  145. }
  146. return false;
  147. }
  148. _onSwipe: string => void;
  149. /**
  150. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  151. * if the swipe gesture is handled by the menu, false otherwise.
  152. *
  153. * @param {string} direction - Direction of 'up' or 'down'.
  154. * @returns {boolean}
  155. */
  156. _onSwipe(direction) {
  157. const { showMore } = this.state;
  158. switch (direction) {
  159. case 'up':
  160. !showMore && this.setState({
  161. showMore: true
  162. });
  163. return !showMore;
  164. case 'down':
  165. showMore && this.setState({
  166. showMore: false
  167. });
  168. return showMore;
  169. }
  170. }
  171. _onToggleMenu: () => void;
  172. /**
  173. * Callback to be invoked when the expand menu button is pressed.
  174. *
  175. * @returns {void}
  176. */
  177. _onToggleMenu() {
  178. this.setState({
  179. showMore: !this.state.showMore
  180. });
  181. }
  182. }
  183. /**
  184. * Function that maps parts of Redux state tree into component props.
  185. *
  186. * @param {Object} state - Redux state.
  187. * @private
  188. * @returns {Props}
  189. */
  190. function _mapStateToProps(state) {
  191. return {
  192. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  193. _chatEnabled: getFeatureFlag(state, CHAT_ENABLED, true),
  194. _isOpen: isDialogOpen(state, OverflowMenu_),
  195. _recordingEnabled: Platform.OS !== 'ios' || getFeatureFlag(state, IOS_RECORDING_ENABLED)
  196. };
  197. }
  198. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  199. export default OverflowMenu_;