Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

[Question] save scroll position between navigations #59

Open
AbrahamAlcaina opened this issue Jul 4, 2015 · 12 comments
Open

[Question] save scroll position between navigations #59

AbrahamAlcaina opened this issue Jul 4, 2015 · 12 comments

Comments

@AbrahamAlcaina
Copy link

Hi,
I used the fluxible-generator and it have the HandleHistory

export default handleHistory(provideContext(connectToStores(
    Application,
    [ApplicationStore, WallStore],
    function (stores, props) {
        const appStore = stores.ApplicationStore;
        const wallStore = stores.WallStore;
        return {
            currentPageName: appStore.getCurrentPageName(),
            pageTitle: appStore.getPageTitle(),
            pages: appStore.getPages(),
            wall: wallStore.getWall()
        };
    }
)));

I read the documentation and it restore automatically the scroll position.
It's working fine if I use the refresh button in the browser, but if I navigated to another page and comeback it do not restore the scroll position.

I used the option preserveScrollPosition

 <NavLink routeName={link.page} preserveScrollPosition={true}>{link.title}</NavLink>

I miss something?

here you can test
Sorry if it is a noov question.

@mridgway
Copy link
Collaborator

mridgway commented Jul 8, 2015

Can you try changing the order of the HoCs to provideContext(handleHistory(connectToStores(...)))? I wonder if handleHistory is not able to access the context correctly.

@AbrahamAlcaina
Copy link
Author

@mridgway I changed it and still fail.
Could be related with add action to the configuration?
This is my code:

import {getNews} from '../actions/newsActions';
export default {
    home: {
        path: '/',
        method: 'get',
        page: 'home',
        title: 'Home',
        handler: require('../components/Home'),
        action: getNews
    },
    about: {
        path: '/about',
        method: 'get',
        page: 'about',
        title: 'About',
        handler: require('../components/About')
    }
};

PS today I uploaded all the app to github

@AbrahamAlcaina
Copy link
Author

One of my components it is listening 'scroll' & 'resize'.

window.addEventListener('scroll', this.scrollListener);
window.addEventListener('resize', this.scrollListener);

To do an infinite scroll (aka load more items)

@tbo
Copy link

tbo commented Jul 18, 2015

I think I can confirm this. I originally wrote the preserveScrollPosition feature for flux-router-component. Both versions seem to differ in one very basic aspect. flux-router-component changes the current route after the route action has been executed, fluxible-router changes it directly on NAVIGATE_START.

In case of routes with async actions, the scroll position is being restored before the current route handler has anything to display.

@mridgway Can you confirm this?

@mridgway
Copy link
Collaborator

Confirmed, we moved pushState to the beginning of navigation. We've had some debates internally whether the scrollTo should be moved to NAVIGATE_SUCCESS and I think we're leaning towards doing just this. I think this would help with the issue at hand as well.

@tbo
Copy link

tbo commented Aug 17, 2015

@mridgway Have you made a decision on how to proceed?

@mridgway
Copy link
Collaborator

I believe @dnewcome has been diving into page transition behavior and may have some insight into the how to handle scrolling during navigation.

@malaman
Copy link

malaman commented Sep 26, 2015

@dnewcome @mridgway Do you have you any updates regarding the issue?

@Vijar
Copy link
Contributor

Vijar commented Sep 28, 2015

I believe #87 will fix this.

@mridgway
Copy link
Collaborator

We're going to recommend that you manage the scroll positions on your own and we will provide access to the saved scroll position for pop state.

We have found that there's no silver bullet solution for scrolling. It needs to be synchronized with the flow of your application rather than before or after NAVIGATE_START.

We are not going to remove the current functionality, but we will suggest that if you need better handling, then you should disable scrolling with enableScroll: false and then manage it yourself.

@malaman
Copy link

malaman commented Oct 1, 2015

@mridgway thank you for answer. Could you please describe in more details how to receive access to the saved scroll positions. Thxs in advance.

@mridgway
Copy link
Collaborator

Scroll position is available on window.history.state.scroll.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants