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.

VideoSwitch.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Switch, TouchableWithoutFeedback, View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../base/i18n';
  6. import { Header, Text } from '../../base/react';
  7. import { updateSettings } from '../../base/settings';
  8. import styles, { SWITCH_THUMB_COLOR, SWITCH_UNDER_COLOR } from './styles';
  9. /**
  10. * The type of the React {@code Component} props of {@link VideoSwitch}.
  11. */
  12. type Props = {
  13. /**
  14. * The redux {@code dispatch} function.
  15. */
  16. dispatch: Function,
  17. /**
  18. * The i18n translate function.
  19. */
  20. t: Function,
  21. /**
  22. * The current settings from redux.
  23. */
  24. _settings: Object
  25. };
  26. /**
  27. * Renders the "Video <-> Voice" switch on the {@code WelcomePage}.
  28. */
  29. class VideoSwitch extends Component<Props> {
  30. /**
  31. * Initializes a new {@code VideoSwitch} instance.
  32. *
  33. * @inheritdoc
  34. */
  35. constructor(props) {
  36. super(props);
  37. // Bind event handlers so they are only bound once per instance.
  38. this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this);
  39. this._onStartAudioOnlyFalse = this._onStartAudioOnlyChangeFn(false);
  40. this._onStartAudioOnlyTrue = this._onStartAudioOnlyChangeFn(true);
  41. }
  42. /**
  43. * Implements React's {@link Component#render}.
  44. *
  45. * @inheritdoc
  46. */
  47. render() {
  48. const { t, _settings } = this.props;
  49. const { textStyle } = Header;
  50. return (
  51. <View style = { styles.audioVideoSwitchContainer }>
  52. <TouchableWithoutFeedback
  53. onPress = { this._onStartAudioOnlyFalse }>
  54. <Text style = { textStyle }>
  55. { t('welcomepage.audioVideoSwitch.video') }
  56. </Text>
  57. </TouchableWithoutFeedback>
  58. <Switch
  59. onTintColor = { SWITCH_UNDER_COLOR }
  60. onValueChange = { this._onStartAudioOnlyChange }
  61. style = { styles.audioVideoSwitch }
  62. thumbTintColor = { SWITCH_THUMB_COLOR }
  63. value = { _settings.startAudioOnly } />
  64. <TouchableWithoutFeedback
  65. onPress = { this._onStartAudioOnlyTrue }>
  66. <Text style = { textStyle }>
  67. { t('welcomepage.audioVideoSwitch.audio') }
  68. </Text>
  69. </TouchableWithoutFeedback>
  70. </View>
  71. );
  72. }
  73. _onStartAudioOnlyChange: boolean => void;
  74. /**
  75. * Handles the audio-video switch changes.
  76. *
  77. * @private
  78. * @param {boolean} startAudioOnly - The new startAudioOnly value.
  79. * @returns {void}
  80. */
  81. _onStartAudioOnlyChange(startAudioOnly) {
  82. const { dispatch } = this.props;
  83. dispatch(updateSettings({
  84. startAudioOnly
  85. }));
  86. }
  87. /**
  88. * Creates a function that forwards the {@code startAudioOnly} changes to
  89. * the function that handles it.
  90. *
  91. * @private
  92. * @param {boolean} startAudioOnly - The new {@code startAudioOnly} value.
  93. * @returns {void}
  94. */
  95. _onStartAudioOnlyChangeFn(startAudioOnly) {
  96. return () => this._onStartAudioOnlyChange(startAudioOnly);
  97. }
  98. _onStartAudioOnlyFalse: boolean => void;
  99. _onStartAudioOnlyTrue: boolean => void;
  100. }
  101. /**
  102. * Maps (parts of) the redux state to the React {@code Component} props of
  103. * {@code VideoSwitch}.
  104. *
  105. * @param {Object} state - The redux state.
  106. * @protected
  107. * @returns {{
  108. * _settings: Object
  109. * }}
  110. */
  111. export function _mapStateToProps(state: Object) {
  112. return {
  113. _settings: state['features/base/settings']
  114. };
  115. }
  116. export default translate(connect(_mapStateToProps)(VideoSwitch));