Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

VideoSwitch.js 4.1KB

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