tech-systems / panes

🎉📱 Create dynamic modals, cards, panes for your applications in few steps. One instance – Thousands solutions. Any framework and free.
https://panejs.com
MIT License
681 stars 40 forks source link

[BUG] overflow-y stop working when switching pages #218

Closed luckashenri closed 1 year ago

luckashenri commented 1 year ago

Describe the bug Currently in my angular app, I added some routing inside the Drawer. Aka Cupertino Pane. Everytime I move to another route the overflow-y stop working, like there's no scrolling.

At first I thought about recalculating and I found out that there's this method called 'calcFitHeight', but when I call it it says 'calcFitHeight is not a function'.

Second try was calling 'scrollElementInit'. That worked but only if I scroll DOWN. When I try to scroll UP again it brings the whole drawer with it.

https://github.com/luckashenri/cupertino-pane-bug

To Reproduce Steps to reproduce the behavior:

  1. See my github project. Also dropped it in Stackblitz.

Expected behavior When I switch page, it should recalculate and present the scroll like it does the first time I refresh. Or at least allow me to access some recalculate method.

Screenshots image

Desktop:

Additional context Angular 16.2 No other library installed. If I don't use overflow-y it works normally.

roman-rr commented 1 year ago

@luckashenri not checked yet, just quick assumption that router remove elements from DOM. Maybe just init inside body will fix. I will check in few days.

luckashenri commented 1 year ago

@roman-rr I tried with diff version, but still no luck.

Something interesting is that after calling 'scrollElementInit' it does work to scroll down, but when I scroll up it brings the panel together.

Well keep trying at the meantime and keep u posted.

roman-rr commented 1 year ago

@luckashenri Thank you again, I've checked. calcFitHeight() method should be used for Auto Height panes with settings.fitHeight = true; The fitHeight: true option will assign method calcFitHeight() for instance.

In your case, you just want to scroll up on each new page?

luckashenri commented 1 year ago

@roman-rr I found out something interesting..

Not sure if u're familiar with angular, or any other framework like that.. But basically when I put the 'overflow-y' attribute in a upper level, it will render the inner data correctly with scroll.

When I do it inside each inner page, it will work for first one only, and then break.

example 1: image

In this example, the pages have their own custom header, and custom body. In that case, the scroll breaks cause it needs to recalc everytime I switch page (that's what I think).

example 2:

image

In this second example, I have the page changing INSIDE the overflow-y div.. In that case, even changing the height of inner content, it works nicely.. But in this case, I can't have a custom header like in first example.

roman-rr commented 1 year ago

@luckashenri Would you like to recalculate height of overflow-y element on page changes?

  1. Have you tried setOverflowHeight() method ?
  2. Have you checked this example ? Here overflow element recalculated dynamically.

If nothing works, your example still relevant ? I may try to do this right on this example ? Or you have to adjust this example with headers ?

luckashenri commented 1 year ago

@roman-rr .

I don't want the overflow-y to recalc it necessarely, it's just that I noticed that it loses the height once I move to another page for some reason, I thought recalculating would fix, but it caused the scroll affecting the drawer as well. (like I explain below answering ur second question).

1 - Yes, it didn't have any effect. 2 - Yes, I tried something similar calculating manually the height. It kinda works but then the action of scrolling inner scroll also affects the drawer as a whole. When I scroll it also drags the drawer.

Yeah that project I sent is still valid. In fact now I added 2 modules. One with it working (but with static header). And another with dynamic header (that comes within the page) but with scroll breaking.

Seems like stackblitz doesn't want to run it lol.. I guess u'll need to clone and run it. Lemme know if it works for u.

luckashenri commented 1 year ago

@roman-rr not sure it's relavant, but I noticed it shows 'cancelable: true' once it's being dragged.. The only difference I noticed so far between them.

not working example: image

working example (I took this screenshot before switching pages, so I could check how was the states before breaking): image

roman-rr commented 1 year ago

@luckashenri thank you for details, I'll check in couple days

roman-rr commented 1 year ago

@luckashenri Thank you for interesting case! Actually, angular remove elements from DOM and all events also removed. Moreover, for new element scroll have to be re-initialized and events re-attached.

Solution

Change your function to:

ngAfterViewInit() {
    this.router.events.pipe(
      filter(event => event instanceof NavigationEnd)
    ).subscribe({
      next: async (value) => {
        await new Promise(resolve => requestAnimationFrame(resolve));
        this.myPane.scrollElementInit();
        this.myPane.checkOverflowAttr(this.myPane.breakpoints.currentBreakpoint);
        this.myPane.events.detachAllEvents();
        this.myPane.events.attachAllEvents();
      },
    });
}

Not a simple case, if there are more such re-renders for overflow-y element in the future, I will make some scoped functions to manage events re-attachments around the scroll element.

luckashenri commented 1 year ago

@roman-rr Yeah just got a chance to test it, it worked!! I just ran some tests and profilers and seems like that won't have an impact on performance as well. Thanks man!