jiti-meet/react/features/toolbox/components/Toolbox.native.js

204 lines
5.1 KiB
JavaScript
Raw Normal View History

// @flow
2017-02-16 23:02:40 +00:00
import React, { Component } from 'react';
import { View } from 'react-native';
import { connect } from 'react-redux';
import { Container } from '../../base/react';
import {
isNarrowAspectRatio,
makeAspectRatioAware
} from '../../base/responsive-ui';
import { ColorPalette } from '../../base/styles';
import styles from './styles';
2017-02-16 23:02:40 +00:00
import {
AudioMuteButton,
AudioOnlyButton,
AudioRouteButton,
HangupButton,
PictureInPictureButton,
RoomLockButton,
InviteButton,
ToggleCameraButton,
VideoMuteButton
} from './buttons';
/**
* Styles for the hangup button.
*/
const hangupButtonStyles = {
iconStyle: styles.whitePrimaryToolbarButtonIcon,
style: styles.hangup,
underlayColor: ColorPalette.buttonUnderlay
};
/**
* Styles for buttons in the primary toolbar.
*/
const primaryToolbarButtonStyles = {
iconStyle: styles.primaryToolbarButtonIcon,
style: styles.primaryToolbarButton
};
/**
* Styles for buttons in the primary toolbar.
*/
const primaryToolbarToggledButtonStyles = {
iconStyle: styles.whitePrimaryToolbarButtonIcon,
style: styles.whitePrimaryToolbarButton
};
/**
* Styles for buttons in the secondary toolbar.
*/
const secondaryToolbarButtonStyles = {
iconStyle: styles.secondaryToolbarButtonIcon,
style: styles.secondaryToolbarButton,
underlayColor: 'transparent'
};
/**
* The type of {@link Toolbox}'s React {@code Component} props.
*/
type Props = {
/**
* The indicator which determines whether the toolbox is enabled.
*/
_enabled: boolean,
/**
* Flag showing whether toolbar is visible.
*/
_visible: boolean
};
/**
* Implements the conference toolbox on React Native.
*/
class Toolbox extends Component<Props> {
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
if (!this.props._enabled) {
return null;
}
2017-11-07 14:28:08 +00:00
const toolboxStyle
= isNarrowAspectRatio(this)
? styles.toolboxNarrow
: styles.toolboxWide;
return (
<Container
2017-11-07 14:28:08 +00:00
style = { toolboxStyle }
visible = { this.props._visible } >
{ this._renderToolbars() }
</Container>
);
}
/**
* Renders the toolbar which contains the primary buttons such as hangup,
* audio and video mute.
*
* @private
* @returns {ReactElement}
*/
_renderPrimaryToolbar() {
return (
2017-11-07 23:26:23 +00:00
<View
key = 'primaryToolbar'
pointerEvents = 'box-none'
2017-11-07 23:26:23 +00:00
style = { styles.primaryToolbar }>
<AudioMuteButton
styles = { primaryToolbarButtonStyles }
toggledStyles = { primaryToolbarToggledButtonStyles } />
<HangupButton styles = { hangupButtonStyles } />
<VideoMuteButton
styles = { primaryToolbarButtonStyles }
toggledStyles = { primaryToolbarToggledButtonStyles } />
</View>
);
}
/**
* Renders the toolbar which contains the secondary buttons such as toggle
* camera facing mode.
*
* @private
* @returns {ReactElement}
*/
_renderSecondaryToolbar() {
return (
2017-11-07 23:26:23 +00:00
<View
key = 'secondaryToolbar'
pointerEvents = 'box-none'
2017-11-07 23:26:23 +00:00
style = { styles.secondaryToolbar }>
<AudioRouteButton styles = { secondaryToolbarButtonStyles } />
<ToggleCameraButton styles = { secondaryToolbarButtonStyles } />
<AudioOnlyButton styles = { secondaryToolbarButtonStyles } />
<RoomLockButton styles = { secondaryToolbarButtonStyles } />
<InviteButton styles = { secondaryToolbarButtonStyles } />
<PictureInPictureButton
styles = { secondaryToolbarButtonStyles } />
</View>
);
}
/**
2017-11-07 14:28:08 +00:00
* Renders the primary and the secondary toolbars.
*
* @private
2017-11-07 14:28:08 +00:00
* @returns {[ReactElement, ReactElement]}
*/
_renderToolbars() {
2017-11-07 14:28:08 +00:00
return [
this._renderSecondaryToolbar(),
this._renderPrimaryToolbar()
];
}
}
2017-02-16 23:02:40 +00:00
/**
* Maps parts of the redux state to {@link Toolbox} (React {@code Component})
* props.
2017-02-16 23:02:40 +00:00
*
* @param {Object} state - The redux state of which parts are to be mapped to
* {@code Toolbox} props.
* @protected
2017-02-16 23:02:40 +00:00
* @returns {{
* _enabled: boolean,
* _visible: boolean
2017-02-16 23:02:40 +00:00
* }}
*/
function _mapStateToProps(state: Object): Object {
const { enabled, visible } = state['features/toolbox'];
2017-02-16 23:02:40 +00:00
return {
/**
* The indicator which determines whether the toolbox is enabled.
*
* @private
* @type {boolean}
*/
_enabled: enabled,
2017-02-16 23:02:40 +00:00
/**
* Flag showing whether toolbox is visible.
2017-02-16 23:02:40 +00:00
*
* @protected
* @type {boolean}
*/
_visible: visible
2017-02-16 23:02:40 +00:00
};
}
export default connect(_mapStateToProps)(makeAspectRatioAware(Toolbox));