Add pull to refresh feature?

Dominik L Posted in Technical Support 1 month ago

Any idea how to implement a pull to refresh feature on mobile devices?

I found a js code and tried to implement it via customjss component but without success.

Replies
German Michael Zülsdorff Replied 1 month ago

I am using iOS and when I use the progressive Web app then a swipe down to reload the page it's not possible that's why I want a pull to refresh feature

Can anyone else confirm this issue:
Iphone -> running Ossn in PWA (Progressive Web App) mode -> no reload on swipe down if on top of page?

German Dominik L Replied 1 month ago

Good idea, thanks! :)

German Dominik L Replied 1 month ago

Thanks, will try :)

German Michael Zülsdorff Replied 1 month ago

No idea if it's working in your environment ... just give it a try ;)
https://www.opensource-socialnetwork.org/component/view/7169

German Dominik L Replied 1 month ago

I am using iOS and when I use the progressive Web app then a swipe down to reload the page it's not possible that's why I want a pull to refresh feature

When I use the mobile website on Brave browser for example then I have a built-in pull to refresh but this is not working in the PWA

At the moment I am using the goblue theme and when the user wants to reload the wall (to see if there are new posts), then they have to click on the menu on the left corner and trigger a reload by click on "newsfeed" again

But for a better user experience, I want, that my users just have to swipe down and then newsfeed reloads so they see new postings

German Michael Zülsdorff Replied 1 month ago

Hmm... I don't understand why this extra code should be necessary?

Because with my Android phone
I can trigger an _automatic_ page reload
whenever I'm on top of a page and doing a 'swipe down' gesture!
But of course all this doesn't make too much sense if you have scrolled 20 pages forward already...

Thus my idea would be making it part of the Scroll-To-Top component.
Currently, it implements the scrolling only, but you may add some code to trigger a reload, too when back on top.

German Dominik L Replied 1 month ago

Mostly the newsfeed page

I found that code in GitHub:

document.addEventListener('DOMContentLoaded', function () {
    let refreshDiv = document.createElement('div');
    refreshDiv.className = 'refresh';
    refreshDiv.textContent = 'Refreshing...';
    document.body.prepend(refreshDiv);

    let startY = 0;
    let isPulling = false;

    document.addEventListener('touchstart', function (e) {
        if (window.scrollY === 0) {
            startY = e.touches[0].clientY;
        }
    });

    document.addEventListener('touchmove', function (e) {
        if (window.scrollY === 0 && e.touches[0].clientY > startY) {
            let diff = e.touches[0].clientY - startY;
            if (diff > 50) {
                isPulling = true;
                refreshDiv.style.top = '0';
            } else {
                refreshDiv.style.top = '-50px';
                isPulling = false;
            }
        }
    });

    document.addEventListener('touchend', function (e) {
        if (isPulling) {
            setTimeout(function () {
                refreshDiv.style.top = '-50px';
                alert('Content refreshed!');
            }, 1000);
        }
        isPulling = false;
    });
});

But when I try to insert it on custom JS, I get a 403 error

German Michael Zülsdorff Replied 1 month ago

Which page(s) are you trying to refresh and what code are you talking about?