mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 22:32:41 +00:00
Fix calculation of currently-viewed page.
Previously, this relied on a hard-coded constant determining the height of a page. However, that's unnecessary -- we know the scroll height of the window and the number of pages, so we can compute it.
This commit is contained in:
@@ -36,7 +36,6 @@ const BrewRenderer = createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
height : 0,
|
height : 0,
|
||||||
pageHeight : PAGE_HEIGHT,
|
|
||||||
lastRender : <div></div>,
|
lastRender : <div></div>,
|
||||||
|
|
||||||
componentDidMount : function() {
|
componentDidMount : function() {
|
||||||
@@ -48,8 +47,6 @@ const BrewRenderer = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentWillReceiveProps : function(nextProps) {
|
componentWillReceiveProps : function(nextProps) {
|
||||||
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
|
||||||
|
|
||||||
const pages = nextProps.text.split('\\page');
|
const pages = nextProps.text.split('\\page');
|
||||||
this.setState({
|
this.setState({
|
||||||
pages : pages,
|
pages : pages,
|
||||||
@@ -58,10 +55,6 @@ const BrewRenderer = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateSize : function() {
|
updateSize : function() {
|
||||||
setTimeout(()=>{
|
|
||||||
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
height : this.refs.main.parentNode.clientHeight,
|
height : this.refs.main.parentNode.clientHeight,
|
||||||
isMounted : true
|
isMounted : true
|
||||||
@@ -70,7 +63,7 @@ const BrewRenderer = createClass({
|
|||||||
|
|
||||||
handleScroll : function(e){
|
handleScroll : function(e){
|
||||||
this.setState({
|
this.setState({
|
||||||
viewablePageNumber : Math.floor(e.target.scrollTop / this.pageHeight)
|
viewablePageNumber : Math.floor(e.target.scrollTop / e.target.scrollHeight * this.state.pages.length)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user