Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. <View style = { styles.switchLabel }>
  55. <Text style = { textStyle }>
  56. { t('welcomepage.audioVideoSwitch.video') }
  57. </Text>
  58. </View>
  59. </TouchableWithoutFeedback>
  60. <Switch
  61. onTintColor = { SWITCH_UNDER_COLOR }
  62. onValueChange = { this._onStartAudioOnlyChange }
  63. style = { styles.audioVideoSwitch }
  64. thumbTintColor = { SWITCH_THUMB_COLOR }
  65. value = { _settings.startAudioOnly } />
  66. <TouchableWithoutFeedback
  67. onPress = { this._onStartAudioOnlyTrue }>
  68. <View style = { styles.switchLabel }>
  69. <Text style = { textStyle }>
  70. { t('welcomepage.audioVideoSwitch.audio') }
  71. </Text>
  72. </View>
  73. </TouchableWithoutFeedback>
  74. </View>
  75. );
  76. }
  77. _onStartAudioOnlyChange: boolean => void;
  78. /**
  79. * Handles the audio-video switch changes.
  80. *
  81. * @private
  82. * @param {boolean} startAudioOnly - The new startAudioOnly value.
  83. * @returns {void}
  84. */
  85. _onStartAudioOnlyChange(startAudioOnly) {
  86. const { dispatch } = this.props;
  87. dispatch(updateSettings({
  88. startAudioOnly
  89. }));
  90. }
  91. /**
  92. * Creates a function that forwards the {@code startAudioOnly} changes to
  93. * the function that handles it.
  94. *
  95. * @private
  96. * @param {boolean} startAudioOnly - The new {@code startAudioOnly} value.
  97. * @returns {void}
  98. */
  99. _onStartAudioOnlyChangeFn(startAudioOnly) {
  100. return () => this._onStartAudioOnlyChange(startAudioOnly);
  101. }
  102. _onStartAudioOnlyFalse: boolean => void;
  103. _onStartAudioOnlyTrue: boolean => void;
  104. }
  105. /**
  106. * Maps (parts of) the redux state to the React {@code Component} props of
  107. * {@code VideoSwitch}.
  108. *
  109. * @param {Object} state - The redux state.
  110. * @protected
  111. * @returns {{
  112. * _settings: Object
  113. * }}
  114. */
  115. export function _mapStateToProps(state: Object) {
  116. return {
  117. _settings: state['features/base/settings']
  118. };
  119. }
  120. export default translate(connect(_mapStateToProps)(VideoSwitch));