-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[change] ResponderEventPlugin filters browser emulated mouse events
Browsers dispatch mouse events after touch events: https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent There have been several attempts to avoid this behaviour affecting the ResponderEvent system. The previous approach of cancelling the event in the `onResponderRelease` event handler can end up cancelling other events that are expected, e.g., `focus`. Instead, this patch changes the `ResponderEventPlugin.extractEvents` function to filter the mouse events that occur a short time after a touch event. (It's assumed that people will not be clicking a mouse within a few hundred ms of performing a touch.) This allows the ResponderEvent system to function as expected and leaves other callbacks to fire as they would be expected to in React DOM, i.e., both `onTouchStart` and `onMouseDown` will be called following a touch start. Fix #835 Fix #888 Fix #932 Close #938 Ref #802
- Loading branch information
Showing
5 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
website/storybook/1-components/Switch/examples/TouchableWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable react/jsx-no-bind */ | ||
/** | ||
* @flow | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Switch, TouchableHighlight, View } from 'react-native'; | ||
|
||
class TouchableWrapperExample extends React.PureComponent { | ||
state = { | ||
on: false | ||
}; | ||
|
||
render() { | ||
const { on } = this.state; | ||
|
||
return ( | ||
<View> | ||
<TouchableHighlight onPress={() => {}} style={style} underlayColor="#eee"> | ||
<Switch onValueChange={this._handleChange} value={on} /> | ||
</TouchableHighlight> | ||
</View> | ||
); | ||
} | ||
|
||
_handleChange = value => { | ||
this.setState({ on: value }); | ||
}; | ||
} | ||
|
||
const style = { | ||
alignSelf: 'flex-start', | ||
borderWidth: 1, | ||
borderColor: '#ddd', | ||
paddingHorizontal: 50, | ||
paddingVertical: 20 | ||
}; | ||
|
||
export default TouchableWrapperExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters