From 280178f5d19df9e070f3bed7669dd51e2898ce39 Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Sun, 28 Oct 2018 19:10:55 -0700 Subject: [PATCH] ref(info-dialog): derive when to autoshow or autohide --- .../invite/components/InfoDialogButton.web.js | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/react/features/invite/components/InfoDialogButton.web.js b/react/features/invite/components/InfoDialogButton.web.js index 06e2cccb0..916232b05 100644 --- a/react/features/invite/components/InfoDialogButton.web.js +++ b/react/features/invite/components/InfoDialogButton.web.js @@ -70,6 +70,12 @@ type Props = { */ type State = { + /** + * Cache the conference connection state to derive when transitioning from + * not joined to join, in order to auto-show the InfoDialog. + */ + hasConnectedToConference: boolean, + /** * Whether or not {@code InfoDialog} should be visible. */ @@ -83,6 +89,23 @@ type State = { * @extends Component */ class InfoDialogButton extends Component { + /** + * Implements React's {@link Component#getDerivedStateFromProps()}. + * + * @inheritdoc + */ + static getDerivedStateFromProps(props, state) { + return { + hasConnectedToConference: props._isConferenceJoined, + showDialog: (props._toolboxVisible && state.showDialog) + || (!state.hasConnectedToConference + && props._isConferenceJoined + && props._participantCount < 2 + && props._toolboxVisible + && !props._disableAutoShow) + }; + } + /** * Initializes new {@code InfoDialogButton} instance. * @@ -92,6 +115,7 @@ class InfoDialogButton extends Component { super(props); this.state = { + hasConnectedToConference: props._isConferenceJoined, showDialog: false }; @@ -111,22 +135,6 @@ class InfoDialogButton extends Component { } } - /** - * Update the visibility of the {@code InfoDialog}. - * - * @inheritdoc - */ - componentWillReceiveProps(nextProps) { - // Ensure the dialog is closed when the toolbox becomes hidden. - if (this.state.showDialog && !nextProps._toolboxVisible) { - this._onDialogClose(); - - return; - } - - this._maybeAutoShowDialog(nextProps); - } - /** * Implements React's {@link Component#render()}. * @@ -159,24 +167,6 @@ class InfoDialogButton extends Component { ); } - /** - * Invoked to trigger display of the {@code InfoDialog} if certain - * conditions are met. - * - * @param {Object} nextProps - The future properties of this component. - * @private - * @returns {void} - */ - _maybeAutoShowDialog(nextProps) { - if (!this.props._isConferenceJoined - && nextProps._isConferenceJoined - && nextProps._participantCount < 2 - && nextProps._toolboxVisible - && !nextProps._disableAutoShow) { - this.setState({ showDialog: true }); - } - } - _onDialogClose: () => void; /**