diff --git a/react/features/welcome/components/VideoSwitch.js b/react/features/welcome/components/VideoSwitch.js new file mode 100644 index 000000000..fa0179ce2 --- /dev/null +++ b/react/features/welcome/components/VideoSwitch.js @@ -0,0 +1,136 @@ +// @flow +import React, { Component } from 'react'; +import { + Switch, + TouchableWithoutFeedback, + View +} from 'react-native'; +import { connect } from 'react-redux'; + +import { translate } from '../../base/i18n'; +import { updateProfile } from '../../base/profile'; +import { Header, Text } from '../../base/react'; + +import styles, { + SWITCH_THUMB_COLOR, + SWITCH_UNDER_COLOR +} from './styles'; + +type Props = { + + /** + * The Redux dispatch functions. + */ + dispatch: Function, + + /** + * The i18n translate function. + */ + t: Function, + + /** + * The current profile settings from Redux. + */ + _profile: Object +}; + +/** + * Renders the audio-video switch on the welcome screen. + */ +class VideoSwitch extends Component { + /** + * Constructor of the component. + * + * @inheritdoc + */ + constructor(props) { + super(props); + + this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this); + } + + /** + * Implements React Component's render. + * + * @inheritdoc + */ + render() { + const { t, _profile } = this.props; + const { textStyle } = Header; + + return ( + + + + { t('welcomepage.audioVideoSwitch.video') } + + + + + + { t('welcomepage.audioVideoSwitch.audio') } + + + + ); + } + + /** + * Creates a function that forwards the startAudioOnly changes to the + * function that handles it. + * + * @private + * @param {boolean} startAudioOnly - The new startAudioOnly value. + * @returns {void} + */ + _onStartAudioOnlyChangeFn(startAudioOnly) { + return () => this._onStartAudioOnlyChange(startAudioOnly); + } + + _onStartAudioOnlyChange: boolean => void + + /** + * Handles the audio-video switch changes. + * + * @private + * @param {boolean} startAudioOnly - The new startAudioOnly value. + * @returns {void} + */ + _onStartAudioOnlyChange(startAudioOnly) { + const { dispatch } = this.props; + + dispatch(updateProfile({ + ...this.props._profile, + startAudioOnly + })); + } +} + +/** + * Maps (parts of) the redux state to the React {@code Component} props of + * {@code VideoSwitch}. + * + * @param {Object} state - The redux state. + * @protected + * @returns {{ + * _profile: Object + * }} + */ +export function _mapStateToProps(state: Object) { + return { + _profile: state['features/base/profile'] + }; +} + +export default translate(connect(_mapStateToProps)(VideoSwitch)); diff --git a/react/features/welcome/components/WelcomePage.native.js b/react/features/welcome/components/WelcomePage.native.js index 1ee589837..10e2a8ef7 100644 --- a/react/features/welcome/components/WelcomePage.native.js +++ b/react/features/welcome/components/WelcomePage.native.js @@ -3,7 +3,6 @@ import { Animated, Keyboard, SafeAreaView, - Switch, TextInput, TouchableHighlight, TouchableOpacity, @@ -14,7 +13,6 @@ import { connect } from 'react-redux'; import { translate } from '../../base/i18n'; import { Icon } from '../../base/font-icons'; import { MEDIA_TYPE } from '../../base/media'; -import { updateProfile } from '../../base/profile'; import { LoadingIndicator, Header, Text } from '../../base/react'; import { ColorPalette } from '../../base/styles'; import { @@ -27,10 +25,9 @@ import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage'; import { setSideBarVisible } from '../actions'; import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay'; import styles, { - PLACEHOLDER_TEXT_COLOR, - SWITCH_THUMB_COLOR, - SWITCH_UNDER_COLOR + PLACEHOLDER_TEXT_COLOR } from './styles'; +import VideoSwitch from './VideoSwitch'; import WelcomePageLists from './WelcomePageLists'; import WelcomePageSideBar from './WelcomePageSideBar'; @@ -55,7 +52,6 @@ class WelcomePage extends AbstractWelcomePage { this._getHintBoxStyle = this._getHintBoxStyle.bind(this); this._onFieldFocusChange = this._onFieldFocusChange.bind(this); this._onShowSideBar = this._onShowSideBar.bind(this); - this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this); this._renderHintBox = this._renderHintBox.bind(this); } @@ -87,8 +83,8 @@ class WelcomePage extends AbstractWelcomePage { * @returns {ReactElement} */ render() { - const { buttonStyle, pageStyle, textStyle } = Header; - const { t, _profile } = this.props; + const { buttonStyle, pageStyle } = Header; + const { t } = this.props; return ( @@ -99,20 +95,7 @@ class WelcomePage extends AbstractWelcomePage { name = 'menu' style = { buttonStyle } /> - - - { t('welcomepage.audioVideoSwitch.video') } - - - - { t('welcomepage.audioVideoSwitch.audio') } - - + @@ -202,22 +185,6 @@ class WelcomePage extends AbstractWelcomePage { this.props.dispatch(setSideBarVisible(true)); } - /** - * Handles the audio-video switch changes. - * - * @private - * @param {boolean} startAudioOnly - The new startAudioOnly value. - * @returns {void} - */ - _onStartAudioOnlyChange(startAudioOnly) { - const { dispatch } = this.props; - - dispatch(updateProfile({ - ...this.props._profile, - startAudioOnly - })); - } - /** * Renders the hint box if necessary. *