Skip to content

Commit 509e69f

Browse files
authored
[core - v2.2.9] : Update - Device driven background scroll control (#992)
* Refactor scroll handling to be device specific * Refactor for cleanliness * replace removeEventHandler and refactor * Revert demo change * Merge in new develop branch as base
1 parent b63b141 commit 509e69f

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.2.8",
3+
"version": "2.2.9-alpha.1",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",

packages/core/src/views/shared/Modal.svelte

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,37 @@
1616
<script lang="ts">
1717
import { fade } from 'svelte/transition'
1818
import { onDestroy, onMount } from 'svelte'
19+
import { getDevice } from '../../utils'
20+
21+
const device = getDevice()
1922
2023
const body = document.body
21-
onMount(() => {
22-
window.addEventListener(
23-
'scroll',
24-
() => {
25-
document.documentElement.style.setProperty(
26-
'--scroll-y',
27-
`${window.scrollY}px`
28-
)
29-
},
30-
{ passive: true }
24+
const html = document.documentElement
25+
const trackYScrollPosition = () => {
26+
document.documentElement.style.setProperty(
27+
'--scroll-y',
28+
`${window.scrollY}px`
3129
)
32-
const scrollY =
33-
document.documentElement.style.getPropertyValue('--scroll-y')
34-
body.style.position = 'fixed'
30+
}
31+
32+
onMount(() => {
33+
window.addEventListener('scroll', trackYScrollPosition, { passive: true })
34+
const scrollY = html.style.getPropertyValue('--scroll-y')
35+
device.type === 'mobile'
36+
? (html.style.position = 'fixed')
37+
: (html.style.overflow = 'hidden')
38+
3539
body.style.top = `-${scrollY}`
3640
})
3741
3842
onDestroy(() => {
43+
device.type === 'mobile'
44+
? (html.style.position = '')
45+
: (html.style.overflow = 'auto')
3946
const scrollY = body.style.top
40-
body.style.position = ''
4147
body.style.top = ''
4248
window.scrollTo(0, parseInt(scrollY || '0') * -1)
49+
window.removeEventListener('scroll', trackYScrollPosition)
4350
})
4451
export let close: () => void
4552
</script>

packages/react/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.1.6",
3+
"version": "2.1.7-alpha.1",
44
"description": "Collection of React Hooks for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",
@@ -21,8 +21,8 @@
2121
"typescript": "^4.5.5"
2222
},
2323
"dependencies": {
24-
"@web3-onboard/common": "^2.0.7",
25-
"@web3-onboard/core": "^2.2.7"
24+
"@web3-onboard/core": "^2.2.9-alpha.1",
25+
"@web3-onboard/common": "^2.0.7"
2626
},
2727
"peerDependencies": {
2828
"react": "^17.0.2"

0 commit comments

Comments
 (0)