Add hotkeys to switch auto scroll direction
While auto scroll is active, the direction can be changed via the "scroll backward/forward" hotkeys
This commit is contained in:
@@ -94,8 +94,16 @@ export const ReaderHotkeys = ({
|
|||||||
useHotkeys(hotkeys[ReaderHotkey.NEXT_PAGE], () => openPage('next'), [openPage]);
|
useHotkeys(hotkeys[ReaderHotkey.NEXT_PAGE], () => openPage('next'), [openPage]);
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
hotkeys[ReaderHotkey.SCROLL_BACKWARD],
|
hotkeys[ReaderHotkey.SCROLL_BACKWARD],
|
||||||
() =>
|
() => {
|
||||||
scrollElementRef.current &&
|
if (automaticScrolling.isActive) {
|
||||||
|
automaticScrolling.setDirection(ScrollOffset.BACKWARD);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scrollElementRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ReaderControls.scroll(
|
ReaderControls.scroll(
|
||||||
ScrollOffset.BACKWARD,
|
ScrollOffset.BACKWARD,
|
||||||
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
|
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
|
||||||
@@ -107,14 +115,30 @@ export const ReaderHotkeys = ({
|
|||||||
setIsOverlayVisible,
|
setIsOverlayVisible,
|
||||||
setShowPreview,
|
setShowPreview,
|
||||||
scrollAmount,
|
scrollAmount,
|
||||||
),
|
);
|
||||||
|
},
|
||||||
{ preventDefault: true },
|
{ preventDefault: true },
|
||||||
[readingMode.value, readingDirection.value, themeDirection, openChapter, scrollAmount],
|
[
|
||||||
|
readingMode.value,
|
||||||
|
readingDirection.value,
|
||||||
|
themeDirection,
|
||||||
|
openChapter,
|
||||||
|
scrollAmount,
|
||||||
|
automaticScrolling.isActive,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
hotkeys[ReaderHotkey.SCROLL_FORWARD],
|
hotkeys[ReaderHotkey.SCROLL_FORWARD],
|
||||||
() =>
|
() => {
|
||||||
scrollElementRef.current &&
|
if (automaticScrolling.isActive) {
|
||||||
|
automaticScrolling.setDirection(ScrollOffset.FORWARD);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scrollElementRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ReaderControls.scroll(
|
ReaderControls.scroll(
|
||||||
ScrollOffset.FORWARD,
|
ScrollOffset.FORWARD,
|
||||||
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
|
CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION[readingMode.value],
|
||||||
@@ -126,9 +150,17 @@ export const ReaderHotkeys = ({
|
|||||||
setIsOverlayVisible,
|
setIsOverlayVisible,
|
||||||
setShowPreview,
|
setShowPreview,
|
||||||
scrollAmount,
|
scrollAmount,
|
||||||
),
|
);
|
||||||
|
},
|
||||||
{ preventDefault: true },
|
{ preventDefault: true },
|
||||||
[readingMode.value, readingDirection.value, themeDirection, openChapter, scrollAmount],
|
[
|
||||||
|
readingMode.value,
|
||||||
|
readingDirection.value,
|
||||||
|
themeDirection,
|
||||||
|
openChapter,
|
||||||
|
scrollAmount,
|
||||||
|
automaticScrolling.isActive,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
hotkeys[ReaderHotkey.PREVIOUS_CHAPTER],
|
hotkeys[ReaderHotkey.PREVIOUS_CHAPTER],
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const ReaderAutoScrollContext = createContext<TReaderAutoScrollContext>({
|
|||||||
toggleActive: () => {},
|
toggleActive: () => {},
|
||||||
pause: () => {},
|
pause: () => {},
|
||||||
resume: () => {},
|
resume: () => {},
|
||||||
|
setDirection: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useReaderAutoScrollContext = () => useContext(ReaderAutoScrollContext);
|
export const useReaderAutoScrollContext = () => useContext(ReaderAutoScrollContext);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import { isContinuousReadingMode } from '@/modules/reader/utils/ReaderSettings.u
|
|||||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||||
import { CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION } from '@/modules/reader/constants/ReaderSettings.constants.tsx';
|
import { CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION } from '@/modules/reader/constants/ReaderSettings.constants.tsx';
|
||||||
|
import { ScrollOffset } from '@/modules/core/Core.types.ts';
|
||||||
|
import { getOptionForDirection } from '@/modules/theme/services/ThemeCreator.ts';
|
||||||
|
|
||||||
const BaseReaderAutoScrollContextProvider = ({
|
const BaseReaderAutoScrollContextProvider = ({
|
||||||
children,
|
children,
|
||||||
@@ -36,8 +38,17 @@ const BaseReaderAutoScrollContextProvider = ({
|
|||||||
combinedDirection: Direction;
|
combinedDirection: Direction;
|
||||||
}) => {
|
}) => {
|
||||||
const [scrollRef, setScrollRef] = useState<TReaderAutoScrollContext['scrollRef']>();
|
const [scrollRef, setScrollRef] = useState<TReaderAutoScrollContext['scrollRef']>();
|
||||||
|
const [direction, setDirection] = useState<ScrollOffset>(ScrollOffset.FORWARD);
|
||||||
|
|
||||||
const invertScrolling = readingMode === ReadingMode.CONTINUOUS_HORIZONTAL && themeDirection !== combinedDirection;
|
const isScrollingInvertedBasedOnReadingDirection =
|
||||||
|
readingMode === ReadingMode.CONTINUOUS_HORIZONTAL && themeDirection !== combinedDirection;
|
||||||
|
const invertScrolling = isScrollingInvertedBasedOnReadingDirection
|
||||||
|
? getOptionForDirection(
|
||||||
|
direction === ScrollOffset.BACKWARD,
|
||||||
|
direction === ScrollOffset.FORWARD,
|
||||||
|
combinedDirection,
|
||||||
|
)
|
||||||
|
: direction === ScrollOffset.BACKWARD;
|
||||||
const isContinuousReadingModeActive = isContinuousReadingMode(readingMode);
|
const isContinuousReadingModeActive = isContinuousReadingMode(readingMode);
|
||||||
|
|
||||||
const changePage = useCallback(() => {
|
const changePage = useCallback(() => {
|
||||||
@@ -57,6 +68,7 @@ const BaseReaderAutoScrollContextProvider = ({
|
|||||||
() => ({
|
() => ({
|
||||||
scrollRef,
|
scrollRef,
|
||||||
setScrollRef,
|
setScrollRef,
|
||||||
|
setDirection,
|
||||||
...automaticScrolling,
|
...automaticScrolling,
|
||||||
}),
|
}),
|
||||||
[scrollRef, automaticScrolling],
|
[scrollRef, automaticScrolling],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types
|
|||||||
import { TMangaReader } from '@/modules/manga/Manga.types.ts';
|
import { TMangaReader } from '@/modules/manga/Manga.types.ts';
|
||||||
import { useAutomaticScrolling } from '@/modules/core/hooks/useAutomaticScrolling.ts';
|
import { useAutomaticScrolling } from '@/modules/core/hooks/useAutomaticScrolling.ts';
|
||||||
import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts';
|
import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts';
|
||||||
|
import { ScrollOffset } from '@/modules/core/Core.types.ts';
|
||||||
|
|
||||||
export enum ProgressBarType {
|
export enum ProgressBarType {
|
||||||
HIDDEN,
|
HIDDEN,
|
||||||
@@ -361,6 +362,7 @@ export type TReaderAutoScrollContext = ReturnType<typeof useAutomaticScrolling>
|
|||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
scrollRef?: MutableRefObject<HTMLElement | null> | (() => void);
|
scrollRef?: MutableRefObject<HTMLElement | null> | (() => void);
|
||||||
setScrollRef: (scrollRef?: MutableRefObject<HTMLElement | null>) => void;
|
setScrollRef: (scrollRef?: MutableRefObject<HTMLElement | null>) => void;
|
||||||
|
setDirection: (direction: ScrollOffset) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ReaderPageSpreadState = { url: string; isSpread: boolean };
|
export type ReaderPageSpreadState = { url: string; isSpread: boolean };
|
||||||
|
|||||||
Reference in New Issue
Block a user