Browse Source

[RN] Make the audio-video labels touchable

master
zbettenbuk 7 years ago
parent
commit
b777322fdc

+ 136
- 0
react/features/welcome/components/VideoSwitch.js View File

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

+ 5
- 38
react/features/welcome/components/WelcomePage.native.js View File

3
     Animated,
3
     Animated,
4
     Keyboard,
4
     Keyboard,
5
     SafeAreaView,
5
     SafeAreaView,
6
-    Switch,
7
     TextInput,
6
     TextInput,
8
     TouchableHighlight,
7
     TouchableHighlight,
9
     TouchableOpacity,
8
     TouchableOpacity,
14
 import { translate } from '../../base/i18n';
13
 import { translate } from '../../base/i18n';
15
 import { Icon } from '../../base/font-icons';
14
 import { Icon } from '../../base/font-icons';
16
 import { MEDIA_TYPE } from '../../base/media';
15
 import { MEDIA_TYPE } from '../../base/media';
17
-import { updateProfile } from '../../base/profile';
18
 import { LoadingIndicator, Header, Text } from '../../base/react';
16
 import { LoadingIndicator, Header, Text } from '../../base/react';
19
 import { ColorPalette } from '../../base/styles';
17
 import { ColorPalette } from '../../base/styles';
20
 import {
18
 import {
27
 import { setSideBarVisible } from '../actions';
25
 import { setSideBarVisible } from '../actions';
28
 import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
26
 import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
29
 import styles, {
27
 import styles, {
30
-    PLACEHOLDER_TEXT_COLOR,
31
-    SWITCH_THUMB_COLOR,
32
-    SWITCH_UNDER_COLOR
28
+    PLACEHOLDER_TEXT_COLOR
33
 } from './styles';
29
 } from './styles';
30
+import VideoSwitch from './VideoSwitch';
34
 import WelcomePageLists from './WelcomePageLists';
31
 import WelcomePageLists from './WelcomePageLists';
35
 import WelcomePageSideBar from './WelcomePageSideBar';
32
 import WelcomePageSideBar from './WelcomePageSideBar';
36
 
33
 
55
         this._getHintBoxStyle = this._getHintBoxStyle.bind(this);
52
         this._getHintBoxStyle = this._getHintBoxStyle.bind(this);
56
         this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
53
         this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
57
         this._onShowSideBar = this._onShowSideBar.bind(this);
54
         this._onShowSideBar = this._onShowSideBar.bind(this);
58
-        this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this);
59
         this._renderHintBox = this._renderHintBox.bind(this);
55
         this._renderHintBox = this._renderHintBox.bind(this);
60
     }
56
     }
61
 
57
 
87
      * @returns {ReactElement}
83
      * @returns {ReactElement}
88
      */
84
      */
89
     render() {
85
     render() {
90
-        const { buttonStyle, pageStyle, textStyle } = Header;
91
-        const { t, _profile } = this.props;
86
+        const { buttonStyle, pageStyle } = Header;
87
+        const { t } = this.props;
92
 
88
 
93
         return (
89
         return (
94
             <LocalVideoTrackUnderlay style = { styles.welcomePage }>
90
             <LocalVideoTrackUnderlay style = { styles.welcomePage }>
99
                                 name = 'menu'
95
                                 name = 'menu'
100
                                 style = { buttonStyle } />
96
                                 style = { buttonStyle } />
101
                         </TouchableOpacity>
97
                         </TouchableOpacity>
102
-                        <View style = { styles.audioVideoSwitchContainer }>
103
-                            <Text style = { textStyle } >
104
-                                { t('welcomepage.audioVideoSwitch.video') }
105
-                            </Text>
106
-                            <Switch
107
-                                onTintColor = { SWITCH_UNDER_COLOR }
108
-                                onValueChange = { this._onStartAudioOnlyChange }
109
-                                style = { styles.audioVideoSwitch }
110
-                                thumbTintColor = { SWITCH_THUMB_COLOR }
111
-                                value = { _profile.startAudioOnly } />
112
-                            <Text style = { textStyle } >
113
-                                { t('welcomepage.audioVideoSwitch.audio') }
114
-                            </Text>
115
-                        </View>
98
+                        <VideoSwitch />
116
                     </Header>
99
                     </Header>
117
                     <SafeAreaView style = { styles.roomContainer } >
100
                     <SafeAreaView style = { styles.roomContainer } >
118
                         <View style = { styles.joinControls } >
101
                         <View style = { styles.joinControls } >
202
         this.props.dispatch(setSideBarVisible(true));
185
         this.props.dispatch(setSideBarVisible(true));
203
     }
186
     }
204
 
187
 
205
-    /**
206
-     * Handles the audio-video switch changes.
207
-     *
208
-     * @private
209
-     * @param {boolean} startAudioOnly - The new startAudioOnly value.
210
-     * @returns {void}
211
-     */
212
-    _onStartAudioOnlyChange(startAudioOnly) {
213
-        const { dispatch } = this.props;
214
-
215
-        dispatch(updateProfile({
216
-            ...this.props._profile,
217
-            startAudioOnly
218
-        }));
219
-    }
220
-
221
     /**
188
     /**
222
      * Renders the hint box if necessary.
189
      * Renders the hint box if necessary.
223
      *
190
      *

Loading…
Cancel
Save