Skip to content

Commit

Permalink
Fix iOS dnd bug, autoscroll bug and layout bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasramo committed Aug 2, 2020
1 parent 41caf01 commit a3d9e06
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ npm install muuri

Or download:

- [muuri.js](https://cdn.jsdelivr.net/npm/[email protected].0/dist/muuri.js) - for development (not minified, with comments).
- [muuri.min.js](https://cdn.jsdelivr.net/npm/[email protected].0/dist/muuri.min.js) - for production (minified, no comments).
- [muuri.js](https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.js) - for development (not minified, with comments).
- [muuri.min.js](https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.min.js) - for production (minified, no comments).

Or link directly:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/muuri.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.min.js"></script>
```

<h3><a id="getting-started-2" href="#getting-started-2" aria-hidden="true">#</a> 2. Get Web Animations Polyfill (if needed)</h3>
Expand Down
45 changes: 40 additions & 5 deletions dist/muuri.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Muuri v0.9.1
* Muuri v0.9.2
* https://muuri.dev/
* Copyright (c) 2015-present, Haltu Oy
* Released under the MIT license
Expand All @@ -22,7 +22,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Muuri = factory());
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Muuri = factory());
}(this, (function () { 'use strict';

var GRID_INSTANCES = {};
Expand Down Expand Up @@ -2268,6 +2268,10 @@

AutoScroller.prototype.updateItem = function (item) {
if (this._isDestroyed) return;

// Make sure the item still exists in the auto-scroller.
if (!this._dragDirections[item._id]) return;

this._updateDragDirection(item);
if (!this._requestOverlapCheck[item._id]) {
this._requestOverlapCheck[item._id] = this._tickTime;
Expand Down Expand Up @@ -2734,6 +2738,7 @@
}
}

var IS_IOS = /iPad|iPhone|iPod/.test(window.navigator.platform);
var START_PREDICATE_INACTIVE = 0;
var START_PREDICATE_PENDING = 1;
var START_PREDICATE_RESOLVED = 2;
Expand Down Expand Up @@ -2845,6 +2850,7 @@
// cancelled anyways right after it has started (e.g. starting drag while
// the page is scrolling).
if (
!IS_IOS &&
event.isFirst &&
event.srcEvent.isTrusted === true &&
event.srcEvent.defaultPrevented === false &&
Expand Down Expand Up @@ -3131,6 +3137,9 @@
return;
}

// Stop auto-scroll.
ItemDrag.autoScroller.removeItem(this._item);

// Cancel queued ticks.
var itemId = this._item._id;
cancelDragStartTick(itemId);
Expand Down Expand Up @@ -3178,7 +3187,7 @@
*/
ItemDrag.prototype.sort = function (force) {
var item = this._item;
if (item._isActive && this._dragMoveEvent) {
if (this._isActive && item._isActive && this._dragMoveEvent) {
if (force === true) {
this._handleSort();
} else {
Expand Down Expand Up @@ -3456,6 +3465,8 @@
* @private
*/
ItemDrag.prototype._handleSort = function () {
if (!this._isActive) return;

var settings = this._getGrid()._settings;

// No sorting when drag sort is disabled. Also, account for the scenario where
Expand Down Expand Up @@ -3852,6 +3863,8 @@
* ItemDrag.prototype
*/
ItemDrag.prototype._prepareStart = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -3891,6 +3904,8 @@
* @private
*/
ItemDrag.prototype._applyStart = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -3972,8 +3987,9 @@
* @private
*/
ItemDrag.prototype._prepareMove = function () {
var item = this._item;
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

var settings = this._getGrid()._settings;
Expand Down Expand Up @@ -4008,6 +4024,8 @@
* @private
*/
ItemDrag.prototype._applyMove = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -4042,9 +4060,10 @@
* @private
*/
ItemDrag.prototype._prepareScroll = function () {
var item = this._item;
if (!this._isActive) return;

// If item is not active do nothing.
var item = this._item;
if (!item._isActive) return;

var element = item._element;
Expand Down Expand Up @@ -4087,6 +4106,8 @@
* @private
*/
ItemDrag.prototype._applyScroll = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -5138,6 +5159,13 @@
return;
}

// Let's make sure an ongoing animation's callback is cancelled before going
// further. Without this there's a chance that the animation will finish
// before the next tick and mess up our logic.
if (this._animation.isAnimating()) {
this._animation._animation.onfinish = null;
}

// Kick off animation to be started in the next tick.
this._isActive = true;
this._animOptions.easing = animEasing;
Expand Down Expand Up @@ -5846,6 +5874,13 @@
return;
}

// Let's make sure an ongoing animation's callback is cancelled before going
// further. Without this there's a chance that the animation will finish
// before the next tick and mess up our logic.
if (animation.isAnimating()) {
animation._animation.onfinish = null;
}

// Start the animation in the next tick (to avoid layout thrashing).
addVisibilityTick(
item._id,
Expand Down
4 changes: 2 additions & 2 deletions dist/muuri.min.js

Large diffs are not rendered by default.

43 changes: 39 additions & 4 deletions dist/muuri.module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Muuri v0.9.1
* Muuri v0.9.2
* https://muuri.dev/
* Copyright (c) 2015-present, Haltu Oy
* Released under the MIT license
Expand Down Expand Up @@ -2262,6 +2262,10 @@ AutoScroller.prototype.addItem = function (item) {

AutoScroller.prototype.updateItem = function (item) {
if (this._isDestroyed) return;

// Make sure the item still exists in the auto-scroller.
if (!this._dragDirections[item._id]) return;

this._updateDragDirection(item);
if (!this._requestOverlapCheck[item._id]) {
this._requestOverlapCheck[item._id] = this._tickTime;
Expand Down Expand Up @@ -2728,6 +2732,7 @@ function removeClass(element, className) {
}
}

var IS_IOS = /iPad|iPhone|iPod/.test(window.navigator.platform);
var START_PREDICATE_INACTIVE = 0;
var START_PREDICATE_PENDING = 1;
var START_PREDICATE_RESOLVED = 2;
Expand Down Expand Up @@ -2839,6 +2844,7 @@ ItemDrag.defaultStartPredicate = function (item, event, options) {
// cancelled anyways right after it has started (e.g. starting drag while
// the page is scrolling).
if (
!IS_IOS &&
event.isFirst &&
event.srcEvent.isTrusted === true &&
event.srcEvent.defaultPrevented === false &&
Expand Down Expand Up @@ -3125,6 +3131,9 @@ ItemDrag.prototype.stop = function () {
return;
}

// Stop auto-scroll.
ItemDrag.autoScroller.removeItem(this._item);

// Cancel queued ticks.
var itemId = this._item._id;
cancelDragStartTick(itemId);
Expand Down Expand Up @@ -3172,7 +3181,7 @@ ItemDrag.prototype.stop = function () {
*/
ItemDrag.prototype.sort = function (force) {
var item = this._item;
if (item._isActive && this._dragMoveEvent) {
if (this._isActive && item._isActive && this._dragMoveEvent) {
if (force === true) {
this._handleSort();
} else {
Expand Down Expand Up @@ -3450,6 +3459,8 @@ ItemDrag.prototype._resetStartPredicate = function () {
* @private
*/
ItemDrag.prototype._handleSort = function () {
if (!this._isActive) return;

var settings = this._getGrid()._settings;

// No sorting when drag sort is disabled. Also, account for the scenario where
Expand Down Expand Up @@ -3846,6 +3857,8 @@ ItemDrag.prototype._onStart = function (event) {
* ItemDrag.prototype
*/
ItemDrag.prototype._prepareStart = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -3885,6 +3898,8 @@ ItemDrag.prototype._prepareStart = function () {
* @private
*/
ItemDrag.prototype._applyStart = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -3966,8 +3981,9 @@ ItemDrag.prototype._onMove = function (event) {
* @private
*/
ItemDrag.prototype._prepareMove = function () {
var item = this._item;
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

var settings = this._getGrid()._settings;
Expand Down Expand Up @@ -4002,6 +4018,8 @@ ItemDrag.prototype._prepareMove = function () {
* @private
*/
ItemDrag.prototype._applyMove = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -4036,9 +4054,10 @@ ItemDrag.prototype._onScroll = function (event) {
* @private
*/
ItemDrag.prototype._prepareScroll = function () {
var item = this._item;
if (!this._isActive) return;

// If item is not active do nothing.
var item = this._item;
if (!item._isActive) return;

var element = item._element;
Expand Down Expand Up @@ -4081,6 +4100,8 @@ ItemDrag.prototype._prepareScroll = function () {
* @private
*/
ItemDrag.prototype._applyScroll = function () {
if (!this._isActive) return;

var item = this._item;
if (!item._isActive) return;

Expand Down Expand Up @@ -5132,6 +5153,13 @@ ItemLayout.prototype.start = function (instant, onFinish) {
return;
}

// Let's make sure an ongoing animation's callback is cancelled before going
// further. Without this there's a chance that the animation will finish
// before the next tick and mess up our logic.
if (this._animation.isAnimating()) {
this._animation._animation.onfinish = null;
}

// Kick off animation to be started in the next tick.
this._isActive = true;
this._animOptions.easing = animEasing;
Expand Down Expand Up @@ -5840,6 +5868,13 @@ ItemVisibility.prototype._startAnimation = function (toVisible, instant, onFinis
return;
}

// Let's make sure an ongoing animation's callback is cancelled before going
// further. Without this there's a chance that the animation will finish
// before the next tick and mess up our logic.
if (animation.isAnimating()) {
animation._animation.onfinish = null;
}

// Start the animation in the next tick (to avoid layout thrashing).
addVisibilityTick(
item._id,
Expand Down
Loading

0 comments on commit a3d9e06

Please sign in to comment.