mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-05 11:19:34 +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) {
|
touchableHandleResponderRelease: function(e) {
|
||||||
this._receiveSignal(Signals.RESPONDER_RELEASE, 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) => {
|
eventHandlerNames.reduce((props, handlerName) => {
|
||||||
const handler = this.props[handlerName];
|
const handler = this.props[handlerName];
|
||||||
if (typeof handler === 'function') {
|
if (typeof handler === 'function') {
|
||||||
props[handlerName] = this._normalizeEventForHandler(handler, handlerName);
|
props[handlerName] = this._normalizeEventForHandler(handler);
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}, otherProps);
|
}, otherProps);
|
||||||
@@ -127,20 +127,10 @@ class View extends Component {
|
|||||||
return createDOMElement(component, otherProps);
|
return createDOMElement(component, otherProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
_normalizeEventForHandler(handler, handlerName) {
|
_normalizeEventForHandler(handler) {
|
||||||
// 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';
|
|
||||||
|
|
||||||
return (e) => {
|
return (e) => {
|
||||||
e.nativeEvent = normalizeNativeEvent(e.nativeEvent);
|
e.nativeEvent = normalizeNativeEvent(e.nativeEvent);
|
||||||
const returnValue = handler(e);
|
return handler(e);
|
||||||
if (shouldCancelEvent && e.cancelable) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
return returnValue;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user