Skip to content

Commit

Permalink
Spin: fix for stop scroll on swipe
Browse files Browse the repository at this point in the history
[Issue] #1168
[Problem] Spin / DateTimePicker stop scroll on long swipe
[Solution]
 - has been added timeout on case of drag outside screen
 - added timeout for lack of dragEnd event and reset
   drag event detecting
 - method resetDetecting has been changed to public
   in module tau.event.gesture.Manager

Signed-off-by: Tomasz Lukawski <t.lukawski@samsung.com>
  • Loading branch information
TomaszLukawskiSam committed Jun 16, 2020
1 parent d124b35 commit 28b4fdb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/js/core/event/gesture/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
detectors = [];

if (!self._isReadyDetecting) {
self._resetDetecting();
self.resetDetecting();
self._bindEvents();

startEvent = self._createDefaultEventData(gesture.Event.START, event);
Expand Down Expand Up @@ -287,7 +287,7 @@
this.unregister(_instance);
}, self);

self._resetDetecting();
self.resetDetecting();
self._blockMouseEvent = false;
}
},
Expand All @@ -314,7 +314,7 @@
this.unregister(_instance);
}, self);

self._resetDetecting();
self.resetDetecting();
self._blockMouseEvent = false;
},

Expand Down Expand Up @@ -380,11 +380,11 @@

/**
* Reset of gesture manager detector
* @method _resetDetecting
* @method resetDetecting
* @member ns.event.gesture.Manager
* @protected
* @public
*/
_resetDetecting: function () {
resetDetecting: function () {
var self = this;

self._isReadyDetecting = false;
Expand Down Expand Up @@ -596,7 +596,7 @@
_destroy: function () {
var self = this;

self._resetDetecting();
self.resetDetecting();
self.instances.length = 0;
self.unregisterBlockList.length = 0;
self._blockMouseEvent = false;
Expand Down
21 changes: 19 additions & 2 deletions src/js/core/widget/core/Spin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
ROLL_DURATION = 600,
DELTA_Y = 100,
DRAG_STEP_TO_VALUE = 60,
NUMBER_OF_CAROUSEL_ITEMS = 11,
NUMBER_OF_CAROUSEL_ITEMS = 13,
EVENT_DRAG_END_TIMEOUT = 500,

/**
* Alias for class Spin
Expand Down Expand Up @@ -129,6 +130,7 @@
self._lastCurrentIndex = null;
self._currentCentralCarouseItem = 0;
self._count = 0;
self._dragTimeoutHandler = null;
},

WIDGET_CLASS = "ui-spin",
Expand Down Expand Up @@ -677,13 +679,26 @@
utilsEvents.off(self.dragTarget, "drag dragend dragstart", self);
} else {
if (self.options.enabled) {
self._objectValue.value = this._startDragCount - e.detail.deltaY / DRAG_STEP_TO_VALUE;
self._objectValue.value = self._startDragCount - e.detail.deltaY / DRAG_STEP_TO_VALUE;
if (self.options.loop !== "enabled") {
self._objectValue.value = Math.min(Math.max(self._objectValue.value, 0), self.length - 1);
}
showAnimationTick(self);
}
}
// set timeout in case of drag outside screen
window.clearTimeout(self._dragTimeoutHandler);
self._dragTimeoutHandler = window.setTimeout(function () {
self._dragEnd({
detail: {
velocityY: e.velocityY,
distance: e.distance,
direction: e.direction
}
});
self._dragTimeoutHandler = null;
ns.event.gesture.Manager.getInstance().resetDetecting();
}, EVENT_DRAG_END_TIMEOUT);
};

prototype._dragStart = function () {
Expand All @@ -701,6 +716,8 @@
momentum = 0,
duration = self.options.duration;

window.clearTimeout(self._dragTimeoutHandler);

if (self.options.momentumLevel > 0 &&
e.detail.velocityY > 0.7 &&
e.detail.distance) {
Expand Down
16 changes: 8 additions & 8 deletions tests/js/core/event/gesture/Manager/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@
return event;
};

manager._resetDetecting = function () {
ok(true, "_resetDetecting was called");
manager.resetDetecting = function () {
ok(true, "resetDetecting was called");
};

manager._bindEvents = function () {
Expand Down Expand Up @@ -664,8 +664,8 @@

manager.gestureDetectors = [];

manager._resetDetecting = function () {
ok(true, "_resetDetecting was called");
manager.resetDetecting = function () {
ok(true, "resetDetecting was called");
};

manager._createDefaultEventData = function (type, _event) {
Expand Down Expand Up @@ -704,8 +704,8 @@
touches: []
};

manager._resetDetecting = function () {
ok(true, "_resetDetecting was called");
manager.resetDetecting = function () {
ok(true, "resetDetecting was called");
};

manager._createDefaultEventData = function (type, _event) {
Expand Down Expand Up @@ -770,8 +770,8 @@
test("_destroy", 4, function () {
var manager = new Manager();

manager._resetDetecting = function () {
ok(true, "_resetDetecting was called");
manager.resetDetecting = function () {
ok(true, "resetDetecting was called");
};

manager._destroy();
Expand Down

0 comments on commit 28b4fdb

Please sign in to comment.