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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 HelpButton from '../HelpButton';
  19. import AudioOnlyButton from './AudioOnlyButton';
  20. import MoreOptionsButton from './MoreOptionsButton';
  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. * True if the overflow menu is currently visible, false otherwise.
  34. */
  35. _isOpen: boolean,
  36. /**
  37. * Whether the recoding button should be enabled or not.
  38. */
  39. _recordingEnabled: boolean,
  40. /**
  41. * Used for hiding the dialog when the selection was completed.
  42. */
  43. dispatch: Function
  44. };
  45. type State = {
  46. /**
  47. * True if the bottom scheet is scrolled to the top.
  48. */
  49. scrolledToTop: boolean,
  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. scrolledToTop: true,
  77. showMore: false
  78. };
  79. // Bind event handlers so they are only bound once per instance.
  80. this._onCancel = this._onCancel.bind(this);
  81. this._onSwipe = this._onSwipe.bind(this);
  82. this._onToggleMenu = this._onToggleMenu.bind(this);
  83. this._renderMenuExpandToggle = this._renderMenuExpandToggle.bind(this);
  84. }
  85. /**
  86. * Implements React's {@link Component#render()}.
  87. *
  88. * @inheritdoc
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. const { _bottomSheetStyles } = this.props;
  93. const { showMore } = this.state;
  94. const buttonProps = {
  95. afterClick: this._onCancel,
  96. showLabel: true,
  97. styles: _bottomSheetStyles.buttons
  98. };
  99. const moreOptionsButtonProps = {
  100. ...buttonProps,
  101. afterClick: this._onToggleMenu,
  102. visible: !showMore
  103. };
  104. return (
  105. <BottomSheet
  106. onCancel = { this._onCancel }
  107. onSwipe = { this._onSwipe }
  108. renderHeader = { this._renderMenuExpandToggle }>
  109. <AudioRouteButton { ...buttonProps } />
  110. <InviteButton { ...buttonProps } />
  111. <AudioOnlyButton { ...buttonProps } />
  112. <RaiseHandButton { ...buttonProps } />
  113. <LobbyModeButton { ...buttonProps } />
  114. <MoreOptionsButton { ...moreOptionsButtonProps } />
  115. <Collapsible collapsed = { !showMore }>
  116. <ToggleCameraButton { ...buttonProps } />
  117. <TileViewButton { ...buttonProps } />
  118. <RecordButton { ...buttonProps } />
  119. <LiveStreamButton { ...buttonProps } />
  120. <RoomLockButton { ...buttonProps } />
  121. <ClosedCaptionButton { ...buttonProps } />
  122. <SharedDocumentButton { ...buttonProps } />
  123. <HelpButton { ...buttonProps } />
  124. </Collapsible>
  125. </BottomSheet>
  126. );
  127. }
  128. _renderMenuExpandToggle: () => React$Element<any>;
  129. /**
  130. * Function to render the menu toggle in the bottom sheet header area.
  131. *
  132. * @returns {React$Element}
  133. */
  134. _renderMenuExpandToggle() {
  135. return (
  136. <View
  137. style = { [
  138. this.props._bottomSheetStyles.sheet,
  139. styles.expandMenuContainer
  140. ] }>
  141. <TouchableOpacity onPress = { this._onToggleMenu }>
  142. { /* $FlowFixMeProps */ }
  143. <IconDragHandle style = { this.props._bottomSheetStyles.expandIcon } />
  144. </TouchableOpacity>
  145. </View>
  146. );
  147. }
  148. _onCancel: () => boolean;
  149. /**
  150. * Hides this {@code OverflowMenu}.
  151. *
  152. * @private
  153. * @returns {boolean}
  154. */
  155. _onCancel() {
  156. if (this.props._isOpen) {
  157. this.props.dispatch(hideDialog(OverflowMenu_));
  158. return true;
  159. }
  160. return false;
  161. }
  162. _onSwipe: string => void;
  163. /**
  164. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  165. * if the swipe gesture is handled by the menu, false otherwise.
  166. *
  167. * @param {string} direction - Direction of 'up' or 'down'.
  168. * @returns {boolean}
  169. */
  170. _onSwipe(direction) {
  171. const { showMore } = this.state;
  172. switch (direction) {
  173. case 'up':
  174. !showMore && this.setState({
  175. showMore: true
  176. });
  177. return !showMore;
  178. case 'down':
  179. showMore && this.setState({
  180. showMore: false
  181. });
  182. return showMore;
  183. }
  184. }
  185. _onToggleMenu: () => void;
  186. /**
  187. * Callback to be invoked when the expand menu button is pressed.
  188. *
  189. * @returns {void}
  190. */
  191. _onToggleMenu() {
  192. this.setState({
  193. showMore: !this.state.showMore
  194. });
  195. }
  196. }
  197. /**
  198. * Function that maps parts of Redux state tree into component props.
  199. *
  200. * @param {Object} state - Redux state.
  201. * @private
  202. * @returns {Props}
  203. */
  204. function _mapStateToProps(state) {
  205. return {
  206. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  207. _isOpen: isDialogOpen(state, OverflowMenu_)
  208. };
  209. }
  210. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  211. export default OverflowMenu_;