Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] scroll position #45

Open
nichoth opened this issue Aug 23, 2016 · 5 comments
Open

[question] scroll position #45

nichoth opened this issue Aug 23, 2016 · 5 comments

Comments

@nichoth
Copy link

nichoth commented Aug 23, 2016

When we use the back and forward buttons we expect the scroll position to be where we left off at. How do you handle scroll position? Does this library provide a mechanism for it?

@yoshuawuyts
Copy link
Owner

yoshuawuyts commented Aug 25, 2016

@nichoth nope so far this lib only does routing and all stuff related with that. E.g. instrument the history API, handle links to trigger the router, etc.

I'm not sure what the story is about scroll position. I haven't given it much though, but figured virtual doms would handle this. Could you perhaps provide some more information on this? How does persisting scroll position work, and what's the use case? Should we handle it?

@nichoth
Copy link
Author

nichoth commented Aug 25, 2016

I've always used single-page which passes you the previous scroll position when the route changes, but it is a lower level module. I would like to better encapsulate this functionality, not sure how though. Here is an example of it in use, where we jump to that position after rendering the new view. https://github.com/nichoth/tiny-thunder/blob/master/src/lib/routes/index.js#L19

@yoshuawuyts
Copy link
Owner

@nichoth would it be viable to save scrollposition on a per-view basis? perhaps with a lil history listener + subscription or something?

@nichoth
Copy link
Author

nichoth commented Aug 29, 2016

It makes sense for scroll position to be part of UI state like everything else. We need a hook somewhere during page changes that gets the scroll position when someone leaves a view. Then the view needs to go to the scroll position iff the user got there via the back button. So the minimum that we need to know from the router is if the route was triggered via back button or click. Maybe we don't want to save scroll state in the router. I will eventually do more work on this, because I have to figure it out for my project.

@yoshuawuyts
Copy link
Owner

It makes sense for scroll position to be part of UI state like everything else

Yeah I think that's fair. Though scrollstate can also a thing on a per-component basis, but I feel like that might be a bit more of an edge case. What do you think the right API for this would be?

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

No branches or pull requests

2 participants