Add body scroll lock
This commit is contained in:
@@ -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()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
ImagesLightbox,
|
ImagesLightbox,
|
||||||
ProfileImageLightbox,
|
ProfileImageLightbox,
|
||||||
} from '#/state/lightbox'
|
} from '#/state/lightbox'
|
||||||
|
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
||||||
|
|
||||||
interface Img {
|
interface Img {
|
||||||
uri: string
|
uri: string
|
||||||
@@ -32,8 +33,10 @@ interface Img {
|
|||||||
export function Lightbox() {
|
export function Lightbox() {
|
||||||
const {activeLightbox} = useLightbox()
|
const {activeLightbox} = useLightbox()
|
||||||
const {closeLightbox} = useLightboxControls()
|
const {closeLightbox} = useLightboxControls()
|
||||||
|
const isActive = !!activeLightbox
|
||||||
|
useWebBodyScrollLock(isActive)
|
||||||
|
|
||||||
if (!activeLightbox) {
|
if (!isActive) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {TouchableWithoutFeedback, StyleSheet, View} from 'react-native'
|
|||||||
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
|
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
||||||
|
|
||||||
import {useModals, useModalControls} from '#/state/modals'
|
import {useModals, useModalControls} from '#/state/modals'
|
||||||
import type {Modal as ModalIface} from '#/state/modals'
|
import type {Modal as ModalIface} from '#/state/modals'
|
||||||
@@ -37,6 +38,7 @@ import * as LinkWarningModal from './LinkWarning'
|
|||||||
|
|
||||||
export function ModalsContainer() {
|
export function ModalsContainer() {
|
||||||
const {isModalActive, activeModals} = useModals()
|
const {isModalActive, activeModals} = useModals()
|
||||||
|
useWebBodyScrollLock(isModalActive)
|
||||||
|
|
||||||
if (!isModalActive) {
|
if (!isModalActive) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {ComposePost} from '../com/composer/Composer'
|
|||||||
import {useComposerState} from 'state/shell/composer'
|
import {useComposerState} from 'state/shell/composer'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
|
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
||||||
|
|
||||||
const BOTTOM_BAR_HEIGHT = 61
|
const BOTTOM_BAR_HEIGHT = 61
|
||||||
|
|
||||||
@@ -12,11 +13,13 @@ export function Composer({}: {winHeight: number}) {
|
|||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
const state = useComposerState()
|
const state = useComposerState()
|
||||||
|
const isActive = !!state
|
||||||
|
useWebBodyScrollLock(isActive)
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
// =
|
// =
|
||||||
|
|
||||||
if (!state) {
|
if (!isActive) {
|
||||||
return <View />
|
return <View />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {useAuxClick} from 'lib/hooks/useAuxClick'
|
|||||||
import {t} from '@lingui/macro'
|
import {t} from '@lingui/macro'
|
||||||
import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell'
|
import {useIsDrawerOpen, useSetDrawerOpen} from '#/state/shell'
|
||||||
import {useCloseAllActiveElements} from '#/state/util'
|
import {useCloseAllActiveElements} from '#/state/util'
|
||||||
|
import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock'
|
||||||
|
|
||||||
function ShellInner() {
|
function ShellInner() {
|
||||||
const isDrawerOpen = useIsDrawerOpen()
|
const isDrawerOpen = useIsDrawerOpen()
|
||||||
@@ -23,6 +24,7 @@ function ShellInner() {
|
|||||||
const navigator = useNavigation<NavigationProp>()
|
const navigator = useNavigation<NavigationProp>()
|
||||||
const closeAllActiveElements = useCloseAllActiveElements()
|
const closeAllActiveElements = useCloseAllActiveElements()
|
||||||
|
|
||||||
|
useWebBodyScrollLock(isDrawerOpen)
|
||||||
useAuxClick()
|
useAuxClick()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user