2018-02-19 22:52:21 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-02-16 23:02:40 +00:00
|
|
|
import React, { Component } from 'react';
|
2016-10-05 14:36:59 +00:00
|
|
|
import { View } from 'react-native';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2018-05-10 23:01:55 +00:00
|
|
|
import { Container } from '../../../base/react';
|
2019-01-22 10:35:28 +00:00
|
|
|
import { ColorSchemeRegistry } from '../../../base/color-scheme';
|
|
|
|
import { StyleType } from '../../../base/styles';
|
2019-01-13 19:34:38 +00:00
|
|
|
import { ChatButton } from '../../../chat';
|
2018-04-18 14:34:40 +00:00
|
|
|
|
2019-01-30 17:19:40 +00:00
|
|
|
import { isToolboxVisible } from '../../functions';
|
2019-01-22 10:35:28 +00:00
|
|
|
import { HANGUP_BUTTON_SIZE } from '../../constants';
|
2019-01-30 17:19:40 +00:00
|
|
|
|
2018-05-10 23:01:55 +00:00
|
|
|
import AudioMuteButton from '../AudioMuteButton';
|
|
|
|
import HangupButton from '../HangupButton';
|
2019-01-30 17:19:40 +00:00
|
|
|
|
2018-05-15 11:18:42 +00:00
|
|
|
import OverflowMenuButton from './OverflowMenuButton';
|
2019-01-22 10:35:28 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import VideoMuteButton from '../VideoMuteButton';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-04-18 14:34:40 +00:00
|
|
|
/**
|
2018-05-18 19:35:58 +00:00
|
|
|
* The number of buttons other than {@link HangupButton} to render in
|
|
|
|
* {@link Toolbox}.
|
2018-05-16 21:49:03 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type number
|
2018-04-18 14:34:40 +00:00
|
|
|
*/
|
2018-05-16 21:49:03 +00:00
|
|
|
const _BUTTON_COUNT = 4;
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-05-15 11:18:42 +00:00
|
|
|
* Factor relating the hangup button and other toolbar buttons.
|
2018-05-16 21:49:03 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type number
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-05-18 11:50:34 +00:00
|
|
|
const _BUTTON_SIZE_FACTOR = 0.85;
|
2017-07-03 07:06:33 +00:00
|
|
|
|
2018-04-18 14:34:40 +00:00
|
|
|
/**
|
|
|
|
* The type of {@link Toolbox}'s React {@code Component} props.
|
|
|
|
*/
|
|
|
|
type Props = {
|
2018-02-06 10:41:23 +00:00
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the feature.
|
|
|
|
*/
|
|
|
|
_styles: StyleType,
|
|
|
|
|
2018-02-19 22:52:21 +00:00
|
|
|
/**
|
2018-05-15 11:18:42 +00:00
|
|
|
* The indicator which determines whether the toolbox is visible.
|
2018-02-19 22:52:21 +00:00
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
_visible: boolean,
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-02-19 22:52:21 +00:00
|
|
|
/**
|
2018-05-15 11:18:42 +00:00
|
|
|
* The redux {@code dispatch} function.
|
2018-02-19 22:52:21 +00:00
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
dispatch: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of {@link Toolbox}'s React {@code Component} state.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The detected width for this component.
|
|
|
|
*/
|
|
|
|
width: number
|
2018-02-19 22:52:21 +00:00
|
|
|
};
|
2017-08-04 21:06:42 +00:00
|
|
|
|
2018-02-19 22:52:21 +00:00
|
|
|
/**
|
|
|
|
* Implements the conference toolbox on React Native.
|
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
class Toolbox extends Component<Props, State> {
|
|
|
|
state = {
|
|
|
|
width: 0
|
|
|
|
};
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-05-15 11:18:42 +00:00
|
|
|
* Initializes a new {@code Toolbox} instance.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
2018-02-06 10:41:23 +00:00
|
|
|
|
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._onLayout = this._onLayout.bind(this);
|
2016-12-11 23:39:31 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 18:29:34 +00:00
|
|
|
/**
|
2018-05-15 11:18:42 +00:00
|
|
|
* Implements React's {@link Component#render()}.
|
2017-10-19 18:29:34 +00:00
|
|
|
*
|
2018-05-15 11:18:42 +00:00
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
2017-10-19 18:29:34 +00:00
|
|
|
*/
|
2018-05-15 11:18:42 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Container
|
|
|
|
onLayout = { this._onLayout }
|
2018-08-29 19:04:05 +00:00
|
|
|
style = { styles.toolbox }
|
2018-05-18 19:35:58 +00:00
|
|
|
visible = { this.props._visible }>
|
2018-05-18 11:42:16 +00:00
|
|
|
{ this._renderToolbar() }
|
2018-05-15 11:18:42 +00:00
|
|
|
</Container>
|
|
|
|
);
|
2017-10-19 18:29:34 +00:00
|
|
|
}
|
2018-05-16 21:49:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates how large our toolbar buttons can be, given the available
|
|
|
|
* width. In the future we might want to have a size threshold, and once
|
|
|
|
* it's passed a completely different style could be used, akin to the web.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
_calculateButtonSize() {
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _styles } = this.props;
|
2018-05-16 21:49:03 +00:00
|
|
|
const { width } = this.state;
|
|
|
|
|
2018-05-18 19:35:58 +00:00
|
|
|
if (width <= 0) {
|
|
|
|
// We don't know how much space is allocated to the toolbar yet.
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
const hangupButtonSize = HANGUP_BUTTON_SIZE;
|
|
|
|
const { style } = _styles.buttonStyles;
|
2018-05-16 21:49:03 +00:00
|
|
|
let buttonSize
|
|
|
|
= (width
|
2018-05-18 19:35:58 +00:00
|
|
|
|
|
|
|
// Account for HangupButton without its margin which is not
|
|
|
|
// included in _BUTTON_COUNT:
|
2018-05-16 21:49:03 +00:00
|
|
|
- hangupButtonSize
|
2018-05-18 19:35:58 +00:00
|
|
|
|
|
|
|
// Account for the horizontal margins of all buttons:
|
|
|
|
- ((_BUTTON_COUNT + 1) * style.marginHorizontal * 2))
|
2018-05-16 21:49:03 +00:00
|
|
|
/ _BUTTON_COUNT;
|
|
|
|
|
2018-05-18 19:35:58 +00:00
|
|
|
// Well, don't return a non-positive button size.
|
|
|
|
if (buttonSize <= 0) {
|
|
|
|
buttonSize = style.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The button should be at most _BUTTON_SIZE_FACTOR of the hangup
|
|
|
|
// button's size.
|
|
|
|
buttonSize
|
|
|
|
= Math.min(buttonSize, hangupButtonSize * _BUTTON_SIZE_FACTOR);
|
2018-05-16 21:49:03 +00:00
|
|
|
|
2018-05-18 19:35:58 +00:00
|
|
|
// Make sure it's an even number.
|
|
|
|
return 2 * Math.round(buttonSize / 2);
|
2018-05-16 21:49:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
/**
|
|
|
|
* Constructs the toggled style of the chat button. This cannot be done by
|
|
|
|
* simple style inheritance due to the size calculation done in this
|
|
|
|
* component.
|
|
|
|
*
|
|
|
|
* @param {Object} baseStyle - The base style that was originally
|
|
|
|
* calculated.
|
|
|
|
* @returns {Object | Array}
|
|
|
|
*/
|
|
|
|
_getChatButtonToggledStyle(baseStyle) {
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _styles } = this.props;
|
|
|
|
|
2019-01-13 19:34:38 +00:00
|
|
|
if (Array.isArray(baseStyle.style)) {
|
|
|
|
return {
|
|
|
|
...baseStyle,
|
|
|
|
style: [
|
|
|
|
...baseStyle.style,
|
2019-01-22 10:35:28 +00:00
|
|
|
_styles.chatButtonOverride.toggled
|
2019-01-13 19:34:38 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...baseStyle,
|
|
|
|
style: [
|
|
|
|
baseStyle.style,
|
2019-01-22 10:35:28 +00:00
|
|
|
_styles.chatButtonOverride.toggled
|
2019-01-13 19:34:38 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-16 21:49:03 +00:00
|
|
|
_onLayout: (Object) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the "on layout" View's event and stores the width as state.
|
|
|
|
*
|
|
|
|
* @param {Object} event - The "on layout" event object/structure passed
|
|
|
|
* by react-native.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onLayout({ nativeEvent: { layout: { width } } }) {
|
|
|
|
this.setState({ width });
|
|
|
|
}
|
2018-05-18 19:35:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the toolbar. In order to avoid a weird visual effect in which the
|
|
|
|
* toolbar is (visually) rendered and then visibly changes its size, it is
|
|
|
|
* rendered only after we've figured out the width available to the toolbar.
|
|
|
|
*
|
|
|
|
* @returns {React$Node}
|
|
|
|
*/
|
|
|
|
_renderToolbar() {
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _styles } = this.props;
|
2018-05-18 19:35:58 +00:00
|
|
|
const buttonSize = this._calculateButtonSize();
|
2019-01-22 10:35:28 +00:00
|
|
|
let { buttonStyles, toggledButtonStyles } = _styles;
|
2018-05-18 19:35:58 +00:00
|
|
|
|
|
|
|
if (buttonSize > 0) {
|
|
|
|
const extraButtonStyle = {
|
|
|
|
borderRadius: buttonSize / 2,
|
|
|
|
height: buttonSize,
|
|
|
|
width: buttonSize
|
|
|
|
};
|
|
|
|
|
|
|
|
// XXX The following width equality checks attempt to minimize
|
|
|
|
// unnecessary objects and possibly re-renders.
|
|
|
|
if (buttonStyles.style.width !== extraButtonStyle.width) {
|
|
|
|
buttonStyles = {
|
|
|
|
...buttonStyles,
|
|
|
|
style: [ buttonStyles.style, extraButtonStyle ]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (toggledButtonStyles.style.width !== extraButtonStyle.width) {
|
|
|
|
toggledButtonStyles = {
|
|
|
|
...toggledButtonStyles,
|
|
|
|
style: [ toggledButtonStyles.style, extraButtonStyle ]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX In order to avoid a weird visual effect in which the toolbar
|
|
|
|
// is (visually) rendered and then visibly changes its size, it is
|
|
|
|
// rendered only after we've figured out the width available to the
|
|
|
|
// toolbar.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
style = { styles.toolbar }>
|
2019-01-13 19:34:38 +00:00
|
|
|
<ChatButton
|
|
|
|
styles = { buttonStyles }
|
|
|
|
toggledStyles = {
|
|
|
|
this._getChatButtonToggledStyle(toggledButtonStyles)
|
|
|
|
} />
|
2018-05-18 19:35:58 +00:00
|
|
|
<AudioMuteButton
|
|
|
|
styles = { buttonStyles }
|
|
|
|
toggledStyles = { toggledButtonStyles } />
|
2019-01-22 10:35:28 +00:00
|
|
|
<HangupButton
|
|
|
|
styles = { _styles.hangupButtonStyles } />
|
2018-05-18 19:35:58 +00:00
|
|
|
<VideoMuteButton
|
|
|
|
styles = { buttonStyles }
|
|
|
|
toggledStyles = { toggledButtonStyles } />
|
|
|
|
<OverflowMenuButton
|
|
|
|
styles = { buttonStyles }
|
|
|
|
toggledStyles = { toggledButtonStyles } />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 23:02:40 +00:00
|
|
|
/**
|
2018-04-18 14:34:40 +00:00
|
|
|
* Maps parts of the redux state to {@link Toolbox} (React {@code Component})
|
2018-02-19 22:52:21 +00:00
|
|
|
* props.
|
2017-02-16 23:02:40 +00:00
|
|
|
*
|
2018-04-18 14:34:40 +00:00
|
|
|
* @param {Object} state - The redux state of which parts are to be mapped to
|
|
|
|
* {@code Toolbox} props.
|
2018-05-11 02:10:26 +00:00
|
|
|
* @private
|
2017-02-16 23:02:40 +00:00
|
|
|
* @returns {{
|
2019-01-22 10:35:28 +00:00
|
|
|
* _styles: StyleType,
|
2018-04-18 14:34:40 +00:00
|
|
|
* _visible: boolean
|
2017-02-16 23:02:40 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2018-04-18 14:34:40 +00:00
|
|
|
function _mapStateToProps(state: Object): Object {
|
2017-02-16 23:02:40 +00:00
|
|
|
return {
|
2019-01-22 10:35:28 +00:00
|
|
|
_styles: ColorSchemeRegistry.get(state, 'Toolbox'),
|
2019-01-30 17:19:40 +00:00
|
|
|
_visible: isToolboxVisible(state)
|
2017-02-16 23:02:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
// $FlowExpectedError
|
2018-08-29 19:04:05 +00:00
|
|
|
export default connect(_mapStateToProps)(Toolbox);
|