瀏覽代碼

[RN] Avoid Toolbox changing size on first render

Wait until the right button size has been calculated before rendering it.
master
Saúl Ibarra Corretgé 7 年之前
父節點
當前提交
39e46bacf6
共有 1 個檔案被更改,包括 57 行新增38 行删除
  1. 57
    38
      react/features/toolbox/components/native/Toolbox.js

+ 57
- 38
react/features/toolbox/components/native/Toolbox.js 查看文件

84
         this._onLayout = this._onLayout.bind(this);
84
         this._onLayout = this._onLayout.bind(this);
85
     }
85
     }
86
 
86
 
87
+    /**
88
+     * Renders the toolbar. It will only be rendered if the {@code Toolbox} is
89
+     * visible and we have already calculated the available width. This avoids
90
+     * a weird effect in which the toolbar is displayed and then changes size.
91
+     *
92
+     * @returns {ReactElement}
93
+     */
94
+    _renderToolbar() {
95
+        const { _visible } = this.props;
96
+        const { width } = this.state;
97
+
98
+        if (!_visible || !width) {
99
+            return null;
100
+        }
101
+
102
+        let buttonStyles = toolbarButtonStyles;
103
+        let toggledButtonStyles = toolbarToggledButtonStyles;
104
+
105
+        const buttonSize = this._calculateButtonSize();
106
+
107
+        if (buttonSize > 0) {
108
+            const extraButtonStyle = {
109
+                borderRadius: buttonSize / 2,
110
+                height: buttonSize,
111
+                width: buttonSize
112
+            };
113
+
114
+            buttonStyles = {
115
+                ...buttonStyles,
116
+                style: [ buttonStyles.style, extraButtonStyle ]
117
+            };
118
+            toggledButtonStyles = {
119
+                ...toggledButtonStyles,
120
+                style: [ toggledButtonStyles.style, extraButtonStyle ]
121
+            };
122
+        }
123
+
124
+        return (
125
+            <View
126
+                pointerEvents = 'box-none'
127
+                style = { styles.toolbar }>
128
+                <InviteButton styles = { buttonStyles } />
129
+                <AudioMuteButton
130
+                    styles = { buttonStyles }
131
+                    toggledStyles = { toggledButtonStyles } />
132
+                <HangupButton styles = { hangupButtonStyles } />
133
+                <VideoMuteButton
134
+                    styles = { buttonStyles }
135
+                    toggledStyles = { toggledButtonStyles } />
136
+                <OverflowMenuButton
137
+                    styles = { buttonStyles }
138
+                    toggledStyles = { toggledButtonStyles } />
139
+            </View>
140
+        );
141
+    }
142
+
87
     /**
143
     /**
88
      * Implements React's {@link Component#render()}.
144
      * Implements React's {@link Component#render()}.
89
      *
145
      *
96
                 ? styles.toolboxNarrow
152
                 ? styles.toolboxNarrow
97
                 : styles.toolboxWide;
153
                 : styles.toolboxWide;
98
         const { _visible } = this.props;
154
         const { _visible } = this.props;
99
-        let buttonStyles = toolbarButtonStyles;
100
-        let toggledButtonStyles = toolbarToggledButtonStyles;
101
-
102
-        if (_visible) {
103
-            const buttonSize = this._calculateButtonSize();
104
-
105
-            if (buttonSize > 0) {
106
-                const extraButtonStyle = {
107
-                    borderRadius: buttonSize / 2,
108
-                    height: buttonSize,
109
-                    width: buttonSize
110
-                };
111
-
112
-                buttonStyles = {
113
-                    ...buttonStyles,
114
-                    style: [ buttonStyles.style, extraButtonStyle ]
115
-                };
116
-                toggledButtonStyles = {
117
-                    ...toggledButtonStyles,
118
-                    style: [ toggledButtonStyles.style, extraButtonStyle ]
119
-                };
120
-            }
121
-        }
122
 
155
 
123
         return (
156
         return (
124
             <Container
157
             <Container
125
                 onLayout = { this._onLayout }
158
                 onLayout = { this._onLayout }
126
                 style = { toolboxStyle }
159
                 style = { toolboxStyle }
127
                 visible = { _visible }>
160
                 visible = { _visible }>
128
-                <View
129
-                    pointerEvents = 'box-none'
130
-                    style = { styles.toolbar }>
131
-                    <InviteButton styles = { buttonStyles } />
132
-                    <AudioMuteButton
133
-                        styles = { buttonStyles }
134
-                        toggledStyles = { toggledButtonStyles } />
135
-                    <HangupButton styles = { hangupButtonStyles } />
136
-                    <VideoMuteButton
137
-                        styles = { buttonStyles }
138
-                        toggledStyles = { toggledButtonStyles } />
139
-                    <OverflowMenuButton
140
-                        styles = { buttonStyles }
141
-                        toggledStyles = { toggledButtonStyles } />
142
-                </View>
161
+                { this._renderToolbar() }
143
             </Container>
162
             </Container>
144
         );
163
         );
145
     }
164
     }

Loading…
取消
儲存