From 360146136b03304676a73198e0a2d8034b9d16d1 Mon Sep 17 00:00:00 2001 From: jalal246 Date: Fri, 3 Nov 2023 14:33:49 +0200 Subject: [PATCH] wip --- .../src/Container/DFlexParentContainer.ts | 8 +- .../src/Container/DFlexScrollContainer.ts | 6 +- .../src/Mechanism/DFlexMechanismController.ts | 78 ++++++++++++------- 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/packages/dflex-core-instance/src/Container/DFlexParentContainer.ts b/packages/dflex-core-instance/src/Container/DFlexParentContainer.ts index 9e9f14d32..d61bbd7cd 100644 --- a/packages/dflex-core-instance/src/Container/DFlexParentContainer.ts +++ b/packages/dflex-core-instance/src/Container/DFlexParentContainer.ts @@ -16,7 +16,7 @@ class DFlexParentContainer { private _boundariesByRow: BoxNum; /** Strict Rect for siblings containers. */ - private _siblingBoundaries: BoxNum | null; + private _siblingBoundaries: BoxRect | null; private _rect: BoxRect; @@ -102,7 +102,7 @@ class DFlexParentContainer { if (this._siblingBoundaries) { this._siblingBoundaries.assignBiggestBox(rect); } else { - this._siblingBoundaries = new BoxNum( + this._siblingBoundaries = new BoxRect( rect.top, rect.right, rect.bottom, @@ -155,8 +155,8 @@ class DFlexParentContainer { * * @returns */ - getBoundaries(): AbstractBox { - return this._siblingBoundaries || this._rect.getBox(); + getBoundaries(): BoxRect { + return this._siblingBoundaries || this._rect; } /** diff --git a/packages/dflex-core-instance/src/Container/DFlexScrollContainer.ts b/packages/dflex-core-instance/src/Container/DFlexScrollContainer.ts index 5c48f28e4..b115df7f2 100644 --- a/packages/dflex-core-instance/src/Container/DFlexScrollContainer.ts +++ b/packages/dflex-core-instance/src/Container/DFlexScrollContainer.ts @@ -219,10 +219,8 @@ class DFlexScrollContainer { this._initializeOrDestroyThreshold("inner", null); this._initializeOrDestroyThreshold("inner", INNER_THRESHOLD); - if (this.hasDynamicVisibility()) { - this._initializeOrDestroyThreshold("outer", null); - this._initializeOrDestroyThreshold("outer", OUTER_THRESHOLD); - } + this._initializeOrDestroyThreshold("outer", null); + this._initializeOrDestroyThreshold("outer", OUTER_THRESHOLD); } private _updateOverflow(): void { diff --git a/packages/dflex-dnd/src/Mechanism/DFlexMechanismController.ts b/packages/dflex-dnd/src/Mechanism/DFlexMechanismController.ts index b91ef64e1..ba90f5f20 100644 --- a/packages/dflex-dnd/src/Mechanism/DFlexMechanismController.ts +++ b/packages/dflex-dnd/src/Mechanism/DFlexMechanismController.ts @@ -868,48 +868,66 @@ class DFlexMechanismController extends DFlexScrollableElement { private _processScroll(x: number, y: number, SK: string): boolean { let isOutSiblingsContainer = false; - const { scroll } = this.draggable; + const { + scroll: { enable }, + } = this.draggable; - if (scroll.enable) { - this.scrollFeed(x, y, SK); + // If scrolling is disable, do nothing. + if (!enable) { + return false; + } - if (this.hasActiveScrolling()) { - if (!this.hasBeenScrolling) { - scheduler(store, null, { - onUpdate: () => { - isOutSiblingsContainer = this.draggable.isOutThreshold(SK); + const { containers, scrolls } = store; - // When it's inside the container, then the siblings are not lifted - if (!(isOutSiblingsContainer || this.isParentLocked)) { - this._updateContainerLockState(true); - this._fillHeadUp(); - } - }, - }); + const container = containers.get(SK)!; + const scroll = scrolls.get(SK)!; - this.hasBeenScrolling = true; - } + const viewportRect = container.getBoundaries(); - return true; - } + const [isInvisible] = scroll.isElmOutViewport(viewportRect, true); - if (this.hasBeenScrolling) { - isOutSiblingsContainer = this.draggable.isOutThreshold(SK); + // If rect is entirely visible, do nothing. + if (!isInvisible) { + return false; + } - if (!isOutSiblingsContainer && this.isParentLocked) { - const [scrollOffsetX, scrollOffsetY] = - this._calculateScrollOffsets(SK); + this.scrollFeed(x, y, SK); - // Update the position before calling the detector. - this.draggable.positions.setPos(x, y, scrollOffsetX, scrollOffsetY); + if (this.hasActiveScrolling()) { + if (!this.hasBeenScrolling) { + scheduler(store, null, { + onUpdate: () => { + isOutSiblingsContainer = this.draggable.isOutThreshold(SK); - this._detectNearestElm(); - } + // When it's inside the container, then the siblings are not lifted + if (!(isOutSiblingsContainer || this.isParentLocked)) { + this._updateContainerLockState(true); + this._fillHeadUp(); + } + }, + }); - this.hasBeenScrolling = false; + this.hasBeenScrolling = true; + } - return true; + return true; + } + + if (this.hasBeenScrolling) { + isOutSiblingsContainer = this.draggable.isOutThreshold(SK); + + if (!isOutSiblingsContainer && this.isParentLocked) { + const [scrollOffsetX, scrollOffsetY] = this._calculateScrollOffsets(SK); + + // Update the position before calling the detector. + this.draggable.positions.setPos(x, y, scrollOffsetX, scrollOffsetY); + + this._detectNearestElm(); } + + this.hasBeenScrolling = false; + + return true; } return false;