fix(app): auto-scroll
This commit is contained in:
@@ -524,6 +524,15 @@ export default function Page() {
|
|||||||
|
|
||||||
const scrollGestureWindowMs = 250
|
const scrollGestureWindowMs = 250
|
||||||
|
|
||||||
|
const scrollIgnoreWindowMs = 250
|
||||||
|
let scrollIgnore = 0
|
||||||
|
|
||||||
|
const markScrollIgnore = () => {
|
||||||
|
scrollIgnore = Date.now()
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasScrollIgnore = () => Date.now() - scrollIgnore < scrollIgnoreWindowMs
|
||||||
|
|
||||||
const markScrollGesture = (target?: EventTarget | null) => {
|
const markScrollGesture = (target?: EventTarget | null) => {
|
||||||
const root = scroller
|
const root = scroller
|
||||||
if (!root) return
|
if (!root) return
|
||||||
@@ -1341,7 +1350,9 @@ export default function Page() {
|
|||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const delta = el.scrollHeight - beforeHeight
|
const delta = el.scrollHeight - beforeHeight
|
||||||
if (delta) el.scrollTop = beforeTop + delta
|
if (!delta) return
|
||||||
|
markScrollIgnore()
|
||||||
|
el.scrollTop = beforeTop + delta
|
||||||
})
|
})
|
||||||
|
|
||||||
scheduleTurnBackfill()
|
scheduleTurnBackfill()
|
||||||
@@ -1378,6 +1389,7 @@ export default function Page() {
|
|||||||
|
|
||||||
if (stick && el) {
|
if (stick && el) {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
|
markScrollIgnore()
|
||||||
el.scrollTo({ top: el.scrollHeight, behavior: "auto" })
|
el.scrollTo({ top: el.scrollHeight, behavior: "auto" })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1779,8 +1791,9 @@ export default function Page() {
|
|||||||
markScrollGesture(e.target)
|
markScrollGesture(e.target)
|
||||||
}}
|
}}
|
||||||
onScroll={(e) => {
|
onScroll={(e) => {
|
||||||
autoScroll.handleScroll()
|
const gesture = hasScrollGesture()
|
||||||
if (!hasScrollGesture()) return
|
if (!hasScrollIgnore() || gesture) autoScroll.handleScroll()
|
||||||
|
if (!gesture) return
|
||||||
markScrollGesture(e.target)
|
markScrollGesture(e.target)
|
||||||
if (isDesktop()) scheduleScrollSpy(e.currentTarget)
|
if (isDesktop()) scheduleScrollSpy(e.currentTarget)
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user