-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: useScrollEnabled alway false in the bottom tab
- Loading branch information
1 parent
bbcfd4e
commit 3895981
Showing
5 changed files
with
33 additions
and
7 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 |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import {useIsFocused} from '@react-navigation/native'; | ||
import usePrevious from '@hooks/usePrevious'; | ||
import type {EventArg, NavigationContainerEventMap} from '@react-navigation/native'; | ||
import {useEffect, useState} from 'react'; | ||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
import SCREENS from '@src/SCREENS'; | ||
import type UseScrollEnabled from './types'; | ||
|
||
const useScrollEnabled: UseScrollEnabled = () => { | ||
const useScrollEnabled: UseScrollEnabled = (RNScrollEnabled?: boolean) => { | ||
const isFocused = useIsFocused(); | ||
const prevIsFocused = usePrevious(isFocused); | ||
return !(prevIsFocused && !isFocused); | ||
const [isScreenFocused, setIsScreenFocused] = useState(false); | ||
useEffect(() => { | ||
const listener = (event: EventArg<'state', false, NavigationContainerEventMap['state']['data']>) => { | ||
const routName = Navigation.getRouteNameFromStateEvent(event); | ||
if (routName === SCREENS.SEARCH.CENTRAL_PANE || routName === SCREENS.SETTINGS_CENTRAL_PANE || routName === SCREENS.HOME) { | ||
setIsScreenFocused(true); | ||
return; | ||
} | ||
setIsScreenFocused(false); | ||
}; | ||
navigationRef.addListener('state', listener); | ||
return () => navigationRef.removeListener('state', listener); | ||
}, []); | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
|
||
// On the Search, Settings, Home screen, isFocused returns false, but it is actually focused | ||
if (shouldUseNarrowLayout) { | ||
return isFocused || isScreenFocused; | ||
} | ||
|
||
// On desktop screen sizes, isFocused always returns false when useIsFocused is called inside the bottom tab. So, we need to manually set scrollEnabled for ScrollView in this case | ||
return isFocused || RNScrollEnabled; | ||
}; | ||
export default useScrollEnabled; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
type UseScrollEnabled = () => boolean | undefined; | ||
type UseScrollEnabled = (scrollEnabled?: boolean) => boolean | undefined; | ||
|
||
export default UseScrollEnabled; |
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