mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-23 06:48:35 +00:00
[change] Move 'onResponderRelease' cancel to 'Touchable'
Moves a fix for double-firing Touchables into 'Touchable'
This commit is contained in:
@@ -404,6 +404,13 @@ var TouchableMixin = {
|
||||
*/
|
||||
touchableHandleResponderRelease: function(e) {
|
||||
this._receiveSignal(Signals.RESPONDER_RELEASE, e);
|
||||
// Browsers fire mouse events after touch events. This causes the
|
||||
// 'onResponderRelease' handler to be called twice for Touchables.
|
||||
// Auto-fix this issue by calling 'preventDefault' to cancel the mouse
|
||||
// events.
|
||||
if (e.cancelable && !e.isDefaultPrevented()) {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,7 +112,7 @@ class View extends Component {
|
||||
eventHandlerNames.reduce((props, handlerName) => {
|
||||
const handler = this.props[handlerName];
|
||||
if (typeof handler === 'function') {
|
||||
props[handlerName] = this._normalizeEventForHandler(handler, handlerName);
|
||||
props[handlerName] = this._normalizeEventForHandler(handler);
|
||||
}
|
||||
return props;
|
||||
}, otherProps);
|
||||
@@ -127,20 +127,10 @@ class View extends Component {
|
||||
return createDOMElement(component, otherProps);
|
||||
}
|
||||
|
||||
_normalizeEventForHandler(handler, handlerName) {
|
||||
// Browsers fire mouse events after touch events. This causes the
|
||||
// 'onResponderRelease' handler to be called twice for Touchables.
|
||||
// Auto-fix this issue by calling 'preventDefault' to cancel the mouse
|
||||
// events.
|
||||
const shouldCancelEvent = handlerName === 'onResponderRelease';
|
||||
|
||||
_normalizeEventForHandler(handler) {
|
||||
return (e) => {
|
||||
e.nativeEvent = normalizeNativeEvent(e.nativeEvent);
|
||||
const returnValue = handler(e);
|
||||
if (shouldCancelEvent && e.cancelable) {
|
||||
e.preventDefault();
|
||||
}
|
||||
return returnValue;
|
||||
return handler(e);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user