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

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