Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
fix: update scroll position after the new page is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Barnes committed Mar 27, 2019
1 parent 6fc3af5 commit 36e5000
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/TransitionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class TransitionHandler extends Component {
pathname,
updateContext,
triggerResolve,
appearAfter: getMs(appearAfter),
e
})
}
Expand Down
15 changes: 14 additions & 1 deletion src/functions/onEnter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { setTimeout } from "requestanimationframe-timer";

const onEnter = ({
node,
inTransition,
Expand All @@ -6,10 +8,14 @@ const onEnter = ({
exitProps,
triggerResolve,
pathname,
entryProps: { delay = 0 },
appearAfter = 0,
e
}) => {
if (inTransition) {
window.scrollTo(0, 0);
setTimeout(() => {
window.scrollTo(0, 0);
}, appearAfter);
} else {
const storageKey = `@@scroll|${pathname}`;
const savedPosition = sessionStorage.getItem(storageKey);
Expand All @@ -20,8 +26,15 @@ const onEnter = ({

const { trigger: removed, ...entryPropsTrimmed } = entryProps;

const timeout = appearAfter + delay;

const visiblePromise = new Promise(resolve => {
setTimeout(() => resolve(), timeout);
});

triggerResolve.entry({
...entryPropsTrimmed,
visible: visiblePromise,
node
});

Expand Down

0 comments on commit 36e5000

Please sign in to comment.