Skip to content

Commit

Permalink
[RN] Avoid Toolbox changing size on first render
Browse files Browse the repository at this point in the history
Wait until the right button size has been calculated before rendering it.
  • Loading branch information
saghul authored and lyubomir committed May 18, 2018
1 parent 12d7ab9 commit 39e46ba
Showing 1 changed file with 57 additions and 38 deletions.
95 changes: 57 additions & 38 deletions react/features/toolbox/components/native/Toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,62 @@ class Toolbox extends Component<Props, State> {
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 (
<View
pointerEvents = 'box-none'
style = { styles.toolbar }>
<InviteButton styles = { buttonStyles } />
<AudioMuteButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
<HangupButton styles = { hangupButtonStyles } />
<VideoMuteButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
<OverflowMenuButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
</View>
);
}

/**
* Implements React's {@link Component#render()}.
*
Expand All @@ -96,50 +152,13 @@ class Toolbox extends Component<Props, State> {
? 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 (
<Container
onLayout = { this._onLayout }
style = { toolboxStyle }
visible = { _visible }>
<View
pointerEvents = 'box-none'
style = { styles.toolbar }>
<InviteButton styles = { buttonStyles } />
<AudioMuteButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
<HangupButton styles = { hangupButtonStyles } />
<VideoMuteButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
<OverflowMenuButton
styles = { buttonStyles }
toggledStyles = { toggledButtonStyles } />
</View>
{ this._renderToolbar() }
</Container>
);
}
Expand Down

0 comments on commit 39e46ba

Please sign in to comment.