Fix scroll navigation

This commit is contained in:
Rodrigo Pombo 2019-03-18 17:28:54 -03:00
parent f11002e599
commit 8ca216e4f2
2 changed files with 15 additions and 1 deletions

View File

@ -105,5 +105,11 @@ export function getChanges(lines) {
i++;
}
if (currentChange) {
currentChange.end = i - 1;
changes.push(currentChange);
currentChange = null;
}
return changes;
}

View File

@ -2,7 +2,7 @@ import React from "react";
import useChildren from "./use-virtual-children";
import "./scroller.css";
import useSpring from "./use-spring";
import { nextIndex, prevIndex, closestIndex, getScrollTop } from "./utils";
import { nextIndex, prevIndex, getScrollTop } from "./utils";
const initialState = {
snap: false,
@ -23,6 +23,8 @@ export default function Scroller({
const reducer = (prevState, action) => {
switch (action.type) {
case "unsnap":
return !prevState.snap ? prevState : { ...prevState, snap: false };
case "change-area":
if (snapAreas.length === 0) {
return prevState;
@ -129,6 +131,12 @@ export default function Scroller({
// });
// }, [snapAreas]);
React.useEffect(() => {
dispatch({
type: "unsnap"
});
}, [snapAreas]);
React.useLayoutEffect(() => {
if (snap) {
ref.current.scrollTop = top;