diff --git a/src/components/App.tsx b/src/components/App.tsx index ca47a64bf2..fee2694895 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -2008,6 +2008,31 @@ class App extends React.Component { this.files, ); } + + if ( + this.state.scrollConstraints && + this.state.scrollConstraints.isAnimating + ) { + const { shouldAnimate, animateTo } = constrainScrollState(this.state); + + scrollConstraintsAnimationTimeout = setTimeout(() => { + this.cancelInProgresAnimation?.(); + if (shouldAnimate && animateTo) { + const fromValues = { + scrollX: this.state.scrollX, + scrollY: this.state.scrollY, + zoom: this.state.zoom.value, + }; + const toValues = { + scrollX: animateTo.scrollX, + scrollY: animateTo.scrollY, + zoom: animateTo.zoom.value, + }; + + this.animateToConstrainedArea(fromValues, toValues); + } + }, 200); + } } private renderInteractiveSceneCallback = ({ @@ -2683,25 +2708,14 @@ class App extends React.Component { }), }; - const { state, shouldAnimate, animateTo } = constrainScrollState(newState); + const { state, shouldAnimate } = constrainScrollState(newState); - this.setState(state, () => { - if (shouldAnimate && animateTo) { - scrollConstraintsAnimationTimeout = setTimeout(() => { - const fromValues = { - scrollX: newState.scrollX, - scrollY: newState.scrollY, - zoom: newState.zoom.value, - }; - const toValues = { - scrollX: animateTo.scrollX, - scrollY: animateTo.scrollY, - zoom: animateTo.zoom.value, - }; - - this.animateToConstrainedArea(fromValues, toValues); - }, 200); - } + this.setState({ + ...state, + scrollConstraints: { + ...state.scrollConstraints!, + isAnimating: shouldAnimate, + }, }); }; @@ -2724,13 +2738,16 @@ class App extends React.Component { toValues, duration: 200, onStart: () => { - this.setState((state) => ({ - shouldCacheIgnoreZoom: true, - scrollConstraints: { - ...state.scrollConstraints!, - isAnimating: true, - }, - })); + this.setState((state) => { + cancelRender(); + return { + shouldCacheIgnoreZoom: true, + scrollConstraints: { + ...state.scrollConstraints!, + isAnimating: false, + }, + }; + }); }, onEnd: cleanUp, onCancel: cleanUp, diff --git a/src/scene/scrollConstraints.ts b/src/scene/scrollConstraints.ts index 1aff887e09..402dc80c0a 100644 --- a/src/scene/scrollConstraints.ts +++ b/src/scene/scrollConstraints.ts @@ -330,7 +330,7 @@ export const constrainScrollState = ( zoom: AppState["zoom"]; } | null; } => { - if (!state.scrollConstraints || state.scrollConstraints.isAnimating) { + if (!state.scrollConstraints) { return { state, shouldAnimate: false, animateTo: null }; } const { scrollX, scrollY, width, height, scrollConstraints, zoom } = state;