fix: stabilize minimalShellMode toggling by introducing modified thresholds (supersedes #938) (#942)

* add separate scroll up/down thresholds to prevent rapid state changes

* set `DY_LIMIT_DOWN` to 150

* Use a different scroll dy limit on web/mobile

---------

Co-authored-by: Sehyun Chung <sehyun.chung@icloud.com>
zio/stable
Paul Frazee 2023-07-02 15:03:16 -05:00 committed by GitHub
parent 7ee7d968e5
commit 97f0d3431c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 6 deletions

View File

@ -4,7 +4,8 @@ import {RootStoreModel} from 'state/index'
import {s} from 'lib/styles'
import {isDesktopWeb} from 'platform/detection'
const DY_LIMIT = isDesktopWeb ? 30 : 10
const DY_LIMIT_UP = isDesktopWeb ? 30 : 10
const DY_LIMIT_DOWN = isDesktopWeb ? 150 : 10
export type OnScrollCb = (
event: NativeSyntheticEvent<NativeScrollEvent>,
@ -23,12 +24,9 @@ export function useOnMainScroll(
const dy = y - (lastY.current || 0)
lastY.current = y
if (!store.shell.minimalShellMode && y > 10 && dy > DY_LIMIT) {
if (!store.shell.minimalShellMode && dy > DY_LIMIT_DOWN) {
store.shell.setMinimalShellMode(true)
} else if (
store.shell.minimalShellMode &&
(y <= 10 || dy < DY_LIMIT * -1)
) {
} else if (store.shell.minimalShellMode && dy < DY_LIMIT_UP * -1) {
store.shell.setMinimalShellMode(false)
}