mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Experiment with cross-document view transitions in Twenty Fifteen theme #8026
Draft
felixarntz
wants to merge
1
commit into
WordPress:trunk
Choose a base branch
from
felixarntz:experiment/2015-view-transitions
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/wp-content/themes/twentyfifteen/css/view-transitions.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@view-transition { | ||
navigation: auto; | ||
} | ||
|
||
::view-transition-group(*) { | ||
animation-duration: 1s; | ||
} | ||
|
||
@keyframes slide-in-from-left { | ||
from { | ||
translate: -100vw 0; | ||
} | ||
} | ||
|
||
@keyframes slide-in-from-right { | ||
from { | ||
translate: 100vw 0; | ||
} | ||
} | ||
|
||
@keyframes slide-out-to-left { | ||
to { | ||
translate: -100vw 0; | ||
} | ||
} | ||
|
||
@keyframes slide-out-to-right { | ||
to { | ||
translate: 100vw 0; | ||
} | ||
} | ||
|
||
html:active-view-transition-type(forwards, backwards) { | ||
:root { | ||
view-transition-name: none; | ||
} | ||
main { | ||
view-transition-name: main; | ||
} | ||
} | ||
|
||
html:active-view-transition-type(forwards) { | ||
&::view-transition-old(main) { | ||
animation-name: slide-out-to-left; | ||
} | ||
&::view-transition-new(main) { | ||
animation-name: slide-in-from-right; | ||
} | ||
} | ||
|
||
html:active-view-transition-type(backwards) { | ||
&::view-transition-old(main) { | ||
animation-name: slide-out-to-right; | ||
} | ||
&::view-transition-new(main) { | ||
animation-name: slide-in-from-left; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/wp-content/themes/twentyfifteen/js/view-transitions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// TODO: Check for `!! window.navigation && 'CSSViewTransitionRule' in window`. | ||
|
||
const determineTransitionType = ( oldNavigationEntry, newNavigationEntry ) => { | ||
if ( ! oldNavigationEntry || ! newNavigationEntry ) { | ||
return 'unknown'; | ||
} | ||
|
||
const currentURL = new URL( oldNavigationEntry.url ); | ||
const destinationURL = new URL( newNavigationEntry.url ); | ||
|
||
const currentPathname = currentURL.pathname; | ||
const destinationPathname = destinationURL.pathname; | ||
|
||
if ( currentPathname !== destinationPathname ) { | ||
// If post URLs start with a date, use that to determine "order". | ||
const currentDateMatches = currentPathname.match( /^\/(\d{4})\/(\d{2})\/(\d{2})\// ); | ||
const destinationDateMatches = destinationPathname.match( /^\/(\d{4})\/(\d{2})\/(\d{2})\// ); | ||
console.log( currentPathname ); | ||
console.log( destinationPathname ); | ||
if ( currentDateMatches && destinationDateMatches ) { | ||
const currentDate = new Date( parseInt( currentDateMatches[ 1 ] ), parseInt( currentDateMatches[ 2 ] ) - 1, parseInt( currentDateMatches[ 3 ] ) ); | ||
const destinationDate = new Date( parseInt( destinationDateMatches[ 1 ] ), parseInt( destinationDateMatches[ 2 ] ) - 1, parseInt( destinationDateMatches[ 3 ] ) ); | ||
if ( currentDate < destinationDate ) { | ||
return 'forwards'; | ||
} | ||
if ( currentDate > destinationDate ) { | ||
return 'backwards'; | ||
} | ||
return 'unknown'; | ||
} | ||
|
||
// Otherwise, check URL "hierarchy". | ||
if ( destinationPathname.startsWith( currentPathname ) ) { | ||
return 'forwards'; | ||
} | ||
if ( currentPathname.startsWith( destinationPathname ) ) { | ||
return 'backwards'; | ||
} | ||
} | ||
|
||
return 'unknown'; | ||
}; | ||
|
||
window.addEventListener( 'pageswap', async ( e ) => { | ||
if ( e.viewTransition ) { | ||
const transitionType = determineTransitionType( e.activation.from, e.activation.entry ); | ||
|
||
console.log( `pageSwap: ${ transitionType }` ); | ||
e.viewTransition.types.add( transitionType ); | ||
} | ||
} ); | ||
|
||
window.addEventListener( 'pagereveal', async ( e ) => { | ||
console.log( 'pageRevealEvent', e ); | ||
if ( e.viewTransition ) { | ||
const transitionType = determineTransitionType( navigation.activation.from, navigation.activation.entry ); | ||
|
||
console.log( `pageReveal: ${ transitionType }` ); | ||
e.viewTransition.types.add( transitionType ); | ||
} | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, the
pagereveal
event is not fired in most of my page loads. I "randomly" see it fired, but rarely - no idea where that comes from.I added the
pageRevealEvent
console log to ensure it has nothing to do with thee.viewTransition
check below, so it's indeed the event itself that is not fired.🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only see it fired when using the back/forward buttons in the browser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that the scripts that adds the event listener is called too late. It has to be added before the first rendering opportunity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also seeing that MDN doesn't talk much about this, mind filing an issue?
pagereveal
event listeners need to be added in either:blocking=render
, either module or classic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @bramus, perhaps the cross-document view-transition official chromium docs should mention this if they don't already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping @noamr. It’s not mentioned in our docs either (but all demos do use it that way). I remember being bitten by this myself, so would indeed be good to have some extra notices around this.