Cleanup progress bar interaction handling
This commit is contained in:
@@ -109,6 +109,36 @@ const BaseReaderProgressBar = ({
|
|||||||
getOptionForDirection,
|
getOptionForDirection,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleMouseDown = (e: React.MouseEvent | React.TouchEvent) => {
|
||||||
|
if (!progressBarRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isTouchEvent = 'touches' in e;
|
||||||
|
|
||||||
|
openPage(
|
||||||
|
getNextIndexFromPage(
|
||||||
|
getPageForMousePos(
|
||||||
|
isTouchEvent ? e.touches[0] : e,
|
||||||
|
progressBarRef.current.getBoundingClientRect(),
|
||||||
|
pages,
|
||||||
|
isHorizontalPosition,
|
||||||
|
getOptionForDirection,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
clearTimeout(draggingDetectionTimeout.current);
|
||||||
|
draggingDetectionTimeout.current = setTimeout(() => setIsDragging(true), 250);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseUp = () => {
|
||||||
|
setIsDragging(false);
|
||||||
|
clearTimeout(draggingDetectionTimeout.current);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReaderProgressBarContainer {...slotProps?.container} progressBarPosition={progressBarPosition}>
|
<ReaderProgressBarContainer {...slotProps?.container} progressBarPosition={progressBarPosition}>
|
||||||
<ReaderProgressBarRoot {...slotProps?.progressBarRoot}>
|
<ReaderProgressBarRoot {...slotProps?.progressBarRoot}>
|
||||||
@@ -132,58 +162,10 @@ const BaseReaderProgressBar = ({
|
|||||||
<ReaderProgressBarSlotsActionArea
|
<ReaderProgressBarSlotsActionArea
|
||||||
{...slotProps?.progressBarSlotsActionArea}
|
{...slotProps?.progressBarSlotsActionArea}
|
||||||
ref={progressBarRef}
|
ref={progressBarRef}
|
||||||
onTouchEnd={() => {
|
onMouseDown={handleMouseDown}
|
||||||
setIsDragging(false);
|
onMouseUp={handleMouseUp}
|
||||||
clearTimeout(draggingDetectionTimeout.current);
|
onTouchStart={handleMouseDown}
|
||||||
}}
|
onTouchEnd={handleMouseUp}
|
||||||
onTouchStart={(event) => {
|
|
||||||
if (!progressBarRef.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
openPage(
|
|
||||||
getNextIndexFromPage(
|
|
||||||
getPageForMousePos(
|
|
||||||
event.touches[0],
|
|
||||||
progressBarRef.current.getBoundingClientRect(),
|
|
||||||
pages,
|
|
||||||
isHorizontalPosition,
|
|
||||||
getOptionForDirection,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
undefined,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
clearTimeout(draggingDetectionTimeout.current);
|
|
||||||
draggingDetectionTimeout.current = setTimeout(() => setIsDragging(true), 250);
|
|
||||||
}}
|
|
||||||
onMouseUp={() => {
|
|
||||||
setIsDragging(false);
|
|
||||||
clearTimeout(draggingDetectionTimeout.current);
|
|
||||||
}}
|
|
||||||
onMouseDown={(event) => {
|
|
||||||
if (!progressBarRef.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
openPage(
|
|
||||||
getNextIndexFromPage(
|
|
||||||
getPageForMousePos(
|
|
||||||
event,
|
|
||||||
progressBarRef.current.getBoundingClientRect(),
|
|
||||||
pages,
|
|
||||||
isHorizontalPosition,
|
|
||||||
getOptionForDirection,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
undefined,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
clearTimeout(draggingDetectionTimeout.current);
|
|
||||||
draggingDetectionTimeout.current = setTimeout(() => setIsDragging(true), 250);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<ReaderProgressBarSlotsContainer {...slotProps?.progressBarSlotsContainer}>
|
<ReaderProgressBarSlotsContainer {...slotProps?.progressBarSlotsContainer}>
|
||||||
{pages.map((page, pagesIndex) => (
|
{pages.map((page, pagesIndex) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user