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

VolumeSlider.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Slider, View } from 'react-native';
  4. import { withTheme } from 'react-native-paper';
  5. import { Icon, IconVolumeEmpty } from '../../../base/icons';
  6. import { VOLUME_SLIDER_SCALE } from '../../constants';
  7. import styles from './styles';
  8. /**
  9. * The type of the React {@code Component} props of {@link VolumeSlider}.
  10. */
  11. type Props = {
  12. /**
  13. * The value of the audio slider should display at when the component first
  14. * mounts. Changes will be stored in state. The value should be a number
  15. * between 0 and 1.
  16. */
  17. initialValue: number,
  18. /**
  19. * The callback to invoke when the audio slider value changes.
  20. */
  21. onChange: Function,
  22. /**
  23. * Theme used for styles.
  24. */
  25. theme: Object
  26. };
  27. /**
  28. * The type of the React {@code Component} state of {@link VolumeSlider}.
  29. */
  30. type State = {
  31. /**
  32. * The volume of the participant's audio element. The value will
  33. * be represented by a slider.
  34. */
  35. volumeLevel: number
  36. };
  37. /**
  38. * Component that renders the volume slider.
  39. *
  40. * @returns {React$Element<any>}
  41. */
  42. class VolumeSlider extends Component<Props, State> {
  43. /**
  44. * Initializes a new {@code VolumeSlider} instance.
  45. *
  46. * @param {Object} props - The read-only properties with which the new
  47. * instance is to be initialized.
  48. */
  49. constructor(props: Props) {
  50. super(props);
  51. this.state = {
  52. volumeLevel: (props.initialValue || 0) * VOLUME_SLIDER_SCALE
  53. };
  54. // Bind event handlers so they are only bound once for every instance.
  55. this._onVolumeChange = this._onVolumeChange.bind(this);
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement}
  62. */
  63. render() {
  64. const { theme } = this.props;
  65. const { volumeLevel } = this.state;
  66. const { palette } = theme;
  67. return (
  68. <View style = { styles.volumeSliderContainer }>
  69. <Icon
  70. size = { 24 }
  71. src = { IconVolumeEmpty }
  72. style = { styles.volumeIcon } />
  73. <Slider
  74. maximumTrackTintColor = { palette.field02 }
  75. maximumValue = { VOLUME_SLIDER_SCALE }
  76. minimumTrackTintColor = { palette.action01 }
  77. minimumValue = { 0 }
  78. onValueChange = { this._onVolumeChange }
  79. style = { styles.sliderContainer }
  80. thumbTintColor = { palette.field02 }
  81. value = { volumeLevel } />
  82. </View>
  83. );
  84. }
  85. _onVolumeChange: (Object) => void;
  86. /**
  87. * Sets the internal state of the volume level for the volume slider.
  88. * Invokes the prop onVolumeChange to notify of volume changes.
  89. *
  90. * @param {number} volumeLevel - Selected volume on slider.
  91. * @private
  92. * @returns {void}
  93. */
  94. _onVolumeChange(volumeLevel) {
  95. const { onChange } = this.props;
  96. onChange(volumeLevel / VOLUME_SLIDER_SCALE);
  97. this.setState({ volumeLevel });
  98. }
  99. }
  100. export default withTheme(VolumeSlider);