Cleanup ReaderControls#scroll
This commit is contained in:
@@ -131,38 +131,35 @@ export class ReaderControls {
|
|||||||
setIsOverlayVisible(false);
|
setIsOverlayVisible(false);
|
||||||
setShowPreview(false);
|
setShowPreview(false);
|
||||||
|
|
||||||
switch (direction) {
|
const doScroll = (
|
||||||
case ScrollDirection.X:
|
isAtStartForDirection: boolean,
|
||||||
if (isAtStartXForDirection && offset === ScrollOffset.BACKWARD && isContinuousReadingModeActive) {
|
isAtEndForDirection: boolean,
|
||||||
|
scrollToOptions: ScrollToOptions,
|
||||||
|
) => {
|
||||||
|
if (isAtStartForDirection && offset === ScrollOffset.BACKWARD && isContinuousReadingModeActive) {
|
||||||
openChapter('previous');
|
openChapter('previous');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAtEndXForDirection && offset === ScrollOffset.FORWARD && isContinuousReadingModeActive) {
|
if (isAtEndForDirection && offset === ScrollOffset.FORWARD && isContinuousReadingModeActive) {
|
||||||
openChapter('next');
|
openChapter('next');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
element.scroll({
|
element.scroll({
|
||||||
left: getNewScrollPosition(element.scrollLeft, element.clientWidth),
|
...scrollToOptions,
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case ScrollDirection.X:
|
||||||
|
doScroll(isAtStartXForDirection, isAtEndXForDirection, {
|
||||||
|
left: getNewScrollPosition(element.scrollLeft, element.clientWidth),
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case ScrollDirection.Y:
|
case ScrollDirection.Y:
|
||||||
if (isAtStartY && offset === ScrollOffset.BACKWARD && isContinuousReadingModeActive) {
|
doScroll(isAtStartY, isAtEndY, { top: getNewScrollPosition(element.scrollTop, element.clientHeight) });
|
||||||
openChapter('previous');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAtEndY && offset === ScrollOffset.FORWARD && isContinuousReadingModeActive) {
|
|
||||||
openChapter('next');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
element.scroll({
|
|
||||||
top: getNewScrollPosition(element.scrollTop, element.clientHeight),
|
|
||||||
behavior: 'smooth',
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected "ScrollDirection" (${direction})`);
|
throw new Error(`Unexpected "ScrollDirection" (${direction})`);
|
||||||
|
|||||||
Reference in New Issue
Block a user