Skip to content

Commit

Permalink
Fix #559, but don't break GameChooserDrawer
Browse files Browse the repository at this point in the history
  • Loading branch information
yishn committed Apr 27, 2019
1 parent 481d2c2 commit 47232df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/components/drawers/GameChooserDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ class GameChooserDrawer extends Component {
return animation !== this.state.animation || show || show !== this.props.show
}

componentDidUpdate(prevProps, prevState) {
if (this.state.scrollTop !== prevState.scrollTop
&& this.state.scrollTop !== this.gamesListElement.scrollTop) {
async componentDidUpdate(prevProps, prevState) {
if (
this.state.scrollTop !== prevState.scrollTop
&& this.state.scrollTop !== this.gamesListElement.scrollTop
) {
// Update scroll top

this.gamesListElement.scrollTop = this.state.scrollTop
Expand All @@ -304,6 +306,8 @@ class GameChooserDrawer extends Component {
if (!prevProps.show && this.props.show) {
// Scroll current list element into view

await this.resize()

let index = this.shownGameTrees.findIndex(([, i]) => i === this.props.gameIndex)
let scrollTop = 0
if (index >= 0) scrollTop = this.getRowFromIndex(index) * itemHeight
Expand Down Expand Up @@ -339,12 +343,14 @@ class GameChooserDrawer extends Component {
}
}

resize() {
async resize() {
let innerWidth = this.gamesListElement.offsetWidth - 28
let height = this.gamesListElement.offsetHeight
let rowCount = Math.floor(innerWidth / itemMinWidth)

this.setState({innerWidth, height, rowCount})
return new Promise(resolve => {
this.setState({innerWidth, height, rowCount}, resolve)
})
}

getRowFromIndex(i) {
Expand Down
2 changes: 1 addition & 1 deletion style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ header, #bar .bar {
z-index: 15;
}
.drawer.hidecontent > * {
visibility: hidden;
display: none;
}
.drawer.show {
transform: translateY(-285px);
Expand Down

0 comments on commit 47232df

Please sign in to comment.