Remove resetMainScroll

This commit is contained in:
Dan Abramov
2023-12-13 04:52:25 +00:00
parent 9e12ea5143
commit 7c06a4eeb9
3 changed files with 10 additions and 15 deletions
+2 -9
View File
@@ -14,9 +14,7 @@ function clamp(num: number, min: number, max: number) {
return Math.min(Math.max(num, min), max) return Math.min(Math.max(num, min), max)
} }
export type ResetCb = () => void export function useOnMainScroll(): ScrollHandlers<any> {
export function useOnMainScroll(): [ScrollHandlers<any>, ResetCb] {
const {headerHeight} = useShellLayout() const {headerHeight} = useShellLayout()
const mode = useMinimalShellMode() const mode = useMinimalShellMode()
const setMode = useSetMinimalShellMode() const setMode = useSetMinimalShellMode()
@@ -100,10 +98,5 @@ export function useOnMainScroll(): [ScrollHandlers<any>, ResetCb] {
[onBeginDrag, onEndDrag, onScroll], [onBeginDrag, onEndDrag, onScroll],
) )
return [ return scrollHandler
scrollHandler,
useCallback(() => {
setMode(false)
}, [setMode]),
]
} }
+5 -3
View File
@@ -10,6 +10,7 @@ import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' import {useOnMainScroll} from 'lib/hooks/useOnMainScroll'
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 {useSetMinimalShellMode} from '#/state/shell'
import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed' import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed'
import {ComposeIcon2} from 'lib/icons' import {ComposeIcon2} from 'lib/icons'
import {colors, s} from 'lib/styles' import {colors, s} from 'lib/styles'
@@ -53,7 +54,8 @@ export function FeedPage({
const queryClient = useQueryClient() const queryClient = useQueryClient()
const {openComposer} = useComposerControls() const {openComposer} = useComposerControls()
const [isScrolledDown, setIsScrolledDown] = React.useState(false) const [isScrolledDown, setIsScrolledDown] = React.useState(false)
const [onMainScroll, resetMainScroll] = useOnMainScroll() const onMainScroll = useOnMainScroll()
const setMinimalShellMode = useSetMinimalShellMode()
const {screen, track} = useAnalytics() const {screen, track} = useAnalytics()
const headerOffset = useHeaderOffset() const headerOffset = useHeaderOffset()
const scrollElRef = React.useRef<ListMethods>(null) const scrollElRef = React.useRef<ListMethods>(null)
@@ -64,8 +66,8 @@ export function FeedPage({
animated: isNative, animated: isNative,
offset: -headerOffset, offset: -headerOffset,
}) })
resetMainScroll() setMinimalShellMode(false)
}, [headerOffset, resetMainScroll]) }, [headerOffset, setMinimalShellMode])
const onSoftReset = React.useCallback(() => { const onSoftReset = React.useCallback(() => {
const isScreenFocused = const isScreenFocused =
+3 -3
View File
@@ -36,7 +36,7 @@ type Props = NativeStackScreenProps<
export function NotificationsScreen({}: Props) { export function NotificationsScreen({}: Props) {
const {_} = useLingui() const {_} = useLingui()
const setMinimalShellMode = useSetMinimalShellMode() const setMinimalShellMode = useSetMinimalShellMode()
const [onMainScroll, resetMainScroll] = useOnMainScroll() const onMainScroll = useOnMainScroll()
const [isScrolledDown, setIsScrolledDown] = React.useState(false) const [isScrolledDown, setIsScrolledDown] = React.useState(false)
const scrollElRef = React.useRef<ListMethods>(null) const scrollElRef = React.useRef<ListMethods>(null)
const checkLatestRef = React.useRef<() => void | null>() const checkLatestRef = React.useRef<() => void | null>()
@@ -52,8 +52,8 @@ export function NotificationsScreen({}: Props) {
// = // =
const scrollToTop = React.useCallback(() => { const scrollToTop = React.useCallback(() => {
scrollElRef.current?.scrollToOffset({animated: isNative, offset: 0}) scrollElRef.current?.scrollToOffset({animated: isNative, offset: 0})
resetMainScroll() setMinimalShellMode(false)
}, [scrollElRef, resetMainScroll]) }, [scrollElRef, setMinimalShellMode])
const onPressLoadLatest = React.useCallback(() => { const onPressLoadLatest = React.useCallback(() => {
scrollToTop() scrollToTop()