Browse Source

[RN] Dynamically adjust LargeView's Avatar to available size (Coding style: comments, flow)

Flow caught an incorrect function call.
master
Lyubo Marinov 7 years ago
parent
commit
cacc4bd769

+ 1
- 1
react/features/base/dialog/components/Dialog.native.js View File

@@ -42,7 +42,7 @@ type Props = {
42 42
     /**
43 43
      * I18n key to put as body title.
44 44
      */
45
-    bodyKey: String,
45
+    bodyKey: string,
46 46
 
47 47
     textInputProps: Object
48 48
 };

+ 42
- 26
react/features/base/participants/components/Avatar.native.js View File

@@ -1,4 +1,5 @@
1
-import PropTypes from 'prop-types';
1
+// @flow
2
+
2 3
 import React, { Component } from 'react';
3 4
 import { Image, View } from 'react-native';
4 5
 
@@ -23,36 +24,48 @@ import styles from './styles';
23 24
  */
24 25
 const _DEFAULT_SOURCE = require('../../../../../images/avatar.png');
25 26
 
27
+/**
28
+ * The type of the React {@link Component} props of {@link Avatar}.
29
+ */
30
+type Props = {
31
+
32
+    /**
33
+     * The size for the {@link Avatar}.
34
+     */
35
+    size: number,
36
+
37
+
38
+    /**
39
+     * The URI of the {@link Avatar}.
40
+     */
41
+    uri: string
42
+};
43
+
44
+/**
45
+ * The type of the React {@link Component} state of {@link Avatar}.
46
+ */
47
+type State = {
48
+    backgroundColor: string,
49
+    source: number | { uri: string }
50
+};
51
+
26 52
 /**
27 53
  * Implements an avatar as a React Native/mobile {@link Component}.
28 54
  */
