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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { 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 { connect } from '../../../base/redux';
  9. import { StyleType } from '../../../base/styles';
  10. import { SharedDocumentButton } from '../../../etherpad';
  11. import { InviteButton } from '../../../invite';
  12. import { LobbyModeButton } from '../../../lobby/components/native';
  13. import { AudioRouteButton } from '../../../mobile/audio-mode';
  14. import { LiveStreamButton, RecordButton } from '../../../recording';
  15. import { RoomLockButton } from '../../../room-lock';
  16. import { SharedVideoButton } from '../../../shared-video/components';
  17. import { ClosedCaptionButton } from '../../../subtitles';
  18. import { TileViewButton } from '../../../video-layout';
  19. import HelpButton from '../HelpButton';
  20. import MuteEveryoneButton from '../MuteEveryoneButton';
  21. import AudioOnlyButton from './AudioOnlyButton';
  22. import MoreOptionsButton from './MoreOptionsButton';
  23. import RaiseHandButton from './RaiseHandButton';
  24. import ScreenSharingButton from './ScreenSharingButton.js';
  25. import ToggleCameraButton from './ToggleCameraButton';
  26. import styles from './styles';
  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. * 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. const moreOptionsButtonProps = {
  103. ...buttonProps,
  104. afterClick: this._onToggleMenu,
  105. visible: !showMore
  106. };
  107. return (
  108. <BottomSheet
  109. onCancel = { this._onCancel }
  110. onSwipe = { this._onSwipe }
  111. renderHeader = { this._renderMenuExpandToggle }>
  112. <AudioRouteButton { ...buttonProps } />
  113. <InviteButton { ...buttonProps } />
  114. <AudioOnlyButton { ...buttonProps } />
  115. <RaiseHandButton { ...buttonProps } />
  116. <LobbyModeButton { ...buttonProps } />
  117. <ScreenSharingButton { ...buttonProps } />
  118. <MoreOptionsButton { ...moreOptionsButtonProps } />
  119. <Collapsible collapsed = { !showMore }>
  120. <ToggleCameraButton { ...buttonProps } />
  121. <TileViewButton { ...buttonProps } />
  122. <RecordButton { ...buttonProps } />
  123. <LiveStreamButton { ...buttonProps } />
  124. <SharedVideoButton { ...buttonProps } />
  125. <RoomLockButton { ...buttonProps } />
  126. <ClosedCaptionButton { ...buttonProps } />
  127. <SharedDocumentButton { ...buttonProps } />
  128. <MuteEveryoneButton { ...buttonProps } />
  129. <HelpButton { ...buttonProps } />
  130. </Collapsible>
  131. </BottomSheet>
  132. );
  133. }
  134. _renderMenuExpandToggle: () => React$Element<any>;
  135. /**
  136. * Function to render the menu toggle in the bottom sheet header area.
  137. *
  138. * @returns {React$Element}
  139. */
  140. _renderMenuExpandToggle() {
  141. return (
  142. <View
  143. style = { [
  144. this.props._bottomSheetStyles.sheet,
  145. styles.expandMenuContainer
  146. ] }>
  147. <TouchableOpacity onPress = { this._onToggleMenu }>
  148. { /* $FlowFixMe */ }
  149. <IconDragHandle
  150. fill = { this.props._bottomSheetStyles.buttons.iconStyle.color } />
  151. </TouchableOpacity>
  152. </View>
  153. );
  154. }
  155. _onCancel: () => boolean;
  156. /**
  157. * Hides this {@code OverflowMenu}.
  158. *
  159. * @private
  160. * @returns {boolean}
  161. */
  162. _onCancel() {
  163. if (this.props._isOpen) {
  164. this.props.dispatch(hideDialog(OverflowMenu_));
  165. return true;
  166. }
  167. return false;
  168. }
  169. _onSwipe: string => void;
  170. /**
  171. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  172. * if the swipe gesture is handled by the menu, false otherwise.
  173. *
  174. * @param {string} direction - Direction of 'up' or 'down'.
  175. * @returns {boolean}
  176. */
  177. _onSwipe(direction) {
  178. const { showMore } = this.state;
  179. switch (direction) {
  180. case 'up':
  181. !showMore && this.setState({
  182. showMore: true
  183. });
  184. return !showMore;
  185. case 'down':
  186. showMore && this.setState({
  187. showMore: false
  188. });
  189. return showMore;
  190. }
  191. }
  192. _onToggleMenu: () => void;
  193. /**
  194. * Callback to be invoked when the expand menu button is pressed.
  195. *
  196. * @returns {void}
  197. */
  198. _onToggleMenu() {
  199. this.setState({
  200. showMore: !this.state.showMore
  201. });
  202. }
  203. }
  204. /**
  205. * Function that maps parts of Redux state tree into component props.
  206. *
  207. * @param {Object} state - Redux state.
  208. * @private
  209. * @returns {Props}
  210. */
  211. function _mapStateToProps(state) {
  212. return {
  213. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  214. _isOpen: isDialogOpen(state, OverflowMenu_)
  215. };
  216. }
  217. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  218. export default OverflowMenu_;