Skip to content

Commit

Permalink
📺 playsite: Remove slide back transition on navigation (#442)
Browse files Browse the repository at this point in the history
When navigating to the next playground sample or lab challenge while on
the output view on mobile, we had this awkward: slide back to notes or
code first, than load new code. It seems more natural and intuitive to
just load the new contents - so for hashChange transition remove
animation by adding and eventually removing a CSS class that sets the
translate transition duration for the main container to 0 seconds.

Pull-request: #442
  • Loading branch information
juliaogris authored Sep 16, 2024
1 parent 3bda735 commit 4486ea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion frontend/play/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,14 @@ button.share > div {
.main .editor-wrap {
margin-top: 4px;
}
.main.no-translate-transition {
transition: translate 0s;
}
}

@media (prefers-reduced-motion) {
.main {
transition: translate 0s ease-in-out 0.1s;
transition: translate 0s;
}
.main.animate {
animation: fadein 0.2s ease-in forwards;
Expand Down
7 changes: 6 additions & 1 deletion frontend/play/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ function loadSession() {
// If notes are available, navigates to the notes view.
// If no notes but the editor is present, switches to the code view.
// Otherwise, defaults to the output view
function resetView() {
async function resetView() {
const mainClassList = document.querySelector("main.main").classList
mainClassList.add("no-translate-transition")
const showNotesBtn = document.querySelector("#show-notes")
if (showNotesBtn) showNotesBtn.classList.add("hidden")
if (!notesHidden) {
Expand All @@ -490,6 +492,9 @@ function resetView() {
} else {
setView("view-output")
}
// sleep for 0.3 seconds, otherwise translate transition kicks in.
await new Promise((r) => setTimeout(r, 300))
mainClassList.remove("no-translate-transition")
}

function updateNotes(notes) {
Expand Down

0 comments on commit 4486ea9

Please sign in to comment.