Browse Source

fix(prejoin): Make avatar resizable

j8
Vlad Piersec 4 years ago
parent
commit
4f52a29120

+ 1
- 8
css/_premeeting-screens.scss View File

@@ -197,16 +197,9 @@
197 197
         text-align: center;
198 198
     }
199 199
 
200
-    .preview-avatar-container {
201
-        width: 100%;
202
-        height: 80%;
203
-        display: flex;
204
-        align-items: center;
205
-        justify-content: center;
206
-    }
207
-
208 200
     .avatar {
209 201
         background: #A4B8D1;
202
+        margin: 0 auto;
210 203
     }
211 204
 
212 205
     video {

+ 61
- 0
react/features/base/premeeting/components/web/Avatar.js View File

@@ -0,0 +1,61 @@
1
+// @flow
2
+
3
+import React from 'react';
4
+
5
+import { Avatar } from '../../../avatar';
6
+import { connect } from '../../../redux';
7
+import { calculateAvatarDimensions } from '../../functions';
8
+
9
+type Props = {
10
+
11
+   /**
12
+    * The height of the window.
13
+    */
14
+    height: number,
15
+
16
+   /**
17
+    * The name of the participant (if any).
18
+    */
19
+    name: string
20
+}
21
+
22
+/**
23
+ * Component displaying the avatar for the premeeting screen.
24
+ *
25
+ * @param {Props} props - The props of the component.
26
+ * @returns {ReactElement}
27
+ */
28
+function PremeetingAvatar({ height, name }: Props) {
29
+    const { marginTop, size } = calculateAvatarDimensions(height);
30
+
31
+    if (size <= 5) {
32
+        return null;
33
+    }
34
+
35
+
36
+    return (
37
+        <div style = {{ marginTop }}>
38
+            <Avatar
39
+                className = 'preview-avatar'
40
+                displayName = { name }
41
+                participantId = 'local'
42
+                size = { size } />
43
+        </div>
44
+    );
45
+}
46
+
47
+/**
48
+ * Maps (parts of) the redux state to the React {@code Component} props.
49
+ *
50
+ * @param {Object} state - The redux state.
51
+ * @returns {{
52
+ *    height: number
53
+ * }}
54
+ */
55
+function mapStateToProps(state) {
56
+    return {
57
+        height: state['features/base/responsive-ui'].clientHeight
58
+    };
59
+}
60
+
61
+export default connect(mapStateToProps)(PremeetingAvatar);

+ 3
- 8
react/features/base/premeeting/components/web/Preview.js View File

@@ -2,11 +2,12 @@
2 2
 
3 3
 import React from 'react';
4 4
 
5
-import { Avatar } from '../../../avatar';
6 5
 import { Video } from '../../../media';
7 6
 import { connect } from '../../../redux';
8 7
 import { getLocalVideoTrack } from '../../../tracks';
9 8
 
9
+import PreviewAvatar from './Avatar';
10
+
10 11
 export type Props = {
11 12
 
12 13
     /**
@@ -54,13 +55,7 @@ function Preview(props: Props) {
54 55
             <div
55 56
                 className = 'no-video'
56 57
                 id = 'preview'>
57
-                <div className = 'preview-avatar-container'>
58
-                    <Avatar
59
-                        className = 'preview-avatar'
60
-                        displayName = { name }
61
-                        participantId = 'local'
62
-                        size = { 200 } />
63
-                </div>
58
+                <PreviewAvatar name = { name } />
64 59
             </div>
65 60
         );
66 61
     }

+ 72
- 1
react/features/base/premeeting/functions.js View File

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import { findIndex } from 'lodash';
2 4
 
3 5
 import { CONNECTION_TYPE } from './constants';
@@ -8,6 +10,75 @@ const LOSS_VIDEO_THRESHOLDS = [ 0.33, 0.1, 0.05 ];
8 10
 const THROUGHPUT_AUDIO_THRESHOLDS = [ 8, 20 ];
9 11
 const THROUGHPUT_VIDEO_THRESHOLDS = [ 60, 750 ];
10 12
 
13
+/**
14
+ * The avatar size to container size ration.
15
+ */
16
+const ratio = 1 / 3;
17
+
18
+/**
19
+ * The max avatar size.
20
+ */
21
+const maxSize = 190;
22
+
23
+/**
24
+ * The window limit hight over which the avatar should have the default dimension.
25
+ */
26
+const upperHeightLimit = 760;
27
+
28
+/**
29
+ * The window limit hight under which the avatar should not be resized anymore.
30
+ */
31
+const lowerHeightLimit = 460;
32
+
33
+/**
34
+ * The default top margin of the avatar.
35
+ */
36
+const defaultMarginTop = '10%';
37
+
38
+/**
39
+ * The top margin of the avatar when its dimension is small.
40
+ */
41
+const smallMarginTop = '5%';
42
+
43
+/**
44
+ * Calculates avatar dimensions based on window height and position.
45
+ *
46
+ * @param {number} height - The window height.
47
+ * @returns {{
48
+ *   marginTop: string,
49
+ *   size: number
50
+ * }}
51
+ */
52
+export function calculateAvatarDimensions(height: number) {
53
+    if (height > upperHeightLimit) {
54
+        return {
55
+            size: maxSize,
56
+            marginTop: defaultMarginTop
57
+        };
58
+    }
59
+
60
+    if (height > lowerHeightLimit) {
61
+        const diff = height - lowerHeightLimit;
62
+        const percent = diff * ratio;
63
+        const size = Math.floor(maxSize * percent / 100);
64
+        let marginTop = defaultMarginTop;
65
+
66
+        if (height < 600) {
67
+            marginTop = smallMarginTop;
68
+        }
69
+
70
+        return {
71
+            size,
72
+            marginTop
73
+        };
74
+    }
75
+
76
+    return {
77
+        size: 0,
78
+        marginTop: '0'
79
+    };
80
+}
81
+
11 82
 /**
12 83
  * Returns the level based on a list of thresholds.
13 84
  *
@@ -121,7 +192,7 @@ function _getConnectionDataFromTestResults({ fractionalLoss: l, throughput: t })
121 192
  *   connectionDetails: string[]
122 193
  * }}
123 194
  */
124
-export function getConnectionData(state) {
195
+export function getConnectionData(state: Object) {
125 196
     const { precallTestResults } = state['features/prejoin'];
126 197
 
127 198
     if (precallTestResults) {

Loading…
Cancel
Save