You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbox.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  5. import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
  6. import { Container } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import { StyleType } from '../../../base/styles';
  9. import { ChatButton } from '../../../chat';
  10. import { InfoDialogButton } from '../../../invite';
  11. import { isToolboxVisible } from '../../functions';
  12. import AudioMuteButton from '../AudioMuteButton';
  13. import HangupButton from '../HangupButton';
  14. import OverflowMenuButton from './OverflowMenuButton';
  15. import styles from './styles';
  16. import VideoMuteButton from '../VideoMuteButton';
  17. /**
  18. * The type of {@link Toolbox}'s React {@code Component} props.
  19. */
  20. type Props = {
  21. /**
  22. * Whether the chat feature has been enabled. The meeting info button will be displayed in its place when disabled.
  23. */
  24. _chatEnabled: boolean,
  25. /**
  26. * The color-schemed stylesheet of the feature.
  27. */
  28. _styles: StyleType,
  29. /**
  30. * The indicator which determines whether the toolbox is visible.
  31. */
  32. _visible: boolean,
  33. /**
  34. * The redux {@code dispatch} function.
  35. */
  36. dispatch: Function
  37. };
  38. /**
  39. * The type of {@link Toolbox}'s React {@code Component} state.
  40. */
  41. type State = {
  42. /**
  43. * The detected width for this component.
  44. */
  45. width: number
  46. };
  47. /**
  48. * Implements the conference toolbox on React Native.
  49. */
  50. class Toolbox extends Component<Props, State> {
  51. state = {
  52. width: 0
  53. };
  54. /**
  55. * Initializes a new {@code Toolbox} instance.
  56. *
  57. * @inheritdoc
  58. */
  59. constructor(props: Props) {
  60. super(props);
  61. // Bind event handlers so they are only bound once per instance.
  62. this._onLayout = this._onLayout.bind(this);
  63. }
  64. /**
  65. * Implements React's {@link Component#render()}.
  66. *
  67. * @inheritdoc
  68. * @returns {ReactElement}
  69. */
  70. render() {
  71. return (
  72. <Container
  73. onLayout = { this._onLayout }
  74. style = { styles.toolbox }
  75. visible = { this.props._visible }>
  76. { this._renderToolbar() }
  77. </Container>
  78. );
  79. }
  80. /**
  81. * Constructs the toggled style of the chat button. This cannot be done by
  82. * simple style inheritance due to the size calculation done in this
  83. * component.
  84. *
  85. * @param {Object} baseStyle - The base style that was originally
  86. * calculated.
  87. * @returns {Object | Array}
  88. */
  89. _getChatButtonToggledStyle(baseStyle) {
  90. const { _styles } = this.props;
  91. if (Array.isArray(baseStyle.style)) {
  92. return {
  93. ...baseStyle,
  94. style: [
  95. ...baseStyle.style,
  96. _styles.chatButtonOverride.toggled
  97. ]
  98. };
  99. }
  100. return {
  101. ...baseStyle,
  102. style: [
  103. baseStyle.style,
  104. _styles.chatButtonOverride.toggled
  105. ]
  106. };
  107. }
  108. _onLayout: (Object) => void;
  109. /**
  110. * Handles the "on layout" View's event and stores the width as state.
  111. *
  112. * @param {Object} event - The "on layout" event object/structure passed
  113. * by react-native.
  114. * @private
  115. * @returns {void}
  116. */
  117. _onLayout({ nativeEvent: { layout: { width } } }) {
  118. this.setState({ width });
  119. }
  120. /**
  121. * Renders the toolbar. In order to avoid a weird visual effect in which the
  122. * toolbar is (visually) rendered and then visibly changes its size, it is
  123. * rendered only after we've figured out the width available to the toolbar.
  124. *
  125. * @returns {React$Node}
  126. */
  127. _renderToolbar() {
  128. const { _chatEnabled, _styles } = this.props;
  129. const { buttonStyles, buttonStylesBorderless, hangupButtonStyles, toggledButtonStyles } = _styles;
  130. return (
  131. <View
  132. pointerEvents = 'box-none'
  133. style = { styles.toolbar }>
  134. {
  135. _chatEnabled
  136. && <ChatButton
  137. styles = { buttonStylesBorderless }
  138. toggledStyles = {
  139. this._getChatButtonToggledStyle(toggledButtonStyles)
  140. } />
  141. }
  142. {
  143. !_chatEnabled
  144. && <InfoDialogButton
  145. styles = { buttonStyles }
  146. toggledStyles = { toggledButtonStyles } />
  147. }
  148. <AudioMuteButton
  149. styles = { buttonStyles }
  150. toggledStyles = { toggledButtonStyles } />
  151. <HangupButton
  152. styles = { hangupButtonStyles } />
  153. <VideoMuteButton
  154. styles = { buttonStyles }
  155. toggledStyles = { toggledButtonStyles } />
  156. <OverflowMenuButton
  157. styles = { buttonStylesBorderless }
  158. toggledStyles = { toggledButtonStyles } />
  159. </View>
  160. );
  161. }
  162. }
  163. /**
  164. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  165. * props.
  166. *
  167. * @param {Object} state - The redux state of which parts are to be mapped to
  168. * {@code Toolbox} props.
  169. * @private
  170. * @returns {{
  171. * _chatEnabled: boolean,
  172. * _styles: StyleType,
  173. * _visible: boolean
  174. * }}
  175. */
  176. function _mapStateToProps(state: Object): Object {
  177. return {
  178. _chatEnabled: getFeatureFlag(state, CHAT_ENABLED, true),
  179. _styles: ColorSchemeRegistry.get(state, 'Toolbox'),
  180. _visible: isToolboxVisible(state)
  181. };
  182. }
  183. export default connect(_mapStateToProps)(Toolbox);