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

Reverse restrictToViewport #28

Open
liamb13 opened this issue Jul 1, 2021 · 9 comments
Open

Reverse restrictToViewport #28

liamb13 opened this issue Jul 1, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@liamb13
Copy link

liamb13 commented Jul 1, 2021

Wondering how it could be possible to work restrictToViewport going the opposite direction.

restrictToViewport works great for:
/contacts to /contacts/12

But not so much going from
/contacts/12 to /contacts

To replicate, using your dynamic list example (obviously with restrictToViewport enabled)
/dynamic-lists to /dynamic-lists/8 works as intended:
Lists to List works

But the opposite /dynamic-lists/8 to /dynamic-lists doesn't
List Item to Lists

@justintaddei
Copy link
Owner

That would be a simple check of the activeElement's DOMRect at index.ts:38

restrictToViewport was originally developed to alleviate the performance cost of having many shared elements on a single page. This also helped with the jarring effect of seeing a shared element, that was not in the viewport on the route you left, suddenly fly into the viewport on the new route. Since v-shared-element only considers shared elements that have been cached on the previous route, there is little to gain from disabling those which are not in the viewport on the new route.

What was your main reasoning behind trying to do this? If think it would be a worthwhile feature, I will look into developing it!

@liamb13
Copy link
Author

liamb13 commented Jul 1, 2021

So idea being that a user could navigate to a page from google search or their history. Then by clicking the back button there’s a nice interaction to take them to the item in the list.

Does that make sense?

@justintaddei
Copy link
Owner

I apologize, but I'm not quite sure I follow what you're saying. If they arrive at /examples/dynamic-lists/2 from Google search, and hit the back button, they will be taken back to Google.

But the opposite /dynamic-lists/8 to /dynamic-lists doesn't

This gif you provided displays the behavior I intended. What is it that "doesn't work" exactly? Do you mean to have it not animate back to the list because the list item is outside of the viewport?

@liamb13
Copy link
Author

liamb13 commented Jul 1, 2021

Sorry, I'm having a hard time describing it. I've simulated the intended effect:
Intended

So the viewport would be where that item appears on the page after the transition.

Where currently it's the top of the page:
Current

@justintaddei
Copy link
Owner

Oh, so you're suggesting that the page is scrolled so that the active shared-element on the incoming route is positioned inside the viewport?

@liamb13
Copy link
Author

liamb13 commented Jul 1, 2021

Yep, spot on! Sorry I was a bit over the shop trying to explain. I think as an option might be best because I can see why some would prefer as is.

@justintaddei justintaddei added the enhancement New feature or request label Jul 1, 2021
@justintaddei
Copy link
Owner

That's a cool idea. I'll look into implementing it!

@719media
Copy link
Contributor

719media commented Jul 14, 2021

If the route is changing between, this is generally best solved by using <keep-alive> along with vue-router in vue, which will take care of scrolling for you.

@justintaddei
Copy link
Owner

@719media I believe the difference they are talking about is for when navigating to pages that have not yet been visited. Where vue-router wouldn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants