[FIX] Web touch: Prevent ButtonProps.onPressIn to trigger twice (#1091)

* prevent onMouseDown to trigger after onTouchStart

* fix regression where onPress is not triggered

* fix regression where onPress is triggered while cursor is outside
This commit is contained in:
Daniel Neveux 2019-07-15 01:32:21 +02:00 коммит произвёл Eric Traut
Родитель 618572ebbe
Коммит 58164cec8f
1 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -267,8 +267,7 @@ export class Button extends ButtonBase {
* 2- Long press > leave button > release touch
* 3- Tap
*
* Case where onPressOut is not triggered and the bubbling is NOT canceled:
* 4- Press in > leave button > release touch
* All other cases: onPressOut is not triggered and the bubbling is NOT canceled:
*/
private _onTouchEnd = (e: Types.SyntheticEvent | Types.TouchEvent) => {
if (this._isMouseOver && this._ignoreTouchEnd) {
@ -280,14 +279,21 @@ export class Button extends ButtonBase {
/* 3 */
this._isMouseOver && !this._ignoreTouchEnd
) {
if ('touches' in e) {
// Stop the to event sequence to prevent trigger button.onMouseDown
e.preventDefault();
if (this.props.onPress) {
this.props.onPress(e);
}
}
if (this.props.onPressOut) {
this.props.onPressOut(e);
}
} else {
/* 4 */
this._ignoreTouchEnd = false;
}
this._ignoreTouchEnd = false;
if (this._longPressTimer) {
Timers.clearTimeout(this._longPressTimer);
}