Skip to content

Conversation

@hbcarlos
Copy link
Contributor

@hbcarlos hbcarlos commented Dec 9, 2020

Description

As discussed in #1001 the resizing with scrolling is not working.
I'm trying to solve it here but I'm having some troubles. Now is working fine but I'm resizing the layout adding some rows on resizestart because when while resizing an item there is a back and force with the number of cells creating a strange behaviour.

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

@hbcarlos hbcarlos marked this pull request as draft December 9, 2020 13:39
@hbcarlos hbcarlos marked this pull request as ready for review December 9, 2020 23:39
Copy link
Member

@adumesny adumesny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for doing this! but minRow + 100 is a big no. Ping me if you need more help on fixing right way.

src/utils.ts Outdated
/** @internal */
static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
let scrollEl = this.getScrollParent(el);
if (scrollEl === null) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!scrollEl ) return;

src/utils.ts Outdated
scrollEl.scrollBy({ behavior: 'smooth', top: event.clientY - distance});
}

if (bottom) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (bottom)


// Saving `minRow` and adding new ones for resizing
minRow = this.opts.minRow;
this.opts.minRow = this.getRow() + 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big no no - don't arbitrary add 100 rows!
we should only add 1 extra row (when computing the needed rows) IFF the item you are resizing/moving is at the bottom (node.y+node.h). don't need to mod minRow for this...

src/utils.ts Outdated
}
}

/** @internal */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a real comment on your code. seems reasonable given we do something similar (though quite different code. I will have to diff into the scroll as I didn't write that)

/** @internal */
private temporalRect: Rect;
/** @internal */
private scrollY: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need that in JQ version as well ?

private _resizeStart(event: MouseEvent): DDResizable {
this.originalRect = this.el.getBoundingClientRect();
const scrollEl = Utils.getScrollParent(this.el);
this.scrollY = scrollEl === null ? 0 : scrollEl.scrollTop;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.scrollY = scrollEl ? scrollEl.scrollTop : 0;

private _getChange(event: MouseEvent, dir: string): Rect {
const oEvent = this.startEvent;
const scrollEl = Utils.getScrollParent(this.el);
const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar change

/** @internal */
private _resizeStart(event: MouseEvent): DDResizable {
this.originalRect = this.el.getBoundingClientRect();
const scrollEl = Utils.getScrollParent(this.el);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache this since you need it in all 3 methods and continuously, or does it change over time ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes over time. When there is no scroll because the layout is small scrollEl is null and eventually when the layout grows returns the scrollable element.

Copy link
Member

@adumesny adumesny Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, so you could scrollEl = scrollEl || Utils.getScrollParent(this.el) and cache it once it appears, unless it changes values ?
quick looking it appears to go up recursively so maybe it could be different elements over time... so maybe not.

@adumesny adumesny marked this pull request as draft December 12, 2020 17:43
@hbcarlos
Copy link
Contributor Author

Thanks for the tips @adumesny. I need some help with the placeholder and the view of the item while resizing.

There is two case that I'm not sure how to solve.
As you can see in the next gif, when the scrolling starts the item position changes.
item-move

When the item is at the bottom and the mouse pointer goes out of the grid-stack element while resizing, the Utils.getScrollParent(this.el); returns the grid-stack element and not his parent.

item-disapears

@adumesny
Copy link
Member

I'll take a look in the next couple days... I just spend entire weekend re-writing collision so need to take a break from gridstack

@hbcarlos
Copy link
Contributor Author

The resize is working. The problem was the scrollable parent, sometimes got lost.

resize

@hbcarlos hbcarlos marked this pull request as ready for review December 28, 2020 18:26
@adumesny
Copy link
Member

adumesny commented Jan 3, 2021

sorry, taking a look now. I had to fix some Safari mac issues and released I also tweaked on we do resizing (event handling really).

Copy link
Member

@adumesny adumesny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks reasonable (minor doc comments). Can you update to the latest dev code so I can push it in ?
I need to cherry pick as well to verify it works. Have you tried how tat affects the JQ version as well ?

} else if (el.scrollHeight > el.clientHeight) {
returnEl = el;
if (el === null) return document.documentElement;
const style = getComputedStyle(el);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is getComputedStyle() better than checking the simple el.scrollHeight > el.clientHeight because you want to remember what parent MIGHT scroll later ? (in case you don't already scroll ?) - please add comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, also with el.scrollHeight > el.clientHeight sometimes is selecting a non scrollable parent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. didn't think that would be possible... but I realize the call you have return the first that could scroll which is safer anyway... but always return the doc as least, which might not scroll so it should return NULL and have that be handled ideally...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, the best option would be returning NULL when there isn't a scrollable parent but in this case, we need to prevent gridstack to continue growing.

I was using the example float.html to check my changes. I think in this example the ideal would be that gridstack stops growing when there is no more page because the element that is scrolling is the document not the container that wraps gridstack.

Copy link
Contributor Author

@hbcarlos hbcarlos Jan 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we need to manually prevent gridstack to grow because:
In my case, I have two screens one on top of another and I have the browser with the webpage with gridstack on the screen above.
Captura de pantalla 2021-01-03 a las 8 24 12

When I try to resize or drag and drop an item to the bottom my mouse continue on the screen bellow so gridstack still growing even when the page can't scroll. Once I stop there is no scrollable parent so the documentElement is resized to wrap everything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well we have a maxRow to prevent grid from growing past that size, but you are saying that if none of the parents can scroll (by default divs will auto scroll unless you have overflow: hidden or something) then we should stop growing so we don't clip, which makes sense... Looks like you are checking for overflow | overflow-y for and auto or scroll
you don't need 2 screens to test this. browser smaller than full screen will do that too...

if you want to take a stab at it that would be great. _prepareDragDropByNode() should cache if we can not v-scroll and prevent move/size past the max somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at this over the week (probably weekend, I'm quite busy right now) :)

/** @internal */
private _resizeStart(event: MouseEvent): DDResizable {
this.originalRect = this.el.getBoundingClientRect();
this.scrollEl = Utils.getScrollParent(this.el);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset this in destroy()

@adumesny adumesny marked this pull request as draft January 3, 2021 02:20
@adumesny adumesny marked this pull request as ready for review January 3, 2021 02:20
@adumesny adumesny merged commit 3bcf007 into gridstack:develop Jan 3, 2021
@hbcarlos
Copy link
Contributor Author

hbcarlos commented Jan 3, 2021

sorry, taking a look now. I had to fix some Safari mac issues and released I also tweaked on we do resizing (event handling really).

No problem at all.

Thanks for merging and sorry for the comments, I can open a PR to add some comments if you want.

@adumesny
Copy link
Member

adumesny commented Jan 3, 2021

no need, I took care of it I believe. thanks for fixing this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants