diff options
author | Paul Frazee <pfrazee@gmail.com> | 2024-01-22 15:04:41 -0800 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2024-01-22 15:04:41 -0800 |
commit | d25b17ab19e7373b4463be13b8611997b3f028dd (patch) | |
tree | a4dff6d920f5cb72d1bd9177c2503a8ee7485019 /src/lib/hooks/useWebBodyScrollLock.ts | |
parent | ad018d8dbd9353af2a66a0b21a232ee3225bbcf8 (diff) | |
parent | d51ad1fec94ef933eafe0e5f58fba810e349494b (diff) | |
download | voidsky-d25b17ab19e7373b4463be13b8611997b3f028dd.tar.zst |
Merge branch 'main' of github.com:bluesky-social/social-app into main
Diffstat (limited to 'src/lib/hooks/useWebBodyScrollLock.ts')
-rw-r--r-- | src/lib/hooks/useWebBodyScrollLock.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/hooks/useWebBodyScrollLock.ts b/src/lib/hooks/useWebBodyScrollLock.ts new file mode 100644 index 000000000..585f193f1 --- /dev/null +++ b/src/lib/hooks/useWebBodyScrollLock.ts @@ -0,0 +1,28 @@ +import {useEffect} from 'react' +import {isWeb} from '#/platform/detection' + +let refCount = 0 + +function incrementRefCount() { + if (refCount === 0) { + document.body.style.overflow = 'hidden' + } + refCount++ +} + +function decrementRefCount() { + refCount-- + if (refCount === 0) { + document.body.style.overflow = '' + } +} + +export function useWebBodyScrollLock(isLockActive: boolean) { + useEffect(() => { + if (!isWeb || !isLockActive) { + return + } + incrementRefCount() + return () => decrementRefCount() + }) +} |