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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 { AudioRouteButton } from '../../../mobile/audio-mode';
  13. import { LiveStreamButton, RecordButton } from '../../../recording';
  14. import { RoomLockButton } from '../../../room-lock';
  15. import { ClosedCaptionButton } from '../../../subtitles';
  16. import { TileViewButton } from '../../../video-layout';
  17. import HelpButton from '../HelpButton';
  18. import AudioOnlyButton from './AudioOnlyButton';
  19. import MoreOptionsButton from './MoreOptionsButton';
  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. * True if the overflow menu is currently visible, false otherwise.
  33. */
  34. _isOpen: boolean,
  35. /**
  36. * Whether the recoding button should be enabled or not.
  37. */
  38. _recordingEnabled: boolean,
  39. /**
  40. * Used for hiding the dialog when the selection was completed.
  41. */
  42. dispatch: Function
  43. };
  44. type State = {
  45. /**
  46. * True if the bottom scheet is scrolled to the top.
  47. */
  48. scrolledToTop: boolean,
  49. /**
  50. * True if the 'more' button set needas to be rendered.
  51. */
  52. showMore: boolean
  53. }
  54. /**
  55. * The exported React {@code Component}. We need it to execute
  56. * {@link hideDialog}.
  57. *
  58. * XXX It does not break our coding style rule to not utilize globals for state,
  59. * because it is merely another name for {@code export}'s {@code default}.
  60. */
  61. let OverflowMenu_; // eslint-disable-line prefer-const
  62. /**
  63. * Implements a React {@code Component} with some extra actions in addition to
  64. * those in the toolbar.
  65. */
  66. class OverflowMenu extends PureComponent<Props, State> {
  67. /**
  68. * Initializes a new {@code OverflowMenu} instance.
  69. *
  70. * @inheritdoc
  71. */
  72. constructor(props: Props) {
  73. super(props);
  74. this.state = {
  75. scrolledToTop: true,
  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. const moreOptionsButtonProps = {
  99. ...buttonProps,
  100. afterClick: this._onToggleMenu,
  101. visible: !showMore
  102. };
  103. return (
  104. <BottomSheet
  105. onCancel = { this._onCancel }
  106. onSwipe = { this._onSwipe }
  107. renderHeader = { this._renderMenuExpandToggle }>
  108. <AudioRouteButton { ...buttonProps } />
  109. <InviteButton { ...buttonProps } />
  110. <AudioOnlyButton { ...buttonProps } />
  111. <RaiseHandButton { ...buttonProps } />
  112. <MoreOptionsButton { ...moreOptionsButtonProps } />
  113. <Collapsible collapsed = { !showMore }>
  114. <ToggleCameraButton { ...buttonProps } />
  115. <TileViewButton { ...buttonProps } />
  116. <RecordButton { ...buttonProps } />
  117. <LiveStreamButton { ...buttonProps } />
  118. <RoomLockButton { ...buttonProps } />
  119. <ClosedCaptionButton { ...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. <View
  135. style = { [
  136. this.props._bottomSheetStyles.sheet,
  137. styles.expandMenuContainer
  138. ] }>
  139. <TouchableOpacity onPress = { this._onToggleMenu }>
  140. { /* $FlowFixMeProps */ }
  141. <IconDragHandle style = { this.props._bottomSheetStyles.expandIcon } />
  142. </TouchableOpacity>
  143. </View>
  144. );
  145. }
  146. _onCancel: () => boolean;
  147. /**
  148. * Hides this {@code OverflowMenu}.
  149. *
  150. * @private
  151. * @returns {boolean}
  152. */
  153. _onCancel() {
  154. if (this.props._isOpen) {
  155. this.props.dispatch(hideDialog(OverflowMenu_));
  156. return true;
  157. }
  158. return false;
  159. }
  160. _onSwipe: string => void;
  161. /**
  162. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  163. * if the swipe gesture is handled by the menu, false otherwise.
  164. *
  165. * @param {string} direction - Direction of 'up' or 'down'.
  166. * @returns {boolean}
  167. */
  168. _onSwipe(direction) {
  169. const { showMore } = this.state;
  170. switch (direction) {
  171. case 'up':
  172. !showMore && this.setState({
  173. showMore: true
  174. });
  175. return !showMore;
  176. case 'down':
  177. showMore && this.setState({
  178. showMore: false
  179. });
  180. return showMore;
  181. }
  182. }
  183. _onToggleMenu: () => void;
  184. /**
  185. * Callback to be invoked when the expand menu button is pressed.
  186. *
  187. * @returns {void}
  188. */
  189. _onToggleMenu() {
  190. this.setState({
  191. showMore: !this.state.showMore
  192. });
  193. }
  194. }
  195. /**
  196. * Function that maps parts of Redux state tree into component props.
  197. *
  198. * @param {Object} state - Redux state.
  199. * @private
  200. * @returns {Props}
  201. */
  202. function _mapStateToProps(state) {
  203. return {
  204. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  205. _isOpen: isDialogOpen(state, OverflowMenu_)
  206. };
  207. }
  208. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  209. export default OverflowMenu_;