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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 { updateProfile } from '../../base/profile';
  7. import { Header, Text } from '../../base/react';
  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 profile settings from redux.
  23. */
  24. _profile: 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, _profile } = 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 = { _profile.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(updateProfile({
  84. ...this.props._profile,
  85. startAudioOnly
  86. }));
  87. }
  88. /**
  89. * Creates a function that forwards the {@code startAudioOnly} changes to
  90. * the function that handles it.
  91. *
  92. * @private
  93. * @param {boolean} startAudioOnly - The new {@code startAudioOnly} value.
  94. * @returns {void}
  95. */
  96. _onStartAudioOnlyChangeFn(startAudioOnly) {
  97. return () => this._onStartAudioOnlyChange(startAudioOnly);
  98. }
  99. _onStartAudioOnlyFalse: boolean => void;
  100. _onStartAudioOnlyTrue: boolean => void;
  101. }
  102. /**
  103. * Maps (parts of) the redux state to the React {@code Component} props of
  104. * {@code VideoSwitch}.
  105. *
  106. * @param {Object} state - The redux state.
  107. * @protected
  108. * @returns {{
  109. * _profile: Object
  110. * }}
  111. */
  112. export function _mapStateToProps(state: Object) {
  113. return {
  114. _profile: state['features/base/profile']
  115. };
  116. }
  117. export default translate(connect(_mapStateToProps)(VideoSwitch));