Skip to content

Commit 7fb1dae

Browse files
JiPaixschroda
andauthored
decrease reader's up and down arrows scrolling distance (#588)
* revert reader's up and down arrows behavior * add variant to scrolling shortcuts * remove comments for SCROLL_OFFSET & SCROLL_OFFSET_SLIGHT * Apply suggestions from code review see PR #588 Co-authored-by: schroda <50052685+schroda@users.noreply.github.com> * fix linting --------- Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
1 parent 3077824 commit 7fb1dae

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/components/reader/pager/VerticalPager.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const findCurrentPageIndex = (wrapper: HTMLDivElement): number => {
2525
// TODO: make configurable?
2626
const SCROLL_SAFE_ZONE = 5; // px
2727
const SCROLL_OFFSET = 0.95;
28+
const SCROLL_OFFSET_SLIGHT = 0.25;
2829
const SCROLL_BEHAVIOR: ScrollBehavior = 'smooth';
2930

3031
const isAtBottom = () => {
@@ -111,7 +112,7 @@ export function VerticalPager(props: IReaderProps) {
111112
}, [selfRef]);
112113

113114
const go = useCallback(
114-
(direction: 'up' | 'down') => {
115+
(direction: 'up' | 'down', offset: number = SCROLL_OFFSET) => {
115116
if (direction === 'down' && isAtBottom()) {
116117
nextChapter();
117118
return;
@@ -123,7 +124,7 @@ export function VerticalPager(props: IReaderProps) {
123124
}
124125

125126
window.scroll({
126-
top: window.scrollY + window.innerHeight * SCROLL_OFFSET * (direction === 'up' ? -1 : 1),
127+
top: window.scrollY + window.innerHeight * offset * (direction === 'up' ? -1 : 1),
127128
behavior: SCROLL_BEHAVIOR,
128129
});
129130
},
@@ -138,11 +139,17 @@ export function VerticalPager(props: IReaderProps) {
138139
go(e.shiftKey ? 'up' : 'down');
139140
break;
140141
case 'ArrowDown':
142+
e.preventDefault();
143+
go(e.shiftKey ? 'up' : 'down', SCROLL_OFFSET_SLIGHT);
144+
break;
141145
case 'ArrowRight':
142146
e.preventDefault();
143147
go(e.shiftKey ? 'up' : 'down');
144148
break;
145149
case 'ArrowUp':
150+
e.preventDefault();
151+
go(e.shiftKey ? 'down' : 'up', SCROLL_OFFSET_SLIGHT);
152+
break;
146153
case 'ArrowLeft':
147154
e.preventDefault();
148155
go(e.shiftKey ? 'down' : 'up');

0 commit comments

Comments
 (0)