Skip to content

Commit

Permalink
Fix 2048 on desktop browsers
Browse files Browse the repository at this point in the history
One thing I found out while working on necolas#908 this is that the 2048 game
demo does not work on browsers since it listens for touch events only.
This can be solved by listening to both mouse and touch events.
  • Loading branch information
philipp-spiess committed Apr 21, 2018
1 parent 83a8758 commit 9919e08
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions website/storybook/3-demos/Game2048/Game2048.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Game2048 extends React.Component {
this.setState({ board: new GameBoard() });
};

_handleTouchStart = (event: Object) => {
_handleStart = (event: Object) => {
if (this.state.board.hasWon()) {
return;
}
Expand All @@ -193,7 +193,7 @@ class Game2048 extends React.Component {
this.startY = event.nativeEvent.pageY;
};

_handleTouchEnd = (event: Object) => {
_handleEnd = (event: Object) => {
if (this.state.board.hasWon()) {
return;
}
Expand All @@ -220,8 +220,10 @@ class Game2048 extends React.Component {

return (
<View
onTouchEnd={this._handleTouchEnd}
onTouchStart={this._handleTouchStart}
onMouseDown={this._handleStart}
onMouseUp={this._handleEnd}
onTouchEnd={this._handleEnd}
onTouchStart={this._handleStart}
style={styles.container}
>
<Board>{tiles}</Board>
Expand Down

0 comments on commit 9919e08

Please sign in to comment.