Преглед изворни кода

ref(info-dialog): derive when to autoshow or autohide

master
Leonard Kim пре 7 година
родитељ
комит
280178f5d1
1 измењених фајлова са 24 додато и 34 уклоњено
  1. 24
    34
      react/features/invite/components/InfoDialogButton.web.js

+ 24
- 34
react/features/invite/components/InfoDialogButton.web.js Прегледај датотеку

@@ -70,6 +70,12 @@ type Props = {
70 70
  */
71 71
 type State = {
72 72
 
73
+    /**
74
+     * Cache the conference connection state to derive when transitioning from
75
+     * not joined to join, in order to auto-show the InfoDialog.
76
+     */
77
+    hasConnectedToConference: boolean,
78
+
73 79
     /**
74 80
      * Whether or not {@code InfoDialog} should be visible.
75 81
      */
@@ -83,6 +89,23 @@ type State = {
83 89
  * @extends Component
84 90
  */
85 91
 class InfoDialogButton extends Component<Props, State> {
92
+    /**
93
+     * Implements React's {@link Component#getDerivedStateFromProps()}.
94
+     *
95
+     * @inheritdoc
96
+     */
97
+    static getDerivedStateFromProps(props, state) {
98
+        return {
99
+            hasConnectedToConference: props._isConferenceJoined,
100
+            showDialog: (props._toolboxVisible && state.showDialog)
101
+                || (!state.hasConnectedToConference
102
+                    && props._isConferenceJoined
103
+                    && props._participantCount < 2
104
+                    && props._toolboxVisible
105
+                    && !props._disableAutoShow)
106
+        };
107
+    }
108
+
86 109
     /**
87 110
      * Initializes new {@code InfoDialogButton} instance.
88 111
      *
@@ -92,6 +115,7 @@ class InfoDialogButton extends Component<Props, State> {
92 115
         super(props);
93 116
 
94 117
         this.state = {
118
+            hasConnectedToConference: props._isConferenceJoined,
95 119
             showDialog: false
96 120
         };
97 121
 
@@ -111,22 +135,6 @@ class InfoDialogButton extends Component<Props, State> {
111 135
         }
112 136
     }
113 137
 
114
-    /**
115
-     * Update the visibility of the {@code InfoDialog}.
116
-     *
117
-     * @inheritdoc
118
-     */
119
-    componentWillReceiveProps(nextProps) {
120
-        // Ensure the dialog is closed when the toolbox becomes hidden.
121
-        if (this.state.showDialog && !nextProps._toolboxVisible) {
122
-            this._onDialogClose();
123
-
124
-            return;
125
-        }
126
-
127
-        this._maybeAutoShowDialog(nextProps);
128
-    }
129
-
130 138
     /**
131 139
      * Implements React's {@link Component#render()}.
132 140
      *
@@ -159,24 +167,6 @@ class InfoDialogButton extends Component<Props, State> {
159 167
         );
160 168
     }
161 169
 
162
-    /**
163
-     * Invoked to trigger display of the {@code InfoDialog} if certain
164
-     * conditions are met.
165
-     *
166
-     * @param {Object} nextProps - The future properties of this component.
167
-     * @private
168
-     * @returns {void}
169
-     */
170
-    _maybeAutoShowDialog(nextProps) {
171
-        if (!this.props._isConferenceJoined
172
-            && nextProps._isConferenceJoined
173
-            && nextProps._participantCount < 2
174
-            && nextProps._toolboxVisible
175
-            && !nextProps._disableAutoShow) {
176
-            this.setState({ showDialog: true });
177
-        }
178
-    }
179
-
180 170
     _onDialogClose: () => void;
181 171
 
182 172
     /**

Loading…
Откажи
Сачувај