jiti-meet/react/features/mobile/audio-mode/components/AudioRouteButton.js

131 lines
3.4 KiB
JavaScript
Raw Normal View History

// @flow
import React from 'react';
import {
findNodeHandle,
NativeModules,
requireNativeComponent,
View
} from 'react-native';
import { connect } from 'react-redux';
import { openDialog } from '../../../base/dialog';
import { translate } from '../../../base/i18n';
import { AbstractButton } from '../../../base/toolbox';
import type { AbstractButtonProps } from '../../../base/toolbox';
import AudioRoutePickerDialog from './AudioRoutePickerDialog';
/**
* The {@code MPVolumeView} React {@code Component}. It will only be available
* on iOS.
*/
const MPVolumeView
= NativeModules.MPVolumeViewManager
2018-10-03 09:29:19 +00:00
&& requireNativeComponent('MPVolumeView');
/**
* The style required to hide the {@code MPVolumeView}, since it's displayed
* programmatically.
*/
const HIDE_VIEW_STYLE = { display: 'none' };
type Props = AbstractButtonProps & {
/**
* The redux {@code dispatch} function used to open/show the
* {@code AudioRoutePickerDialog}.
*/
dispatch: Function
};
/**
* A toolbar button which triggers an audio route picker when pressed.
*/
class AudioRouteButton extends AbstractButton<Props, *> {
fix(i18n) Accessiblity labels translations (#3071) * fix(toolbar): accessibilityLabel should be translatable. This commit adds a helper property to get the accessibilityLabel of an item, providing a translation if one is available. This mimics the behavior of label and tooltip. * fix(toolbar) 'hangup' button accessibilityLabel i18n * fix(toolbar) 'mute' button accessibilityLabel i18n * fix(toolbar) 'videomute' button accessibilityLabel i18n * fix(toolbar) 'moreActions' button accessibilityLabel i18n * fix(toolbar) 'shareRoom' button accessibilityLabel i18n * fix(toolbar) 'audioRoute' button accessibilityLabel i18n * fix(toolbar) 'toggleCamera' button accessibilityLabel i18n * fix(toolbar) 'audioOnly' button accessibilityLabel i18n * fix(toolbar) 'roomLock' button accessibilityLabel i18n * fix(toolbar) 'pip' button accessibilityLabel i18n * fix(toolbar) 'invite' button accessibilityLabel i18n * fix(toolbar) 'raiseHand' button accessibilityLabel i18n * fix(toolbar) 'chat' button accessibilityLabel i18n * fix(toolbar) 'shareYourScreen' button accessibilityLabel i18n * fix(toolbar) 'fullScreen' button accessibilityLabel i18n * fix(toolbar) 'sharedvideo' button accessibilityLabel i18n * fix(toolbar) 'document' button accessibilityLabel i18n * fix(toolbar) 'speakerStats' button accessibilityLabel i18n * fix(toolbar) 'feedback' button accessibilityLabel i18n * fix(toolbar) 'shortcuts' button accessibilityLabel i18n * fix(toolbar) 'recording' button accessibilityLabel i18n * fix(toolbar) 'settings' button accessibilityLabel i18n * fix(welcomepage) accessibilityLabels i18n * fix(toolbar) 'info' button accessibilityLabel i18n * fix(i18n): Add translation to various aria-label property values. * fix(i18n): Differentiate between overflow menu and button.
2018-06-07 20:32:18 +00:00
accessibilityLabel = 'toolbar.accessibilityLabel.audioRoute';
iconName = 'icon-volume';
label = 'toolbar.audioRoute';
_volumeComponent: ?Object;
/**
* Initializes a new {@code AudioRouteButton} instance.
*
* @param {Props} props - The React {@code Component} props to initialize
* the new {@code AudioRouteButton} instance with.
*/
constructor(props: Props) {
super(props);
/**
* The internal reference to the React {@code MPVolumeView} for
* showing the volume control view.
*
* @private
* @type {ReactElement}
*/
this._volumeComponent = null;
// Bind event handlers so they are only bound once per instance.
this._setVolumeComponent = this._setVolumeComponent.bind(this);
}
/**
* Handles clicking / pressing the button, and opens the appropriate dialog.
*
* @private
* @returns {void}
*/
_handleClick() {
if (MPVolumeView) {
NativeModules.MPVolumeViewManager.show(
findNodeHandle(this._volumeComponent));
} else if (AudioRoutePickerDialog) {
this.props.dispatch(openDialog(AudioRoutePickerDialog));
}
}
_setVolumeComponent: (?Object) => void;
/**
* Sets the internal reference to the React Component wrapping the
* {@code MPVolumeView} component.
*
* @param {ReactElement} component - React Component.
* @private
* @returns {void}
*/
_setVolumeComponent(component) {
this._volumeComponent = component;
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
2018-05-11 02:10:26 +00:00
* @returns {React$Node}
*/
render() {
if (!MPVolumeView && !AudioRoutePickerDialog) {
return null;
}
const element = super.render();
return (
<View>
{ element }
{
MPVolumeView
&& <MPVolumeView
ref = { this._setVolumeComponent }
style = { HIDE_VIEW_STYLE } />
}
</View>
);
}
}
export default translate(connect()(AudioRouteButton));