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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 { ClosedCaptionButton } from '../../../subtitles';
  17. import { TileViewButton } from '../../../video-layout';
  18. import { VideoShareButton } from '../../../youtube-player/components';
  19. import HelpButton from '../HelpButton';
  20. import AudioOnlyButton from './AudioOnlyButton';
  21. import MoreOptionsButton from './MoreOptionsButton';
  22. import RaiseHandButton from './RaiseHandButton';
  23. import ScreenSharingButton from './ScreenSharingButton.js';
  24. import ToggleCameraButton from './ToggleCameraButton';
  25. import styles from './styles';
  26. /**
  27. * The type of the React {@code Component} props of {@link OverflowMenu}.
  28. */
  29. type Props = {
  30. /**
  31. * The color-schemed stylesheet of the dialog feature.
  32. */
  33. _bottomSheetStyles: StyleType,
  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. this._renderMenuExpandToggle = this._renderMenuExpandToggle.bind(this);
  86. }
  87. /**
  88. * Implements React's {@link Component#render()}.
  89. *
  90. * @inheritdoc
  91. * @returns {ReactElement}
  92. */
  93. render() {
  94. const { _bottomSheetStyles } = this.props;
  95. const { showMore } = this.state;
  96. const buttonProps = {
  97. afterClick: this._onCancel,
  98. showLabel: true,
  99. styles: _bottomSheetStyles.buttons
  100. };
  101. const moreOptionsButtonProps = {
  102. ...buttonProps,
  103. afterClick: this._onToggleMenu,
  104. visible: !showMore
  105. };
  106. return (
  107. <BottomSheet
  108. onCancel = { this._onCancel }
  109. onSwipe = { this._onSwipe }
  110. renderHeader = { this._renderMenuExpandToggle }>
  111. <AudioRouteButton { ...buttonProps } />
  112. <InviteButton { ...buttonProps } />
  113. <AudioOnlyButton { ...buttonProps } />
  114. <RaiseHandButton { ...buttonProps } />
  115. <LobbyModeButton { ...buttonProps } />
  116. <ScreenSharingButton { ...buttonProps } />
  117. <MoreOptionsButton { ...moreOptionsButtonProps } />
  118. <Collapsible collapsed = { !showMore }>
  119. <ToggleCameraButton { ...buttonProps } />
  120. <TileViewButton { ...buttonProps } />
  121. <RecordButton { ...buttonProps } />
  122. <LiveStreamButton { ...buttonProps } />
  123. <VideoShareButton { ...buttonProps } />
  124. <RoomLockButton { ...buttonProps } />
  125. <ClosedCaptionButton { ...buttonProps } />
  126. <SharedDocumentButton { ...buttonProps } />
  127. <HelpButton { ...buttonProps } />
  128. </Collapsible>
  129. </BottomSheet>
  130. );
  131. }
  132. _renderMenuExpandToggle: () => React$Element<any>;
  133. /**
  134. * Function to render the menu toggle in the bottom sheet header area.
  135. *
  136. * @returns {React$Element}
  137. */
  138. _renderMenuExpandToggle() {
  139. return (
  140. <View
  141. style = { [
  142. this.props._bottomSheetStyles.sheet,
  143. styles.expandMenuContainer
  144. ] }>
  145. <TouchableOpacity onPress = { this._onToggleMenu }>
  146. { /* $FlowFixMeProps */ }
  147. <IconDragHandle style = { this.props._bottomSheetStyles.expandIcon } />
  148. </TouchableOpacity>
  149. </View>
  150. );
  151. }
  152. _onCancel: () => boolean;
  153. /**
  154. * Hides this {@code OverflowMenu}.
  155. *
  156. * @private
  157. * @returns {boolean}
  158. */
  159. _onCancel() {
  160. if (this.props._isOpen) {
  161. this.props.dispatch(hideDialog(OverflowMenu_));
  162. return true;
  163. }
  164. return false;
  165. }
  166. _onSwipe: string => void;
  167. /**
  168. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  169. * if the swipe gesture is handled by the menu, false otherwise.
  170. *
  171. * @param {string} direction - Direction of 'up' or 'down'.
  172. * @returns {boolean}
  173. */
  174. _onSwipe(direction) {
  175. const { showMore } = this.state;
  176. switch (direction) {
  177. case 'up':
  178. !showMore && this.setState({
  179. showMore: true
  180. });
  181. return !showMore;
  182. case 'down':
  183. showMore && this.setState({
  184. showMore: false
  185. });
  186. return showMore;
  187. }
  188. }
  189. _onToggleMenu: () => void;
  190. /**
  191. * Callback to be invoked when the expand menu button is pressed.
  192. *
  193. * @returns {void}
  194. */
  195. _onToggleMenu() {
  196. this.setState({
  197. showMore: !this.state.showMore
  198. });
  199. }
  200. }
  201. /**
  202. * Function that maps parts of Redux state tree into component props.
  203. *
  204. * @param {Object} state - Redux state.
  205. * @private
  206. * @returns {Props}
  207. */
  208. function _mapStateToProps(state) {
  209. return {
  210. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  211. _isOpen: isDialogOpen(state, OverflowMenu_)
  212. };
  213. }
  214. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  215. export default OverflowMenu_;