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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { View } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../../base/color-scheme';
  5. import { Container } from '../../../base/react';
  6. import { connect } from '../../../base/redux';
  7. import { StyleType } from '../../../base/styles';
  8. import { ChatButton } from '../../../chat';
  9. import { isToolboxVisible } from '../../functions';
  10. import AudioMuteButton from '../AudioMuteButton';
  11. import HangupButton from '../HangupButton';
  12. import VideoMuteButton from '../VideoMuteButton';
  13. import OverflowMenuButton from './OverflowMenuButton';
  14. import styles from './styles';
  15. /**
  16. * The type of {@link Toolbox}'s React {@code Component} props.
  17. */
  18. type Props = {
  19. /**
  20. * The color-schemed stylesheet of the feature.
  21. */
  22. _styles: StyleType,
  23. /**
  24. * The indicator which determines whether the toolbox is visible.
  25. */
  26. _visible: boolean,
  27. /**
  28. * The redux {@code dispatch} function.
  29. */
  30. dispatch: Function
  31. };
  32. /**
  33. * Implements the conference toolbox on React Native.
  34. */
  35. class Toolbox extends PureComponent<Props> {
  36. /**
  37. * Implements React's {@link Component#render()}.
  38. *
  39. * @inheritdoc
  40. * @returns {ReactElement}
  41. */
  42. render() {
  43. return (
  44. <Container
  45. style = { styles.toolbox }
  46. visible = { this.props._visible }>
  47. { this._renderToolbar() }
  48. </Container>
  49. );
  50. }
  51. /**
  52. * Constructs the toggled style of the chat button. This cannot be done by
  53. * simple style inheritance due to the size calculation done in this
  54. * component.
  55. *
  56. * @param {Object} baseStyle - The base style that was originally
  57. * calculated.
  58. * @returns {Object | Array}
  59. */
  60. _getChatButtonToggledStyle(baseStyle) {
  61. const { _styles } = this.props;
  62. if (Array.isArray(baseStyle.style)) {
  63. return {
  64. ...baseStyle,
  65. style: [
  66. ...baseStyle.style,
  67. _styles.chatButtonOverride.toggled
  68. ]
  69. };
  70. }
  71. return {
  72. ...baseStyle,
  73. style: [
  74. baseStyle.style,
  75. _styles.chatButtonOverride.toggled
  76. ]
  77. };
  78. }
  79. /**
  80. * Renders the toolbar. In order to avoid a weird visual effect in which the
  81. * toolbar is (visually) rendered and then visibly changes its size, it is
  82. * rendered only after we've figured out the width available to the toolbar.
  83. *
  84. * @returns {React$Node}
  85. */
  86. _renderToolbar() {
  87. const { _styles } = this.props;
  88. const { buttonStyles, buttonStylesBorderless, hangupButtonStyles, toggledButtonStyles } = _styles;
  89. return (
  90. <View
  91. accessibilityRole = 'toolbar'
  92. pointerEvents = 'box-none'
  93. style = { styles.toolbar }>
  94. <ChatButton
  95. styles = { buttonStylesBorderless }
  96. toggledStyles = { this._getChatButtonToggledStyle(toggledButtonStyles) } />
  97. <AudioMuteButton
  98. styles = { buttonStyles }
  99. toggledStyles = { toggledButtonStyles } />
  100. <HangupButton
  101. styles = { hangupButtonStyles } />
  102. <VideoMuteButton
  103. styles = { buttonStyles }
  104. toggledStyles = { toggledButtonStyles } />
  105. <OverflowMenuButton
  106. styles = { buttonStylesBorderless }
  107. toggledStyles = { toggledButtonStyles } />
  108. </View>
  109. );
  110. }
  111. }
  112. /**
  113. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  114. * props.
  115. *
  116. * @param {Object} state - The redux state of which parts are to be mapped to
  117. * {@code Toolbox} props.
  118. * @private
  119. * @returns {Props}
  120. */
  121. function _mapStateToProps(state: Object): Object {
  122. return {
  123. _styles: ColorSchemeRegistry.get(state, 'Toolbox'),
  124. _visible: isToolboxVisible(state)
  125. };
  126. }
  127. export default connect(_mapStateToProps)(Toolbox);