29
-export default class Avatar extends Component {
55
+export default class Avatar extends Component<Props, State> {
30 56
     /**
31
-     * Avatar component's property types.
32
-     *
33
-     * @static
57
+     * The indicator which determines whether this {@code Avatar} has been
58
+     * unmounted.
34 59
      */
35
-    static propTypes = {
36
-        /**
37
-         * The size for the {@link Avatar}.
38
-         */
39
-        size: PropTypes.number,
40
-
41
-        /**
42
-         * The URI of the {@link Avatar}.
43
-         *
44
-         * @type {string}
45
-         */
46
-        uri: PropTypes.string
47
-    };
60
+    _unmounted: ?boolean;
48 61
 
49 62
     /**
50 63
      * Initializes a new Avatar instance.
51 64
      *
52
-     * @param {Object} props - The read-only React Component props with which
65
+     * @param {Props} props - The read-only React Component props with which
53 66
      * the new instance is to be initialized.
54 67
      */
55
-    constructor(props) {
68
+    constructor(props: Props) {
56 69
         super(props);
57 70
 
58 71
         // Fork (in Facebook/React speak) the prop uri because Image will
@@ -68,11 +81,11 @@ export default class Avatar extends Component {
68 81
      * Additionally, other props may be forked as well.
69 82
      *
70 83
      * @inheritdoc
71
-     * @param {Object} nextProps - The read-only React Component props that this
84
+     * @param {Props} nextProps - The read-only React Component props that this
72 85
      * instance will receive.
73 86
      * @returns {void}
74 87
      */
75
-    componentWillReceiveProps(nextProps) {
88
+    componentWillReceiveProps(nextProps: Props) {
76 89
         // uri
77 90
         const prevURI = this.props && this.props.uri;
78 91
         const nextURI = nextProps && nextProps.uri;
@@ -226,14 +239,17 @@ export default class Avatar extends Component {
226 239
         } = this.state;
227 240
 
228 241
         // Compute the base style
242
+        const borderRadius = size / 2;
229 243
         const style = {
230 244
             ...styles.avatar,
231 245
 
232 246
             // XXX Workaround for Android: for radii < 80 the border radius
233
-            // doesn't work properly, but applying a radius twice as big
234
-            // seems to do the trick.
235
-            borderRadius: size / 2 < 80
236
-                ? Platform.OS === 'android' ? size * 2 : size / 2 : size / 2,
247
+            // doesn't work properly, but applying a radius twice as big seems
248
+            // to do the trick.
249
+            borderRadius:
250
+                Platform.OS === 'android' && borderRadius < 80
251
+                    ? size * 2
252
+                    : borderRadius,
237 253
             height: size,
238 254
             width: size
239 255
         };

+ 12
- 14
react/features/base/participants/components/Avatar.web.js View File

@@ -1,24 +1,22 @@
1
-import PropTypes from 'prop-types';
1
+// @flow
2
+
2 3
 import React, { Component } from 'react';
3 4
 
4 5
 /**
5
- * Implements an avatar as a React/Web {@link Component}.
6
+ * The type of the React {@link Component} props of {@link Avatar}.
6 7
  */
7
-export default class Avatar extends Component {
8
+type Props = {
9
+
8 10
     /**
9
-     * Avatar component's property types.
10
-     *
11
-     * @static
11
+     * The URI of the {@link Avatar}.
12 12
      */
13
-    static propTypes = {
14
-        /**
15
-         * The URI of the {@link Avatar}.
16
-         *
17
-         * @type {string}
18
-         */
19
-        uri: PropTypes.string
20
-    };
13
+    uri: string
14
+};
21 15
 
16
+/**
17
+ * Implements an avatar as a React/Web {@link Component}.
18
+ */
19
+export default class Avatar extends Component<Props> {
22 20
     /**
23 21
      * Implements React's {@link Component#render()}.
24 22
      *

+ 109
- 107
react/features/base/participants/components/ParticipantView.native.js View File

@@ -1,10 +1,9 @@
1
-import PropTypes from 'prop-types';
1
+// @flow
2
+
2 3
 import React, { Component } from 'react';
3 4
 import { Text, View } from 'react-native';
4 5
 import { connect } from 'react-redux';
5 6
 
6
-import { prefetch } from '../../../mobile/image-cache';
7
-
8 7
 import { translate } from '../../i18n';
9 8
 import { JitsiParticipantConnectionStatus } from '../../lib-jitsi-meet';
10 9
 import {
@@ -12,116 +11,117 @@ import {
12 11
     shouldRenderVideoTrack,
13 12
     VideoTrack
14 13
 } from '../../media';
14
+import { prefetch } from '../../../mobile/image-cache';
15 15
 import { Container, TintedView } from '../../react';
16 16
 import { getTrackByMediaTypeAndParticipant } from '../../tracks';
17 17
 
18
+import Avatar from './Avatar';
18 19
 import {
19
-    getAvatarURL, getParticipantById, getParticipantDisplayName
20
+    getAvatarURL,
21
+    getParticipantById,
22
+    getParticipantDisplayName
20 23
 } from '../functions';
21
-
22
-import Avatar from './Avatar';
23 24
 import styles from './styles';
24 25
 
25 26
 /**
26
- * Implements a React Component which depicts a specific participant's avatar
27
- * and video.
28
- *
29
- * @extends Component
27
+ * The type of the React {@link Component} props of {@link ParticipantView}.
30 28
  */
31
-class ParticipantView extends Component {
29
+type Props = {
30
+
32 31
     /**
33
-     * ParticipantView component's property types.
32
+     * The indicator which determines whether conferencing is in audio-only
33
+     * mode.
34 34
      *
35
-     * @static
35
+     * @private
36 36
      */
37
-    static propTypes = {
38
-        /**
39
-         * The indicator which determines whether conferencing is in audio-only
40
-         * mode.
41
-         *
42
-         * @private
43
-         */
44
-        _audioOnly: PropTypes.bool,
45
-
46
-        /**
47
-         * The source (e.g. URI, URL) of the avatar image of the participant
48
-         * with {@link #participantId}.
49
-         *
50
-         * @private
51
-         */
52
-        _avatar: PropTypes.string,
53
-
54
-        /**
55
-         * The connection status of the participant. Her video will only be
56
-         * rendered if the connection status is 'active'; otherwise, the avatar
57
-         * will be rendered. If undefined, 'active' is presumed.
58
-         *
59
-         * @private
60
-         */
61
-        _connectionStatus: PropTypes.string,
62
-
63
-        /**
64
-         * The name of the participant which this component represents.
65
-         *
66
-         * @private
67
-         */
68
-        _participantName: PropTypes.string,
69
-
70
-        /**
71
-         * The video Track of the participant with {@link #participantId}.
72
-         */
73
-        _videoTrack: PropTypes.object,
74
-
75
-        /**
76
-         * The avatar size.
77
-         */
78
-        avatarSize: PropTypes.number,
79
-
80
-        /**
81
-         * The ID of the participant (to be) depicted by ParticipantView.
82
-         *
83
-         * @public
84
-         */
85
-        participantId: PropTypes.string,
86
-
87
-        /**
88
-         * True if the avatar of the depicted participant is to be shown should
89
-         * the avatar be available and the video of the participant is not to be
90
-         * shown; otherwise, false. If undefined, defaults to true.
91
-         */
92
-        showAvatar: PropTypes.bool,
93
-
94
-        /**
95
-         * True if the video of the depicted participant is to be shown should
96
-         * the video be available. If undefined, defaults to true.
97
-         */
98
-        showVideo: PropTypes.bool,
99
-
100
-        /**
101
-         * The style, if any, to apply to ParticipantView in addition to its
102
-         * default style.
103
-         */
104
-        style: PropTypes.object,
105
-
106
-        /**
107
-         * The function to translate human-readable text.
108
-         */
109
-        t: PropTypes.func,
110
-
111
-        /**
112
-         * Indicates if the connectivity info label should be shown, if
113
-         * appropriate. It will be shown in case the connection is interrupted.
114
-         */
115
-        useConnectivityInfoLabel: PropTypes.bool,
116
-
117
-        /**
118
-         * The z-order of the Video of ParticipantView in the stacking space of
119
-         * all Videos. For more details, refer to the zOrder property of the
120
-         * Video class for React Native.
121
-         */
122
-        zOrder: PropTypes.number
123
-    };
37
+    _audioOnly: boolean,
38
+
39
+    /**
40
+     * The source (e.g. URI, URL) of the avatar image of the participant with
41
+     * {@link #participantId}.
42
+     *
43
+     * @private
44
+     */
45
+    _avatar: string,
46
+
47
+    /**
48
+     * The connection status of the participant. Her video will only be rendered
49
+     * if the connection status is 'active'; otherwise, the avatar will be
50
+     * rendered. If undefined, 'active' is presumed.
51
+     *
52
+     * @private
53
+     */
54
+    _connectionStatus: string,
55
+
56
+    /**
57
+     * The name of the participant which this component represents.
58
+     *
59
+     * @private
60
+     */
61
+    _participantName: string,
62
+
63
+    /**
64
+     * The video Track of the participant with {@link #participantId}.
65
+     */
66
+    _videoTrack: Object,
124 67
 
68
+    /**
69
+     * The avatar size.
70
+     */
71
+    avatarSize: number,
72
+
73
+    /**
74
+     * The ID of the participant (to be) depicted by {@link ParticipantView}.
75
+     *
76
+     * @public
77
+     */
78
+    participantId: string,
79
+
80
+    /**
81
+     * True if the avatar of the depicted participant is to be shown should the
82
+     * avatar be available and the video of the participant is not to be shown;
83
+     * otherwise, false. If undefined, defaults to true.
84
+     */
85
+    showAvatar: boolean,
86
+
87
+    /**
88
+     * True if the video of the depicted participant is to be shown should the
89
+     * video be available. If undefined, defaults to true.
90
+     */
91
+    showVideo: boolean,
92
+
93
+    /**
94
+     * The style, if any, to apply to {@link ParticipantView} in addition to its
95
+     * default style.
96
+     */
97
+    style: Object,
98
+
99
+    /**
100
+     * The function to translate human-readable text.
101
+     */
102
+    t: Function,
103
+
104
+    /**
105
+     * Indicates if the connectivity info label should be shown, if appropriate.
106
+     * It will be shown in case the connection is interrupted.
107
+     */
108
+    useConnectivityInfoLabel: boolean,
109
+
110
+    /**
111
+     * The z-order of the {@link Video} of {@link ParticipantView} in the
112
+     * stacking space of all {@code Video}s. For more details, refer to the
113
+     * {@code zOrder} property of the {@code Video} class for React Native.
114
+     */
115
+    zOrder: number
116
+};
117
+
118
+/**
119
+ * Implements a React Component which depicts a specific participant's avatar
120
+ * and video.
121
+ *
122
+ * @extends Component
123
+ */
124
+class ParticipantView extends Component<Props> {
125 125
     /**
126 126
      * Renders the connection status label, if appropriate.
127 127
      *
@@ -150,8 +150,8 @@ class ParticipantView extends Component {
150 150
             t
151 151
         } = this.props;
152 152
 
153
-        // XXX Consider splitting this component into 2: one for the large
154
-        // view and one for the thumbnail. Some of these don't apply to both.
153
+        // XXX Consider splitting this component into 2: one for the large view
154
+        // and one for the thumbnail. Some of these don't apply to both.
155 155
         const containerStyle = {
156 156
             ...styles.connectionInfoContainer,
157 157
             width: avatarSize * 1.5
@@ -261,16 +261,18 @@ function _toBoolean(value, undefinedValue) {
261 261
 }
262 262
 
263 263
 /**
264
- * Maps (parts of) the Redux state to the associated ParticipantView's props.
264
+ * Maps (parts of) the redux state to the associated {@link ParticipantView}'s
265
+ * props.
265 266
  *
266
- * @param {Object} state - The Redux state.
267
- * @param {Object} ownProps - The React Component props passed to the associated
268
- * (instance of) ParticipantView.
267
+ * @param {Object} state - The redux state.
268
+ * @param {Object} ownProps - The React {@code Component} props passed to the
269
+ * associated (instance of) {@code ParticipantView}.
269 270
  * @private
270 271
  * @returns {{
271 272
  *     _audioOnly: boolean,
272 273
  *     _avatar: string,
273 274
  *     _connectionStatus: string,
275
+ *     _participantName: string,
274 276
  *     _videoTrack: Track
275 277
  * }}
276 278
  */
@@ -287,7 +289,7 @@ function _mapStateToProps(state, ownProps) {
287 289
     if (participant) {
288 290
         avatar = getAvatarURL(participant);
289 291
         connectionStatus = participant.connectionStatus;
290
-        participantName = getParticipantDisplayName(state);
292
+        participantName = getParticipantDisplayName(state, participant.id);
291 293
 
292 294
         // Avatar (on React Native) now has the ability to generate an
293 295
         // automatically-colored default image when no URI/URL is specified or

+ 2
- 1
react/features/base/participants/functions.js View File

@@ -160,7 +160,8 @@ export function getParticipantCount(stateful: Object | Function) {
160 160
  * @returns {string}
161 161
  */
162 162
 export function getParticipantDisplayName(
163
-        stateful: Object | Function, id: string) {
163
+        stateful: Object | Function,
164
+        id: string) {
164 165
     const participant = getParticipantById(stateful, id);
165 166
 
166 167
     if (participant) {

+ 1
- 1
react/features/filmstrip/components/Thumbnail.js View File

@@ -18,11 +18,11 @@ import {
18 18
     styles,
19 19
     VideoMutedIndicator
20 20
 } from './_';
21
-
22 21
 import { AVATAR_SIZE } from './styles';
23 22
 
24 23
 /**
25 24
  * React component for video thumbnail.
25
+ *
26 26
  * @extends Component
27 27
  */
28 28
 class Thumbnail extends Component {

+ 11
- 5
react/features/large-video/components/LargeVideo.native.js View File

@@ -8,6 +8,9 @@ import { DimensionsDetector } from '../../base/responsive-ui';
8 8
 
9 9
 import styles, { AVATAR_SIZE } from './styles';
10 10
 
11
+/**
12
+ * The type of the React {@link Component} props of {@link LargeVideo}.
13
+ */
11 14
 type Props = {
12 15
 
13 16
     /**
@@ -18,6 +21,9 @@ type Props = {
18 21
     _participantId: string
19 22
 };
20 23
 
24
+/**
25
+ * The type of the React {@link Component} state of {@link LargeVideo}.
26
+ */
21 27
 type State = {
22 28
 
23 29
     /**
@@ -57,6 +63,7 @@ class LargeVideo extends Component<Props, State> {
57 63
     constructor(props) {
58 64
         super(props);
59 65
 
66
+        // Bind event handlers so they are only bound once per instance.
60 67
         this._onDimensionsChanged = this._onDimensionsChanged.bind(this);
61 68
     }
62 69
 
@@ -75,19 +82,18 @@ class LargeVideo extends Component<Props, State> {
75 82
     _onDimensionsChanged(width: number, height: number) {
76 83
         // Get the size, rounded to the nearest even number.
77 84
         const size = 2 * Math.round(Math.min(height, width) / 2);
78
-
79
-        let newState;
85
+        let nextState;
80 86
 
81 87
         if (size < AVATAR_SIZE * 1.5) {
82
-            newState = {
88
+            nextState = {
83 89
                 avatarSize: size - 15, // Leave some margin.
84 90
                 useConnectivityInfoLabel: false
85 91
             };
86 92
         } else {
87
-            newState = DEFAULT_STATE;
93
+            nextState = DEFAULT_STATE;
88 94
         }
89 95
 
90
-        this.setState(newState);
96
+        this.setState(nextState);
91 97
     }
92 98
 
93 99
     /**

Loading…
Cancel
Save