Browse Source

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

master
Leonard Kim 7 years ago
parent
commit
280178f5d1
1 changed files with 24 additions and 34 deletions
  1. 24
    34
      react/features/invite/components/InfoDialogButton.web.js

+ 24
- 34
react/features/invite/components/InfoDialogButton.web.js View File

70
  */
70
  */
71
 type State = {
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
      * Whether or not {@code InfoDialog} should be visible.
80
      * Whether or not {@code InfoDialog} should be visible.
75
      */
81
      */
83
  * @extends Component
89
  * @extends Component
84
  */
90
  */
85
 class InfoDialogButton extends Component<Props, State> {
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
      * Initializes new {@code InfoDialogButton} instance.
110
      * Initializes new {@code InfoDialogButton} instance.
88
      *
111
      *
92
         super(props);
115
         super(props);
93
 
116
 
94
         this.state = {
117
         this.state = {
118
+            hasConnectedToConference: props._isConferenceJoined,
95
             showDialog: false
119
             showDialog: false
96
         };
120
         };
97
 
121
 
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
      * Implements React's {@link Component#render()}.
139
      * Implements React's {@link Component#render()}.
132
      *
140
      *
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
     _onDialogClose: () => void;
170
     _onDialogClose: () => void;
181
 
171
 
182
     /**
172
     /**

Loading…
Cancel
Save