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

[✨] View Transition Hook #229

Closed
shairez opened this issue Mar 10, 2025 · 3 comments
Closed

[✨] View Transition Hook #229

shairez opened this issue Mar 10, 2025 · 3 comments
Labels
[STAGE-2] incomplete implementation Remove this label when implementation is complete [STAGE-2] not fully covered by tests yet Remove this label when tests are verified to cover the implementation [STAGE-2] unresolved discussions left Remove this label when all critical discussions are resolved on the issue [STAGE-3] docs changes not added yet Remove this label when the necessary documentation for the feature / change is added [STAGE-3] missing 2 reviews for RFC PRs Remove this label when at least 2 core team members reviewed and approved the RFC implementation

Comments

@shairez
Copy link
Contributor

shairez commented Mar 10, 2025

Champion: @GrandSchtroumpf

Discussed in #135

Originally posted by GrandSchtroumpf August 26, 2023

Is your feature request related to a problem?

I'm trying a animate a list of item on page navigation. For that I'm animating with Javascript, but there is no way to hook into the transition from the link.

const animate = $(() => {
  const items = document.querySelectorAll('.item');
  for (const item of items) {
    const transitionName = item.style.getProperty('view-transition-name');
    // Animation is not working because I need to be inside the transition
    document.documentElement.animate({
      transform: [....],
    }, {
      pseudoElement: `::view-transition-old(${transitionName})`,
      duration: 200
    })
  }
})
return <Link onClick$={animate} href="...">Link</Link>

Describe the solution you'd like

Ideally the Link element & useNavigation would expose a callback for that :

const animate = $((transition, element) => {
  ....
})
return <Link onViewTransition$={animate} href="...">Link</Link>

Describe alternatives you've considered

We cannot set the animation inside style because this is a pseudo element of html.
As we cannot update the pseudo element with Javascript and we cannot use css variable like that ::view-transition-old(var(--name)).
We cannot set a <style> on each element because it'll be removed before the view transition is ready.

The only solution is to add <style> inside head with all the ::view-transition-old() pseudo class and remove them:

const viewTransitionName = "...";
useVisibleTask$(() => {
  const style = document.createElement('stlye');
  style.textContent = `::view-transition-old(${viewTransitionName}) { animation: ....; }`
  const child = document.head.appenChild(style);
  return () => setTimeout(() => document.head.removeChild(child), 1000); // wait for transition to be done
});
return <Link href="">...</Link>

Note: I'm not using ::view-transition-old(*) because I want to target specific elements (not all) and I want to add delay.

Active PRs

QwikDev/qwik#7237

@github-project-automation github-project-automation bot moved this to In Progress (STAGE 2) in Qwik Evolution Mar 10, 2025
@github-actions github-actions bot added [STAGE-2] incomplete implementation Remove this label when implementation is complete [STAGE-2] not fully covered by tests yet Remove this label when tests are verified to cover the implementation [STAGE-2] unresolved discussions left Remove this label when all critical discussions are resolved on the issue [STAGE-3] docs changes not added yet Remove this label when the necessary documentation for the feature / change is added [STAGE-3] missing 2 reviews for RFC PRs Remove this label when at least 2 core team members reviewed and approved the RFC implementation labels Mar 10, 2025
@shairez
Copy link
Contributor Author

shairez commented Mar 10, 2025

@GrandSchtroumpf can you please wrap this under experimental please? that way we would be able to collect feedback before solidifying the final API

Thanks!

@shairez shairez moved this from In Progress (STAGE 2) to To Review (STAGE 3) in Qwik Evolution Mar 10, 2025
@GrandSchtroumpf
Copy link

With the new qviewTransition event we don't need this anymore. Let's close it.

@shairez
Copy link
Contributor Author

shairez commented Mar 10, 2025

OK cool, thanks

@shairez shairez closed this as completed Mar 10, 2025
@github-project-automation github-project-automation bot moved this from To Review (STAGE 3) to Released as Stable (STAGE 5) in Qwik Evolution Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[STAGE-2] incomplete implementation Remove this label when implementation is complete [STAGE-2] not fully covered by tests yet Remove this label when tests are verified to cover the implementation [STAGE-2] unresolved discussions left Remove this label when all critical discussions are resolved on the issue [STAGE-3] docs changes not added yet Remove this label when the necessary documentation for the feature / change is added [STAGE-3] missing 2 reviews for RFC PRs Remove this label when at least 2 core team members reviewed and approved the RFC implementation
Projects
Status: Released as Stable (STAGE 5)
Development

No branches or pull requests

2 participants