您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OverflowMenu.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 { IOS_RECORDING_ENABLED, getFeatureFlag } from '../../../base/flags';
  8. import { IconDragHandle } from '../../../base/icons';
  9. import { connect } from '../../../base/redux';
  10. import { StyleType } from '../../../base/styles';
  11. import { SharedDocumentButton } from '../../../etherpad';
  12. import { 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 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. <MoreOptionsButton { ...moreOptionsButtonProps } />
  114. <Collapsible collapsed = { !showMore }>
  115. <ToggleCameraButton { ...buttonProps } />
  116. <TileViewButton { ...buttonProps } />
  117. {
  118. this.props._recordingEnabled
  119. && <RecordButton { ...buttonProps } />
  120. }
  121. <LiveStreamButton { ...buttonProps } />
  122. <RoomLockButton { ...buttonProps } />
  123. <ClosedCaptionButton { ...buttonProps } />
  124. <SharedDocumentButton { ...buttonProps } />
  125. <HelpButton { ...buttonProps } />
  126. </Collapsible>
  127. </BottomSheet>
  128. );
  129. }
  130. _renderMenuExpandToggle: () => React$Element<any>;
  131. /**
  132. * Function to render the menu toggle in the bottom sheet header area.
  133. *
  134. * @returns {React$Element}
  135. */
  136. _renderMenuExpandToggle() {
  137. return (
  138. <View
  139. style = { [
  140. this.props._bottomSheetStyles.sheet,
  141. styles.expandMenuContainer
  142. ] }>
  143. <TouchableOpacity onPress = { this._onToggleMenu }>
  144. { /* $FlowFixMeProps */ }
  145. <IconDragHandle style = { this.props._bottomSheetStyles.expandIcon } />
  146. </TouchableOpacity>
  147. </View>
  148. );
  149. }
  150. _onCancel: () => boolean;
  151. /**
  152. * Hides this {@code OverflowMenu}.
  153. *
  154. * @private
  155. * @returns {boolean}
  156. */
  157. _onCancel() {
  158. if (this.props._isOpen) {
  159. this.props.dispatch(hideDialog(OverflowMenu_));
  160. return true;
  161. }
  162. return false;
  163. }
  164. _onSwipe: string => void;
  165. /**
  166. * Callback to be invoked when swipe gesture is detected on the menu. Returns true
  167. * if the swipe gesture is handled by the menu, false otherwise.
  168. *
  169. * @param {string} direction - Direction of 'up' or 'down'.
  170. * @returns {boolean}
  171. */
  172. _onSwipe(direction) {
  173. const { showMore } = this.state;
  174. switch (direction) {
  175. case 'up':
  176. !showMore && this.setState({
  177. showMore: true
  178. });
  179. return !showMore;
  180. case 'down':
  181. showMore && this.setState({
  182. showMore: false
  183. });
  184. return showMore;
  185. }
  186. }
  187. _onToggleMenu: () => void;
  188. /**
  189. * Callback to be invoked when the expand menu button is pressed.
  190. *
  191. * @returns {void}
  192. */
  193. _onToggleMenu() {
  194. this.setState({
  195. showMore: !this.state.showMore
  196. });
  197. }
  198. }
  199. /**
  200. * Function that maps parts of Redux state tree into component props.
  201. *
  202. * @param {Object} state - Redux state.
  203. * @private
  204. * @returns {Props}
  205. */
  206. function _mapStateToProps(state) {
  207. return {
  208. _bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
  209. _isOpen: isDialogOpen(state, OverflowMenu_),
  210. _recordingEnabled: Platform.OS !== 'ios' || getFeatureFlag(state, IOS_RECORDING_ENABLED)
  211. };
  212. }
  213. OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
  214. export default OverflowMenu_;