0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-14 23:42:41 +00:00

Optimize for smooth scrolling of BrewRenderer

The will-change property allows the browser to optimize for smoother animations. This completely eliminates the scrolling stutter.
This commit is contained in:
Trevor Buckner
2018-05-10 12:44:49 -04:00
committed by Rae2che5
parent cbbb7292d9
commit 825c259fba
2 changed files with 56 additions and 34 deletions

View File

@@ -25,6 +25,7 @@ const BrewRenderer = createClass({
return { return {
viewablePageNumber : 0, viewablePageNumber : 0,
height : 0, height : 0,
willChange : 'auto',
isMounted : false, isMounted : false,
usePPR : true, usePPR : true,
@@ -126,11 +127,30 @@ const BrewRenderer = createClass({
return this.lastRender; return this.lastRender;
}, },
/**
* Optimize for smooth scrolling when mouse enters the rendering panel
**/
prepareScroll : function(){
this.setState({willChange : 'transform'});
},
/**
* Unload smooth scrolling optimizations when mouse leaves rendering panel
**/
unprepareScroll : function(){
this.setState({willChange : 'auto'});
},
render : function(){ render : function(){
return <div className='brewRenderer' return (
<React.Fragment>
<div className='brewRenderer'
onScroll={this.handleScroll} onScroll={this.handleScroll}
onMouseOver={this.prepareScroll}
onMouseOut={this.unprepareScroll}
ref='main' ref='main'
style={{ height: this.state.height }}> style={{ height: this.state.height,
willChange: this.state.willChange}}>
<ErrorBar errors={this.props.errors} /> <ErrorBar errors={this.props.errors} />
<RenderWarnings /> <RenderWarnings />
@@ -138,9 +158,11 @@ const BrewRenderer = createClass({
<div className='pages' ref='pages'> <div className='pages' ref='pages'>
{this.renderPages()} {this.renderPages()}
</div> </div>
</div>;
{this.renderPageInfo()} {this.renderPageInfo()}
{this.renderPPRmsg()} {this.renderPPRmsg()}
</div>; </React.Fragment>
);
} }
}); });

View File

@@ -5,28 +5,6 @@
} }
.brewRenderer{ .brewRenderer{
overflow-y : scroll; overflow-y : scroll;
.pageInfo{
position : absolute;
right : 17px;
bottom : 0;
z-index : 1000;
padding : 8px 10px;
background-color : #333;
font-size : 10px;
font-weight : 800;
color : white;
}
.ppr_msg{
position : absolute;
left : 0px;
bottom : 0;
z-index : 1000;
padding : 8px 10px;
background-color : #333;
font-size : 10px;
font-weight : 800;
color : white;
}
.pages{ .pages{
margin : 30px 0px; margin : 30px 0px;
&>.phb{ &>.phb{
@@ -37,3 +15,25 @@
} }
} }
} }
.pageInfo{
position : absolute;
right : 17px;
bottom : 0;
z-index : 1000;
padding : 8px 10px;
background-color : #333;
font-size : 10px;
font-weight : 800;
color : white;
}
.ppr_msg{
position : absolute;
left : 0px;
bottom : 0;
z-index : 1000;
padding : 8px 10px;
background-color : #333;
font-size : 10px;
font-weight : 800;
color : white;
}