2018-05-15 11:18:42 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-11-25 12:01:54 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-04-29 07:35:18 +00:00
|
|
|
import { TouchableOpacity, View } from 'react-native';
|
2019-11-25 12:01:54 +00:00
|
|
|
import Collapsible from 'react-native-collapsible';
|
2018-05-15 11:18:42 +00:00
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
import { ColorSchemeRegistry } from '../../../base/color-scheme';
|
2019-07-11 11:32:17 +00:00
|
|
|
import { BottomSheet, hideDialog, isDialogOpen } from '../../../base/dialog';
|
2020-03-24 12:37:24 +00:00
|
|
|
import { IconDragHandle } from '../../../base/icons';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2019-01-22 10:35:28 +00:00
|
|
|
import { StyleType } from '../../../base/styles';
|
2019-10-04 15:10:19 +00:00
|
|
|
import { SharedDocumentButton } from '../../../etherpad';
|
2020-03-24 11:18:25 +00:00
|
|
|
import { InviteButton } from '../../../invite';
|
2018-05-15 11:18:42 +00:00
|
|
|
import { AudioRouteButton } from '../../../mobile/audio-mode';
|
2018-07-05 11:17:45 +00:00
|
|
|
import { LiveStreamButton, RecordButton } from '../../../recording';
|
2018-05-15 11:18:42 +00:00
|
|
|
import { RoomLockButton } from '../../../room-lock';
|
2018-08-24 18:12:12 +00:00
|
|
|
import { ClosedCaptionButton } from '../../../subtitles';
|
2018-09-13 15:20:22 +00:00
|
|
|
import { TileViewButton } from '../../../video-layout';
|
2019-10-11 18:09:50 +00:00
|
|
|
import HelpButton from '../HelpButton';
|
2019-11-25 12:01:54 +00:00
|
|
|
|
|
|
|
import AudioOnlyButton from './AudioOnlyButton';
|
2020-02-20 14:52:41 +00:00
|
|
|
import MoreOptionsButton from './MoreOptionsButton';
|
2019-03-27 13:47:19 +00:00
|
|
|
import RaiseHandButton from './RaiseHandButton';
|
2018-05-16 21:49:03 +00:00
|
|
|
import ToggleCameraButton from './ToggleCameraButton';
|
2020-03-23 08:37:35 +00:00
|
|
|
import styles from './styles';
|
2018-05-15 11:18:42 +00:00
|
|
|
|
2018-05-16 21:49:03 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link OverflowMenu}.
|
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
type Props = {
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the dialog feature.
|
|
|
|
*/
|
|
|
|
_bottomSheetStyles: StyleType,
|
|
|
|
|
2019-07-11 11:32:17 +00:00
|
|
|
/**
|
|
|
|
* True if the overflow menu is currently visible, false otherwise.
|
|
|
|
*/
|
|
|
|
_isOpen: boolean,
|
|
|
|
|
2019-05-24 15:11:54 +00:00
|
|
|
/**
|
|
|
|
* Whether the recoding button should be enabled or not.
|
|
|
|
*/
|
|
|
|
_recordingEnabled: boolean,
|
|
|
|
|
2018-05-15 11:18:42 +00:00
|
|
|
/**
|
|
|
|
* Used for hiding the dialog when the selection was completed.
|
|
|
|
*/
|
2019-01-22 10:35:28 +00:00
|
|
|
dispatch: Function
|
2018-05-15 11:18:42 +00:00
|
|
|
};
|
|
|
|
|
2019-11-25 12:01:54 +00:00
|
|
|
type State = {
|
|
|
|
|
2019-12-12 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* True if the bottom scheet is scrolled to the top.
|
|
|
|
*/
|
|
|
|
scrolledToTop: boolean,
|
|
|
|
|
2019-11-25 12:01:54 +00:00
|
|
|
/**
|
|
|
|
* True if the 'more' button set needas to be rendered.
|
|
|
|
*/
|
|
|
|
showMore: boolean
|
|
|
|
}
|
|
|
|
|
2018-05-15 11:18:42 +00:00
|
|
|
/**
|
2018-05-16 21:49:03 +00:00
|
|
|
* The exported React {@code Component}. We need it to execute
|
|
|
|
* {@link hideDialog}.
|
|
|
|
*
|
|
|
|
* XXX It does not break our coding style rule to not utilize globals for state,
|
|
|
|
* because it is merely another name for {@code export}'s {@code default}.
|
2018-05-15 11:18:42 +00:00
|
|
|
*/
|
2018-05-16 21:49:03 +00:00
|
|
|
let OverflowMenu_; // eslint-disable-line prefer-const
|
2018-05-15 11:18:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@code Component} with some extra actions in addition to
|
|
|
|
* those in the toolbar.
|
|
|
|
*/
|
2019-11-25 12:01:54 +00:00
|
|
|
class OverflowMenu extends PureComponent<Props, State> {
|
2018-05-15 11:18:42 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code OverflowMenu} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
2019-11-25 12:01:54 +00:00
|
|
|
this.state = {
|
2019-12-12 13:52:41 +00:00
|
|
|
scrolledToTop: true,
|
2019-11-25 12:01:54 +00:00
|
|
|
showMore: false
|
|
|
|
};
|
|
|
|
|
2018-05-16 21:49:03 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2018-05-15 11:18:42 +00:00
|
|
|
this._onCancel = this._onCancel.bind(this);
|
2019-11-25 12:01:54 +00:00
|
|
|
this._onSwipe = this._onSwipe.bind(this);
|
|
|
|
this._onToggleMenu = this._onToggleMenu.bind(this);
|
2020-03-23 08:37:35 +00:00
|
|
|
this._renderMenuExpandToggle = this._renderMenuExpandToggle.bind(this);
|
2018-05-15 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2019-11-25 12:01:54 +00:00
|
|
|
const { _bottomSheetStyles } = this.props;
|
|
|
|
const { showMore } = this.state;
|
|
|
|
|
2018-05-22 09:33:03 +00:00
|
|
|
const buttonProps = {
|
|
|
|
afterClick: this._onCancel,
|
|
|
|
showLabel: true,
|
2019-11-25 12:01:54 +00:00
|
|
|
styles: _bottomSheetStyles.buttons
|
2018-05-22 09:33:03 +00:00
|
|
|
};
|
|
|
|
|
2020-02-20 14:52:41 +00:00
|
|
|
const moreOptionsButtonProps = {
|
|
|
|
...buttonProps,
|
|
|
|
afterClick: this._onToggleMenu,
|
|
|
|
visible: !showMore
|
|
|
|
};
|
|
|
|
|
2018-05-15 11:18:42 +00:00
|
|
|
return (
|
2019-11-25 12:01:54 +00:00
|
|
|
<BottomSheet
|
|
|
|
onCancel = { this._onCancel }
|
2020-03-23 08:37:35 +00:00
|
|
|
onSwipe = { this._onSwipe }
|
|
|
|
renderHeader = { this._renderMenuExpandToggle }>
|
2018-05-22 09:33:03 +00:00
|
|
|
<AudioRouteButton { ...buttonProps } />
|
2020-03-24 11:24:36 +00:00
|
|
|
<InviteButton { ...buttonProps } />
|
2018-05-22 09:33:03 +00:00
|
|
|
<AudioOnlyButton { ...buttonProps } />
|
2020-03-24 11:24:36 +00:00
|
|
|
<RaiseHandButton { ...buttonProps } />
|
2020-02-20 14:52:41 +00:00
|
|
|
<MoreOptionsButton { ...moreOptionsButtonProps } />
|
2019-11-25 12:01:54 +00:00
|
|
|
<Collapsible collapsed = { !showMore }>
|
2020-03-24 11:24:36 +00:00
|
|
|
<ToggleCameraButton { ...buttonProps } />
|
|
|
|
<TileViewButton { ...buttonProps } />
|
2020-04-29 07:35:18 +00:00
|
|
|
<RecordButton { ...buttonProps } />
|
2019-11-25 12:01:54 +00:00
|
|
|
<LiveStreamButton { ...buttonProps } />
|
2020-03-24 11:24:36 +00:00
|
|
|
<RoomLockButton { ...buttonProps } />
|
|
|
|
<ClosedCaptionButton { ...buttonProps } />
|
2019-11-25 12:01:54 +00:00
|
|
|
<SharedDocumentButton { ...buttonProps } />
|
|
|
|
<HelpButton { ...buttonProps } />
|
|
|
|
</Collapsible>
|
2018-05-15 11:18:42 +00:00
|
|
|
</BottomSheet>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-23 08:37:35 +00:00
|
|
|
_renderMenuExpandToggle: () => React$Element<any>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to render the menu toggle in the bottom sheet header area.
|
|
|
|
*
|
|
|
|
* @returns {React$Element}
|
|
|
|
*/
|
|
|
|
_renderMenuExpandToggle() {
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style = { [
|
|
|
|
this.props._bottomSheetStyles.sheet,
|
|
|
|
styles.expandMenuContainer
|
|
|
|
] }>
|
|
|
|
<TouchableOpacity onPress = { this._onToggleMenu }>
|
|
|
|
{ /* $FlowFixMeProps */ }
|
|
|
|
<IconDragHandle style = { this.props._bottomSheetStyles.expandIcon } />
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-11 11:32:17 +00:00
|
|
|
_onCancel: () => boolean;
|
2018-05-15 11:18:42 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-16 21:49:03 +00:00
|
|
|
* Hides this {@code OverflowMenu}.
|
2018-05-15 11:18:42 +00:00
|
|
|
*
|
|
|
|
* @private
|
2019-07-11 11:32:17 +00:00
|
|
|
* @returns {boolean}
|
2018-05-15 11:18:42 +00:00
|
|
|
*/
|
|
|
|
_onCancel() {
|
2019-07-11 11:32:17 +00:00
|
|
|
if (this.props._isOpen) {
|
|
|
|
this.props.dispatch(hideDialog(OverflowMenu_));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-05-15 11:18:42 +00:00
|
|
|
}
|
2019-11-25 12:01:54 +00:00
|
|
|
|
2019-12-12 13:52:41 +00:00
|
|
|
_onSwipe: string => void;
|
2019-11-25 12:01:54 +00:00
|
|
|
|
|
|
|
/**
|
2019-12-12 13:52:41 +00:00
|
|
|
* Callback to be invoked when swipe gesture is detected on the menu. Returns true
|
|
|
|
* if the swipe gesture is handled by the menu, false otherwise.
|
2019-11-25 12:01:54 +00:00
|
|
|
*
|
2019-12-12 13:52:41 +00:00
|
|
|
* @param {string} direction - Direction of 'up' or 'down'.
|
|
|
|
* @returns {boolean}
|
2019-11-25 12:01:54 +00:00
|
|
|
*/
|
2019-12-12 13:52:41 +00:00
|
|
|
_onSwipe(direction) {
|
2019-11-25 12:01:54 +00:00
|
|
|
const { showMore } = this.state;
|
|
|
|
|
2019-12-12 13:52:41 +00:00
|
|
|
switch (direction) {
|
|
|
|
case 'up':
|
2019-11-25 12:01:54 +00:00
|
|
|
!showMore && this.setState({
|
|
|
|
showMore: true
|
|
|
|
});
|
2019-12-12 13:52:41 +00:00
|
|
|
|
|
|
|
return !showMore;
|
|
|
|
case 'down':
|
|
|
|
showMore && this.setState({
|
|
|
|
showMore: false
|
|
|
|
});
|
|
|
|
|
|
|
|
return showMore;
|
2019-11-25 12:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onToggleMenu: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to be invoked when the expand menu button is pressed.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToggleMenu() {
|
|
|
|
this.setState({
|
|
|
|
showMore: !this.state.showMore
|
|
|
|
});
|
|
|
|
}
|
2018-05-15 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @private
|
2019-07-11 11:32:17 +00:00
|
|
|
* @returns {Props}
|
2019-01-22 10:35:28 +00:00
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
2020-02-20 14:52:41 +00:00
|
|
|
_bottomSheetStyles: ColorSchemeRegistry.get(state, 'BottomSheet'),
|
2020-04-29 07:35:18 +00:00
|
|
|
_isOpen: isDialogOpen(state, OverflowMenu_)
|
2019-01-22 10:35:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
OverflowMenu_ = connect(_mapStateToProps)(OverflowMenu);
|
2018-05-15 11:18:42 +00:00
|
|
|
|
|
|
|
export default OverflowMenu_;
|