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.

Toolbar.native.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import React from 'react';
  2. import { View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { MEDIA_TYPE, toggleCameraFacingMode } from '../../base/media';
  5. import { Container } from '../../base/react';
  6. import { ColorPalette } from '../../base/styles';
  7. import { AbstractToolbar, mapStateToProps } from './AbstractToolbar';
  8. import { styles } from './styles';
  9. import ToolbarButton from './ToolbarButton';
  10. /**
  11. * Implements the conference toolbar on React Native.
  12. *
  13. * @extends AbstractToolbar
  14. */
  15. class Toolbar extends AbstractToolbar {
  16. /**
  17. * Toolbar component's property types.
  18. *
  19. * @static
  20. */
  21. static propTypes = AbstractToolbar.propTypes
  22. /**
  23. * Initializes a new Toolbar instance.
  24. *
  25. * @param {Object} props - The read-only React Component props with which
  26. * the new instance is to be initialized.
  27. */
  28. constructor(props) {
  29. super(props);
  30. // Bind event handlers so they are only bound once for every instance.
  31. this._toggleCameraFacingMode
  32. = this._toggleCameraFacingMode.bind(this);
  33. }
  34. /**
  35. * Implements React's {@link Component#render()}.
  36. *
  37. * @inheritdoc
  38. * @returns {ReactElement}
  39. */
  40. render() {
  41. return (
  42. <Container
  43. style = { styles.toolbarContainer }
  44. visible = { this.props.visible }>
  45. {
  46. this._renderPrimaryToolbar()
  47. }
  48. {
  49. this._renderSecondaryToolbar()
  50. }
  51. </Container>
  52. );
  53. }
  54. /**
  55. * Renders the toolbar which contains the primary buttons such as hangup,
  56. * audio and video mute.
  57. *
  58. * @private
  59. * @returns {ReactElement}
  60. */
  61. _renderPrimaryToolbar() {
  62. const audioButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.AUDIO);
  63. const videoButtonStyles = this._getMuteButtonStyles(MEDIA_TYPE.VIDEO);
  64. /* eslint-disable react/jsx-handler-names */
  65. return (
  66. <View style = { styles.primaryToolbar }>
  67. <ToolbarButton
  68. iconName = { audioButtonStyles.iconName }
  69. iconStyle = { audioButtonStyles.iconStyle }
  70. onClick = { this._toggleAudio }
  71. style = { audioButtonStyles.buttonStyle } />
  72. <ToolbarButton
  73. iconName = 'hangup'
  74. iconStyle = { styles.whiteIcon }
  75. onClick = { this._onHangup }
  76. style = {{
  77. ...styles.toolbarButton,
  78. backgroundColor: ColorPalette.red
  79. }}
  80. underlayColor = { ColorPalette.buttonUnderlay } />
  81. <ToolbarButton
  82. iconName = { videoButtonStyles.iconName }
  83. iconStyle = { videoButtonStyles.iconStyle }
  84. onClick = { this._toggleVideo }
  85. style = { videoButtonStyles.buttonStyle } />
  86. </View>
  87. );
  88. /* eslint-enable react/jsx-handler-names */
  89. }
  90. /**
  91. * Renders the toolbar which contains the secondary buttons such as toggle
  92. * camera facing mode.
  93. *
  94. * @private
  95. * @returns {ReactElement}
  96. */
  97. _renderSecondaryToolbar() {
  98. /* eslint-disable react/jsx-handler-names */
  99. // TODO Use an appropriate icon for toggle camera facing mode.
  100. return (
  101. <View style = { styles.secondaryToolbar }>
  102. <ToolbarButton
  103. iconName = 'reload'
  104. iconStyle = { styles.whiteIcon }
  105. onClick = { this._toggleCameraFacingMode }
  106. style = { styles.toggleCameraFacingModeButton }
  107. underlayColor = 'transparent' />
  108. </View>
  109. );
  110. /* eslint-enable react/jsx-handler-names */
  111. }
  112. /**
  113. * Switches between the front/user-facing and rear/environment-facing
  114. * cameras.
  115. *
  116. * @private
  117. * @returns {void}
  118. */
  119. _toggleCameraFacingMode() {
  120. this.props.dispatch(toggleCameraFacingMode());
  121. }
  122. }
  123. /**
  124. * Additional properties for various icons, which are now platform-dependent.
  125. * This is done to have common logic of generating styles for web and native.
  126. * TODO As soon as we have common font sets for web and native, this will no
  127. * longer be required.
  128. */
  129. Object.assign(Toolbar.prototype, {
  130. audioIcon: 'microphone',
  131. audioMutedIcon: 'mic-disabled',
  132. videoIcon: 'webCam',
  133. videoMutedIcon: 'camera-disabled'
  134. });
  135. export default connect(mapStateToProps)(Toolbar);