-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1360: EVM Design. Home page. Custom App Scroll
- Loading branch information
Showing
8 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
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
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,39 @@ | ||
import React, { FC, useLayoutEffect, useRef } from 'react'; | ||
|
||
import * as Woozie from 'lib/woozie'; | ||
|
||
interface Props extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {} | ||
|
||
let SCROLL_RESTORATION = new Map<string, number>(); | ||
const MEMOIZED_SCROLLS_LIMIT = 10; | ||
|
||
export const ScrollRestorer: FC<PropsWithChildren<Props>> = props => { | ||
const { trigger, href } = Woozie.useLocation(); | ||
|
||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useLayoutEffect(() => { | ||
// Only 'popstate' to location restores scroll position | ||
// Other navigation ways discard previous memoized position | ||
if (trigger !== 'popstate') return void SCROLL_RESTORATION.delete(href); | ||
|
||
if (SCROLL_RESTORATION.size > MEMOIZED_SCROLLS_LIMIT) { | ||
const slicedArray = Array.from(SCROLL_RESTORATION.entries()).slice( | ||
SCROLL_RESTORATION.size - MEMOIZED_SCROLLS_LIMIT | ||
); | ||
SCROLL_RESTORATION = new Map(slicedArray); | ||
} | ||
|
||
if (!ref.current) return; | ||
|
||
const scrollTop = SCROLL_RESTORATION.get(href); | ||
if (scrollTop == null) return; | ||
ref.current.scrollTop = scrollTop; | ||
}, [trigger, href]); | ||
|
||
return <div ref={ref} onScroll={onScroll} {...props} />; | ||
}; | ||
|
||
function onScroll(event: React.UIEvent<HTMLDivElement>) { | ||
SCROLL_RESTORATION.set(window.location.href, event.currentTarget.scrollTop); | ||
} |
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,7 @@ | ||
body, #root, #app-content-wrap { | ||
height: 100%; | ||
} | ||
|
||
#app-content-wrap { | ||
display: flex; | ||
} |
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
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
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
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 |
---|---|---|
|
@@ -9,7 +9,6 @@ html { | |
} | ||
|
||
body { | ||
/* min-height: calc(100vh + 1px); */ | ||
min-height: 100%; | ||
} | ||
|
||
|
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