-
Notifications
You must be signed in to change notification settings - Fork 58
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
Several enhancements for StandardScroll #52
Conversation
- Adds ability to ignore scroll behavior by passing ignoreScroll with location state - Adds ability to restore scroll by passing `restoreScroll` with location state - When routing to the current location scroll to top - RAF around scrollTo that was necessary for restoreScroll functionality
Will add tests and documentation as well, but wanted to start a conversation about the changes first |
For |
It could. Seems like a feature that would be nice to have out of the box though. |
I thought a visual might help explain the necessity of the enhancements. In the screenshot you'll notice a top bar that allows you to switch between your home timeline and notifications. I have added You'll also notice a "SegmentedControl" on the profile that allows you to switch between Tweets, Media, and Likes. For these links I have added |
I like where you're going with this.
Thanks again for the PR! |
Thanks for the review @taion
Let me know when the changes are good and I'll work on the tests and documentation. |
I see what you mean. That makes sense, thanks. Give me a moment to think about this. I'll get back to you shortly. |
Do you think it would make sense if You don't need to amend your PR – I just had a separate idea for how to update scroll position that might address some long-standing issues like #15, but I need to experiment with it. How urgently do you need a release? It might take me a day or two. |
@taion I actually had the same thought about I need a solution in the next day or so, but don't rush because of me. I can use my fork to unblock myself. I'm also interested in authoring the patch if you want to share your plans for #15 |
Would you be willing to amend this PR to just update I don't want to waste your time with my hairbrained ideas for #15. The idea – and I have no clue if it works – is to actual listen for the scroll event caused by our attempt to restore the scroll position (is there one?), and keep trying to scroll to the right position every frame until that scroll event fires, except if I get the same scroll position back two frames in a row, in which case I give up (because maybe I'm at the end of the page or something and I can't get to where I want to be, because the page is shorter now). |
@taion I'll take a shot at that. I might need the RAF stuff for restore scroll (not really sure why honestly). Do you expect wrapping window.scrollTo in RAF will cause problems? |
I'm saying that I think what I have is more reliable than RAF. I'll make some time to look at it later today. For future API consideration, are you willing to share whether you're using this with React Router, or whether you're using this on its own? |
Something more reliable sounds like a win. We are using this with React Router. I was originally going to fork this internally, but then realized that there will likely be some churn on this module and react router integration, so I wanted to make sure the features we need for our app will carry on. I'm working on the patch in a new branch now. It's code complete just need to write the tests. Should have it for you shortly. |
Closing in favor of #53 |
So this is what I ended up with implementing these features in user land. It can be further simplified once the RAF alternative lands: https://gist.github.com/jondkoon/e81c956674655d3cae625e985f749d81 I don't like that I have to use readState in order to get the scrollPosition. Have any ideas for alternatives? |
Are the data not all on |
Doesn't seem to be. I was surprised by that as well. Double checking... |
What sorts of transitions were these? Push or pop? |
Fresh page load -> push -> push |
Ah, sorry! I see now. Yes, for the previous state, to avoid weird stuff with mutating the location object, we don't update You'll want to always use |
Gotcha. I think I can probably get away with just looking at new state for my case. Thanks! |
Implemented the more robust scroll handling on #56. |
Adds ability to ignore scroll behavior by passingignoreScroll
withlocation state
restoreScroll
withlocation state