From 2b39bc9c96201b83526694b90b1938e57831fd1b Mon Sep 17 00:00:00 2001 From: Pete Miller Date: Wed, 11 Oct 2017 13:26:48 -0700 Subject: [PATCH] Do not re-create stylesheet rules every time tabs are rendered Helps with performance, instead use css variables to pass js variables to css. Fix #11465 --- .../components/tabs/content/favIcon.js | 64 ++++++++++++------- .../components/tabs/content/tabIcon.js | 36 +++++++---- app/renderer/components/tabs/tab.js | 30 +++++---- 3 files changed, 80 insertions(+), 50 deletions(-) diff --git a/app/renderer/components/tabs/content/favIcon.js b/app/renderer/components/tabs/content/favIcon.js index 2114cf55a86..73967684745 100644 --- a/app/renderer/components/tabs/content/favIcon.js +++ b/app/renderer/components/tabs/content/favIcon.js @@ -52,45 +52,40 @@ class Favicon extends React.Component { return null } - const iconStyles = StyleSheet.create({ - icon__loading_color: { - filter: this.props.tabIconColor === 'white' - ? filter.makeWhite - : 'none' - }, - icon__favicon: { - backgroundImage: `url(${this.props.favicon})`, - filter: this.props.tabIconColor === 'white' - ? filter.whiteShadow - : 'none' - }, - icon__default_sizeAndColor: { - WebkitMaskSize: this.props.showIconAtReducedSize ? '10px' : '12px', - backgroundColor: this.props.tabIconColor === 'white' - ? color.white100 - : color.mediumGray - } - }) + const themeLight = this.props.tabIconColor === 'white' + const instanceStyles = { } + if (this.props.favicon) { + instanceStyles['--faviconsrc'] = `url(${this.props.favicon})` + } return } @@ -119,6 +114,14 @@ const styles = StyleSheet.create({ alignSelf: 'center' }, + icon_favicon: { + backgroundImage: 'var(--faviconsrc)' + }, + + icon_faviconLight: { + filter: filter.whiteShadow + }, + icon_lessMargin: { margin: 0 }, @@ -143,9 +146,22 @@ const styles = StyleSheet.create({ animationIterationCount: 'infinite' }, - icon__default: { + icon__loading_colorLight: { + filter: filter.makeWhite + }, + + icon__defaultIcon: { WebkitMaskRepeat: 'no-repeat', WebkitMaskPosition: 'center', - WebkitMaskImage: `url(${defaultIconSvg})` + WebkitMaskImage: `url(${defaultIconSvg})`, + WebkitMaskSize: '12px', + backgroundColor: color.mediumGray + }, + + icon__defaultIcon_reducedSize: { + WebkitMaskSize: '10px' + }, + icon__defaultIcon_colorLight: { + backgroundColor: color.white100 } }) diff --git a/app/renderer/components/tabs/content/tabIcon.js b/app/renderer/components/tabs/content/tabIcon.js index 004df67ef14..1e4d908aa18 100644 --- a/app/renderer/components/tabs/content/tabIcon.js +++ b/app/renderer/components/tabs/content/tabIcon.js @@ -16,19 +16,6 @@ const globalStyles = require('../../styles/global') class TabIcon extends ImmutableComponent { render () { - const styles = StyleSheet.create({ - tabIcon: { - fontSize: this.props.symbolContent ? '8px' : 'inherit', - display: 'flex', - width: globalStyles.spacing.iconSize, - height: globalStyles.spacing.iconSize, - alignItems: 'center', - justifyContent: this.props.symbolContent ? 'flex-end' : 'center', - fontWeight: this.props.symbolContent ? 'bold' : 'normal', - color: this.props.symbolContent ? globalStyles.color.black100 : 'inherit' - } - }) - let altProps if (!this.props.symbol) { altProps = { @@ -43,6 +30,7 @@ class TabIcon extends ImmutableComponent { onDragStart={this.props.onDragStart} draggable={this.props.draggable} onClick={this.props.onClick} + style={this.props.style} {...altProps} > { @@ -50,7 +38,7 @@ class TabIcon extends ImmutableComponent { ?