UBER-1159: fixed horizontal scrolling in Scroller (#3945)

Signed-off-by: Alexander Platov <sas_lord@mail.ru>
This commit is contained in:
Alexander Platov 2023-11-07 07:45:16 +03:00 committed by GitHub
parent cbd7e82e8f
commit b77ad4dc4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -162,7 +162,13 @@
const onScroll = (event: MouseEvent): void => {
scrolling = false
if (isScrolling && divBar && divScroll) {
if (
(divBar == null && isScrolling === 'vertical') ||
(divBarH == null && isScrolling === 'horizontal') ||
divScroll == null
) {
return
}
const rectScroll = divScroll.getBoundingClientRect()
if (isScrolling === 'vertical') {
let Y = event.clientY - dXY
@ -189,34 +195,23 @@
divScroll.scrollLeft = (divScroll.scrollWidth - divScroll.clientWidth) * procBar
}
}
}
const onScrollEnd = (event: MouseEvent): void => {
const el: HTMLElement = event.currentTarget as HTMLElement
if (el && isScrolling) {
const onScrollEnd = (): void => {
document.removeEventListener('mousemove', onScroll)
// document.body.style.pointerEvents = 'all'
document.body.style.userSelect = 'auto'
document.body.style.webkitUserSelect = 'auto'
}
document.removeEventListener('mouseup', onScrollEnd)
isScrolling = false
}
const onScrollStart = (event: MouseEvent, direction: 'vertical' | 'horizontal'): void => {
if (divScroll == null) return
scrolling = false
const el: HTMLElement = event.currentTarget as HTMLElement
if (el && divScroll) {
dXY =
direction === 'vertical'
? event.clientY - el.getBoundingClientRect().y
: event.clientX - el.getBoundingClientRect().x
dXY = direction === 'vertical' ? event.offsetY : event.offsetX
document.addEventListener('mouseup', onScrollEnd)
document.addEventListener('mousemove', onScroll)
// document.body.style.pointerEvents = 'none'
document.body.style.userSelect = 'none'
document.body.style.webkitUserSelect = 'none'
isScrolling = direction
}
}
const renderFade = () => {
if (divScroll && !noFade) {
@ -456,7 +451,14 @@
ev: MouseEvent & { currentTarget: EventTarget & HTMLDivElement },
horizontal: boolean = false
) => {
if (!isScrolling && divBar && divScroll) {
if (
(divBar == null && !horizontal) ||
(divBarH == null && horizontal) ||
divScroll == null ||
isScrolling !== false
) {
return
}
const rectScroll = divScroll.getBoundingClientRect()
if (horizontal) {
const x = ev.offsetX
@ -488,7 +490,6 @@
divScroll.scrollTop = (divScroll.scrollHeight - divScroll.clientHeight) * procBar
}
}
}
$: topButton =
(orientir === 'vertical' && (mask === 'top' || mask === 'both')) ||