您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbox.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @flow
  2. import React, { PureComponent } 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. * Implements the conference toolbox on React Native.
  40. */
  41. class Toolbox extends PureComponent<Props> {
  42. /**
  43. * Implements React's {@link Component#render()}.
  44. *
  45. * @inheritdoc
  46. * @returns {ReactElement}
  47. */
  48. render() {
  49. return (
  50. <Container
  51. style = { styles.toolbox }
  52. visible = { this.props._visible }>
  53. { this._renderToolbar() }
  54. </Container>
  55. );
  56. }
  57. /**
  58. * Constructs the toggled style of the chat button. This cannot be done by
  59. * simple style inheritance due to the size calculation done in this
  60. * component.
  61. *
  62. * @param {Object} baseStyle - The base style that was originally
  63. * calculated.
  64. * @returns {Object | Array}
  65. */
  66. _getChatButtonToggledStyle(baseStyle) {
  67. const { _styles } = this.props;
  68. if (Array.isArray(baseStyle.style)) {
  69. return {
  70. ...baseStyle,
  71. style: [
  72. ...baseStyle.style,
  73. _styles.chatButtonOverride.toggled
  74. ]
  75. };
  76. }
  77. return {
  78. ...baseStyle,
  79. style: [
  80. baseStyle.style,
  81. _styles.chatButtonOverride.toggled
  82. ]
  83. };
  84. }
  85. /**
  86. * Renders the toolbar. In order to avoid a weird visual effect in which the
  87. * toolbar is (visually) rendered and then visibly changes its size, it is
  88. * rendered only after we've figured out the width available to the toolbar.
  89. *
  90. * @returns {React$Node}
  91. */
  92. _renderToolbar() {
  93. const { _chatEnabled, _styles } = this.props;
  94. const { buttonStyles, buttonStylesBorderless, hangupButtonStyles, toggledButtonStyles } = _styles;
  95. return (
  96. <View
  97. pointerEvents = 'box-none'
  98. style = { styles.toolbar }>
  99. {
  100. _chatEnabled
  101. && <ChatButton
  102. styles = { buttonStylesBorderless }
  103. toggledStyles = {
  104. this._getChatButtonToggledStyle(toggledButtonStyles)
  105. } />
  106. }
  107. {
  108. !_chatEnabled
  109. && <InfoDialogButton
  110. styles = { buttonStyles }
  111. toggledStyles = { toggledButtonStyles } />
  112. }
  113. <AudioMuteButton
  114. styles = { buttonStyles }
  115. toggledStyles = { toggledButtonStyles } />
  116. <HangupButton
  117. styles = { hangupButtonStyles } />
  118. <VideoMuteButton
  119. styles = { buttonStyles }
  120. toggledStyles = { toggledButtonStyles } />
  121. <OverflowMenuButton
  122. styles = { buttonStylesBorderless }
  123. toggledStyles = { toggledButtonStyles } />
  124. </View>
  125. );
  126. }
  127. }
  128. /**
  129. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  130. * props.
  131. *
  132. * @param {Object} state - The redux state of which parts are to be mapped to
  133. * {@code Toolbox} props.
  134. * @private
  135. * @returns {{
  136. * _chatEnabled: boolean,
  137. * _styles: StyleType,
  138. * _visible: boolean
  139. * }}
  140. */
  141. function _mapStateToProps(state: Object): Object {
  142. return {
  143. _chatEnabled: getFeatureFlag(state, CHAT_ENABLED, true),
  144. _styles: ColorSchemeRegistry.get(state, 'Toolbox'),
  145. _visible: isToolboxVisible(state)
  146. };
  147. }
  148. export default connect(_mapStateToProps)(Toolbox);