Skip to content

Commit

Permalink
Disable auto-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Mar 17, 2019
1 parent 2543dfb commit 84799e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ export default function Scroller({
});
}, []);

React.useLayoutEffect(() => {
dispatch({
type: "change-area",
recalculate: true,
changeIndex: closestIndex
});
}, [snapAreas]);
// Auto-scroll to closest change when changing versions:
// React.useLayoutEffect(() => {
// dispatch({
// type: "change-area",
// recalculate: true,
// changeIndex: closestIndex
// });
// }, [snapAreas]);

React.useLayoutEffect(() => {
if (snap) {
Expand Down
3 changes: 2 additions & 1 deletion src/scroller.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const snapAreas1 = [
const snapAreas2 = [
{ start: 8, end: 12 },
{ start: 30, end: 32 },
{ start: 550, end: 552 }
{ start: 550, end: 552 },
{ start: 595, end: 599 }
];

const items = Array(600)
Expand Down
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function getScrollTop(area, contentHeight, containerHeight, heights) {
const bestTop =
end - start > containerHeight ? start : middle - halfContainer;
if (bestTop < 0) return 0;
if (bestTop + containerHeight > contentHeight)
return containerHeight - contentHeight;
if (bestTop + containerHeight > contentHeight) {
return contentHeight - containerHeight;
}
return bestTop;
}

0 comments on commit 84799e6

Please sign in to comment.