diff --git a/release/internal/drag-operation-controller.d.ts b/release/internal/drag-operation-controller.d.ts index 0621ea0..c4bd0e7 100644 --- a/release/internal/drag-operation-controller.d.ts +++ b/release/internal/drag-operation-controller.d.ts @@ -29,7 +29,7 @@ export declare class DragOperationController { private _iterationIntervalId; constructor(_initialEvent: TouchEvent, _config: Config, _sourceNode: HTMLElement, _dragOperationEndedCb: (config: Config, event: TouchEvent, state: DragOperationState) => void); private _setup(); - private _cleanup(); + cleanup(); private _onTouchMove(event); private _onTouchEndOrCancel(event); private _dragAndDropProcessModelIteration(); diff --git a/src/index.ts b/src/index.ts index 7f9ff9a..4200d07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,8 @@ function onTouchstart( e:TouchEvent ) { // only allow one drag operation at a time if( activeDragOperation ) { console.log( "dnd-poly: drag operation already active" ); + // try avoid infinite loop on iOS if something happened with draggable dom object (disappeared or changed during drag) + activeDragOperation.cleanup(); return; } diff --git a/src/internal/drag-operation-controller.ts b/src/internal/drag-operation-controller.ts index 2a20d4d..06c17be 100644 --- a/src/internal/drag-operation-controller.ts +++ b/src/internal/drag-operation-controller.ts @@ -173,7 +173,7 @@ export class DragOperationController { console.log( "dnd-poly: dragstart cancelled" ); // dragstart has been prevented -> cancel d'n'd this._dragOperationState = DragOperationState.CANCELLED; - this._cleanup(); + this.cleanup(); return false; } @@ -245,7 +245,7 @@ export class DragOperationController { return true; } - private _cleanup() { + public cleanup() { console.log( "dnd-poly: cleanup" ); @@ -304,7 +304,7 @@ export class DragOperationController { if( !startDrag ) { - this._cleanup(); + this.cleanup(); return; } @@ -398,7 +398,7 @@ export class DragOperationController { // drag operation did not even start if( this._dragOperationState === DragOperationState.POTENTIAL ) { - this._cleanup(); + this.cleanup(); return; } @@ -796,7 +796,7 @@ export class DragOperationController { // drag operation over and out this._dragOperationState = DragOperationState.ENDED; - this._cleanup(); + this.cleanup(); } // diff --git a/src/internal/feature-detection.ts b/src/internal/feature-detection.ts index b637157..721c5e6 100644 --- a/src/internal/feature-detection.ts +++ b/src/internal/feature-detection.ts @@ -12,15 +12,29 @@ export function detectFeatures():DetectedFeatures { userAgentSupportingNativeDnD: undefined }; - const isBlinkEngine = !!((window).chrome) || /chrome/i.test( navigator.userAgent ); - - features.userAgentSupportingNativeDnD = !( - // if is mobile safari or android browser -> no native dnd - (/iPad|iPhone|iPod|Android/.test( navigator.userAgent )) - || // OR - //if is blink(chrome/opera) with touch events enabled -> no native dnd - (isBlinkEngine && ("ontouchstart" in document.documentElement)) - ); + // const isBlinkEngine = !!((window).chrome) || /chrome/i.test( navigator.userAgent ); + + // features.userAgentSupportingNativeDnD = !( + // // if is mobile safari or android browser -> no native dnd + // (/iPad|iPhone|iPod|Android/.test( navigator.userAgent )) + // || // OR + // //if is blink(chrome/opera) with touch events enabled -> no native dnd + // (isBlinkEngine && ("ontouchstart" in document.documentElement)) + // ); + + if (/iPad|iPhone|iPod/.test(navigator.userAgent)) { + // from iOS 11 and higher are supported + features.userAgentSupportingNativeDnD = !/(OS \d_)|(OS 10_)/.test(navigator.userAgent); + } + else + if (/Android/.test(navigator.userAgent)) { + // from Chrome Mobile 54 and higher are supported + features.userAgentSupportingNativeDnD = !/(Chrome\/5[0-3]\.)|(Chrome\/[1-4]\d\.)|(Chrome\/\d\.)/.test(navigator.userAgent); + } + else { + // should work on all ten years old desktop browsers and younger + features.userAgentSupportingNativeDnD = true; + } return features; }