mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08:00
Fix Game2048 on desktop browsers
The React Native example only listens for touch events but on web we can listen to mouse events to improve support. Close #909
This commit is contained in:
committed by
Nicolas Gallagher
parent
f9ebdb6327
commit
38affa9bae
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user