React (Native) optimizations/performance

Remove toolbar button and icon style literals from the render method of
Toolbox.native.js.

Additionally, comply w/ coding style.
This commit is contained in:
Lyubo Marinov 2017-04-11 12:00:41 -05:00
parent 849f93375c
commit 1ec06f4bf0
2 changed files with 113 additions and 98 deletions

View File

@ -120,18 +120,16 @@ class Toolbox extends Component {
_getMuteButtonStyles(mediaType) { _getMuteButtonStyles(mediaType) {
let iconName; let iconName;
let iconStyle; let iconStyle;
let style = styles.primaryToolbarButton; let style;
if (this.props[`_${mediaType}Muted`]) { if (this.props[`_${mediaType}Muted`]) {
iconName = this[`${mediaType}MutedIcon`]; iconName = this[`${mediaType}MutedIcon`];
iconStyle = styles.whiteIcon; iconStyle = styles.whitePrimaryToolbarButtonIcon;
style = { style = styles.whitePrimaryToolbarButton;
...style,
backgroundColor: ColorPalette.buttonUnderlay
};
} else { } else {
iconName = this[`${mediaType}Icon`]; iconName = this[`${mediaType}Icon`];
iconStyle = styles.icon; iconStyle = styles.primaryToolbarButtonIcon;
style = styles.primaryToolbarButton;
} }
return { return {
@ -163,12 +161,9 @@ class Toolbox extends Component {
style = { audioButtonStyles.style } /> style = { audioButtonStyles.style } />
<ToolbarButton <ToolbarButton
iconName = 'hangup' iconName = 'hangup'
iconStyle = { styles.whiteIcon } iconStyle = { styles.whitePrimaryToolbarButtonIcon }
onClick = { this.props._onHangup } onClick = { this.props._onHangup }
style = {{ style = { styles.hangup }
...styles.primaryToolbarButton,
backgroundColor: ColorPalette.red
}}
underlayColor = { ColorPalette.buttonUnderlay } /> underlayColor = { ColorPalette.buttonUnderlay } />
<ToolbarButton <ToolbarButton
iconName = { videoButtonStyles.iconName } iconName = { videoButtonStyles.iconName }
@ -189,7 +184,7 @@ class Toolbox extends Component {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
_renderSecondaryToolbar() { _renderSecondaryToolbar() {
const iconStyle = styles.secondaryToolbarIcon; const iconStyle = styles.secondaryToolbarButtonIcon;
const style = styles.secondaryToolbarButton; const style = styles.secondaryToolbarButton;
const underlayColor = 'transparent'; const underlayColor = 'transparent';
@ -213,7 +208,7 @@ class Toolbox extends Component {
underlayColor = { underlayColor } /> underlayColor = { underlayColor } />
<ToolbarButton <ToolbarButton
iconName = 'hangup' iconName = 'hangup'
iconStyle = { styles.audioOnlyIcon } iconStyle = { styles.toggleAudioOnlyIcon }
onClick = { this.props._onToggleAudioOnly } onClick = { this.props._onToggleAudioOnly }
style = { style } style = { style }
underlayColor = { underlayColor } /> underlayColor = { underlayColor } />

View File

@ -1,92 +1,91 @@
import { BoxModel, ColorPalette, createStyleSheet } from '../../base/styles'; import { BoxModel, ColorPalette, createStyleSheet } from '../../base/styles';
/**
* The base style for (toolbar) buttons.
*
* @type {Object}
*/
const button = {
borderRadius: 30,
borderWidth: 0,
flex: 0,
flexDirection: 'row',
height: 60,
justifyContent: 'center',
margin: BoxModel.margin,
width: 60
};
/**
* Small toolbar button.
*
* @type {{borderRadius: number, flex: number, flexDirection: string,
* height: number, justifyContent: string, margin: number, width: number}}
*/
const smallButton = {
borderRadius: 20,
flex: 0,
flexDirection: 'column',
height: 40,
justifyContent: 'center',
margin: BoxModel.margin / 2,
width: 40
};
/**
* The base style for icons.
*
* @type {Object}
*/
const icon = {
alignSelf: 'center',
color: ColorPalette.darkGrey,
fontSize: 24
};
/**
* Small toolbar button icon.
*
* @type {{fontSize: number}}
*/
const smallIcon = {
...icon,
fontSize: 18
};
/** /**
* The base style for toolbars. * The base style for toolbars.
* *
* @type {Object} * @type {Object}
*/ */
const toolbar = { const _toolbar = {
flex: 1, flex: 1,
position: 'absolute' position: 'absolute'
}; };
/**
* The base style of toolbar buttons (in primaryToolbar and secondaryToolbar).
*
* @type {Object}
*/
const _toolbarButton = {
flex: 0,
justifyContent: 'center',
opacity: 0.7
};
/**
* The base icon style of toolbar buttons (in primaryToolbar and
* secondaryToolbar).
*
* @type {Object}
*/
const _toolbarButtonIcon = {
alignSelf: 'center'
};
/**
* The style of toolbar buttons in primaryToolbar.
*/
const primaryToolbarButton = {
..._toolbarButton,
backgroundColor: ColorPalette.white,
borderRadius: 30,
borderWidth: 0,
flexDirection: 'row',
height: 60,
margin: BoxModel.margin,
width: 60
};
/**
* The icon style of the toolbar buttons in primaryToolbar.
*
* @type {Object}
*/
const primaryToolbarButtonIcon = {
..._toolbarButtonIcon,
color: ColorPalette.darkGrey,
fontSize: 24
};
/**
* The icon style of the toolbar buttons in secondaryToolbar.
*
* @type {Object}
*/
const secondaryToolbarButtonIcon = {
..._toolbarButtonIcon,
color: ColorPalette.white,
fontSize: 18
};
/** /**
* The (conference) Toolbox/Toolbar related styles. * The (conference) Toolbox/Toolbar related styles.
*/ */
export const styles = createStyleSheet({ export const styles = createStyleSheet({
/** /**
* The audio only (secondary) toolbar icon style. * The style of the toolbar button in {@link #primaryToolbar} which
* hangs the current conference up.
*/ */
audioOnlyIcon: { hangup: {
...smallIcon, ...primaryToolbarButton,
color: ColorPalette.white, backgroundColor: ColorPalette.red
transform: [ { rotate: '135deg' } ]
}, },
/**
* The toolbar button icon style.
*/
icon,
/** /**
* The style of the toolbar which contains the primary buttons such as * The style of the toolbar which contains the primary buttons such as
* hangup, audio and video mute. * hangup, audio and video mute.
*/ */
primaryToolbar: { primaryToolbar: {
...toolbar, ..._toolbar,
bottom: 3 * BoxModel.margin, bottom: 3 * BoxModel.margin,
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
@ -95,20 +94,21 @@ export const styles = createStyleSheet({
}, },
/** /**
* The style of button in primaryToolbar. * The style of toolbar buttons in {@link #primaryToolbar}.
*/ */
primaryToolbarButton: { primaryToolbarButton,
...button,
backgroundColor: ColorPalette.white, /**
opacity: 0.7 * The icon style of the toolbar buttons in {@link #primaryToolbar}.
}, */
primaryToolbarButtonIcon,
/** /**
* The style of the toolbar which contains the secondary buttons such as * The style of the toolbar which contains the secondary buttons such as
* toggle camera facing mode. * toggle camera facing mode.
*/ */
secondaryToolbar: { secondaryToolbar: {
...toolbar, ..._toolbar,
bottom: 0, bottom: 0,
flexDirection: 'column', flexDirection: 'column',
right: BoxModel.margin, right: BoxModel.margin,
@ -116,25 +116,35 @@ export const styles = createStyleSheet({
}, },
/** /**
* The style of button in secondaryToolbar. * The style of toolbar buttons in {@link #secondaryToolbar}.
*/ */
secondaryToolbarButton: { secondaryToolbarButton: {
...smallButton, ..._toolbarButton,
backgroundColor: ColorPalette.darkGrey, backgroundColor: ColorPalette.darkGrey,
opacity: 0.7 borderRadius: 20,
flexDirection: 'column',
height: 40,
margin: BoxModel.margin / 2,
width: 40
}, },
/** /**
* The secondary toolbar icon style. * The icon style of the toolbar buttons in {@link #secondaryToolbar}.
*/ */
secondaryToolbarIcon: { secondaryToolbarButtonIcon,
...smallIcon,
color: ColorPalette.white /**
* The icon style of the toolbar button in {@link #secondaryToolbar} which
* toggles the audio-only mode of the current conference.
*/
toggleAudioOnlyIcon: {
...secondaryToolbarButtonIcon,
transform: [ { rotate: '135deg' } ]
}, },
/** /**
* The style of the root/top-level Container of Toolbar that contains * The style of the root/top-level {@link Container} of {@link Toolbox}
* toolbars. * which contains {@link Toolbar}s.
*/ */
toolbarContainer: { toolbarContainer: {
bottom: 0, bottom: 0,
@ -145,10 +155,20 @@ export const styles = createStyleSheet({
}, },
/** /**
* The toolbar white button icon style. * The style of toolbar buttons in {@link #primaryToolbar} which display
* white icons.
*/ */
whiteIcon: { whitePrimaryToolbarButton: {
...icon, ...primaryToolbarButton,
backgroundColor: ColorPalette.buttonUnderlay
},
/**
* The icon style of toolbar buttons in {@link #primaryToolbar} which
* display white icons.
*/
whitePrimaryToolbarButtonIcon: {
...primaryToolbarButtonIcon,
color: ColorPalette.white color: ColorPalette.white
} }
}); });