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

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