From 39e46bacf6967895b0e71ada01bcb002fd953094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 18 May 2018 13:42:16 +0200 Subject: [PATCH] [RN] Avoid Toolbox changing size on first render Wait until the right button size has been calculated before rendering it. --- .../toolbox/components/native/Toolbox.js | 95 +++++++++++-------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/react/features/toolbox/components/native/Toolbox.js b/react/features/toolbox/components/native/Toolbox.js index 9616becef..d7dcf523b 100644 --- a/react/features/toolbox/components/native/Toolbox.js +++ b/react/features/toolbox/components/native/Toolbox.js @@ -84,6 +84,62 @@ class Toolbox extends Component { this._onLayout = this._onLayout.bind(this); } + /** + * Renders the toolbar. It will only be rendered if the {@code Toolbox} is + * visible and we have already calculated the available width. This avoids + * a weird effect in which the toolbar is displayed and then changes size. + * + * @returns {ReactElement} + */ + _renderToolbar() { + const { _visible } = this.props; + const { width } = this.state; + + if (!_visible || !width) { + return null; + } + + let buttonStyles = toolbarButtonStyles; + let toggledButtonStyles = toolbarToggledButtonStyles; + + const buttonSize = this._calculateButtonSize(); + + if (buttonSize > 0) { + const extraButtonStyle = { + borderRadius: buttonSize / 2, + height: buttonSize, + width: buttonSize + }; + + buttonStyles = { + ...buttonStyles, + style: [ buttonStyles.style, extraButtonStyle ] + }; + toggledButtonStyles = { + ...toggledButtonStyles, + style: [ toggledButtonStyles.style, extraButtonStyle ] + }; + } + + return ( + + + + + + + + ); + } + /** * Implements React's {@link Component#render()}. * @@ -96,50 +152,13 @@ class Toolbox extends Component { ? styles.toolboxNarrow : styles.toolboxWide; const { _visible } = this.props; - let buttonStyles = toolbarButtonStyles; - let toggledButtonStyles = toolbarToggledButtonStyles; - - if (_visible) { - const buttonSize = this._calculateButtonSize(); - - if (buttonSize > 0) { - const extraButtonStyle = { - borderRadius: buttonSize / 2, - height: buttonSize, - width: buttonSize - }; - - buttonStyles = { - ...buttonStyles, - style: [ buttonStyles.style, extraButtonStyle ] - }; - toggledButtonStyles = { - ...toggledButtonStyles, - style: [ toggledButtonStyles.style, extraButtonStyle ] - }; - } - } return ( - - - - - - - + { this._renderToolbar() } ); }