fix(app): don't show scroll to bottom if no scroll
This commit is contained in:
@@ -30,6 +30,10 @@ export function createAutoScroll(options: AutoScrollOptions) {
|
|||||||
return el.scrollHeight - el.clientHeight - el.scrollTop
|
return el.scrollHeight - el.clientHeight - el.scrollTop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const canScroll = (el: HTMLElement) => {
|
||||||
|
return el.scrollHeight - el.clientHeight > 1
|
||||||
|
}
|
||||||
|
|
||||||
// Browsers can dispatch scroll events asynchronously. If new content arrives
|
// Browsers can dispatch scroll events asynchronously. If new content arrives
|
||||||
// between us calling `scrollTo()` and the subsequent `scroll` event firing,
|
// between us calling `scrollTo()` and the subsequent `scroll` event firing,
|
||||||
// the handler can see a non-zero `distanceFromBottom` and incorrectly assume
|
// the handler can see a non-zero `distanceFromBottom` and incorrectly assume
|
||||||
@@ -89,6 +93,12 @@ export function createAutoScroll(options: AutoScrollOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
|
const el = scroll
|
||||||
|
if (!el) return
|
||||||
|
if (!canScroll(el)) {
|
||||||
|
if (store.userScrolled) setStore("userScrolled", false)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (store.userScrolled) return
|
if (store.userScrolled) return
|
||||||
|
|
||||||
setStore("userScrolled", true)
|
setStore("userScrolled", true)
|
||||||
@@ -111,6 +121,11 @@ export function createAutoScroll(options: AutoScrollOptions) {
|
|||||||
const el = scroll
|
const el = scroll
|
||||||
if (!el) return
|
if (!el) return
|
||||||
|
|
||||||
|
if (!canScroll(el)) {
|
||||||
|
if (store.userScrolled) setStore("userScrolled", false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (distanceFromBottom(el) < threshold()) {
|
if (distanceFromBottom(el) < threshold()) {
|
||||||
if (store.userScrolled) setStore("userScrolled", false)
|
if (store.userScrolled) setStore("userScrolled", false)
|
||||||
return
|
return
|
||||||
@@ -149,6 +164,11 @@ export function createAutoScroll(options: AutoScrollOptions) {
|
|||||||
createResizeObserver(
|
createResizeObserver(
|
||||||
() => store.contentRef,
|
() => store.contentRef,
|
||||||
() => {
|
() => {
|
||||||
|
const el = scroll
|
||||||
|
if (el && !canScroll(el)) {
|
||||||
|
if (store.userScrolled) setStore("userScrolled", false)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!active()) return
|
if (!active()) return
|
||||||
if (store.userScrolled) return
|
if (store.userScrolled) return
|
||||||
// ResizeObserver fires after layout, before paint.
|
// ResizeObserver fires after layout, before paint.
|
||||||
@@ -159,7 +179,7 @@ export function createAutoScroll(options: AutoScrollOptions) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(options.working, (working) => {
|
on(options.working, (working: boolean) => {
|
||||||
settling = false
|
settling = false
|
||||||
if (settleTimer) clearTimeout(settleTimer)
|
if (settleTimer) clearTimeout(settleTimer)
|
||||||
settleTimer = undefined
|
settleTimer = undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user