mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: animate to constrained area on setting constrains
This commit is contained in:
parent
d1e3ea431b
commit
186ed43671
1 changed files with 59 additions and 34 deletions
|
@ -2624,10 +2624,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||
// when animating, we use RequestAnimationFrame to prevent the animation
|
||||
// from slowing down other processes
|
||||
if (opts?.animate) {
|
||||
const origScrollX = this.state.scrollX;
|
||||
const origScrollY = this.state.scrollY;
|
||||
const origZoom = this.state.zoom.value;
|
||||
|
||||
const fromValues = {
|
||||
scrollX: this.state.scrollX,
|
||||
scrollY: this.state.scrollY,
|
||||
|
@ -2702,11 +2698,22 @@ class App extends React.Component<AppProps, AppState> {
|
|||
scrollY: animateTo.scrollY,
|
||||
zoom: animateTo.zoom.value,
|
||||
};
|
||||
|
||||
this.animateToConstrainedArea(fromValues, toValues);
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
private animateToConstrainedArea = (
|
||||
fromValues: AnimateTranslateCanvasValues,
|
||||
toValues: AnimateTranslateCanvasValues,
|
||||
) => {
|
||||
const cleanUp = () => {
|
||||
this.setState((inAnimationState) => ({
|
||||
this.setState((state) => ({
|
||||
shouldCacheIgnoreZoom: false,
|
||||
scrollConstraints: {
|
||||
...inAnimationState.scrollConstraints!,
|
||||
...state.scrollConstraints!,
|
||||
isAnimating: false,
|
||||
},
|
||||
}));
|
||||
|
@ -2717,10 +2724,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||
toValues,
|
||||
duration: 200,
|
||||
onStart: () => {
|
||||
this.setState((inAnimationState) => ({
|
||||
this.setState((state) => ({
|
||||
shouldCacheIgnoreZoom: true,
|
||||
scrollConstraints: {
|
||||
...inAnimationState.scrollConstraints!,
|
||||
...state.scrollConstraints!,
|
||||
isAnimating: true,
|
||||
},
|
||||
}));
|
||||
|
@ -2728,12 +2735,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||
onEnd: cleanUp,
|
||||
onCancel: cleanUp,
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
animateTranslateCanvas = ({
|
||||
private animateTranslateCanvas = ({
|
||||
fromValues,
|
||||
toValues,
|
||||
duration,
|
||||
|
@ -8239,10 +8243,31 @@ class App extends React.Component<AppProps, AppState> {
|
|||
scrollConstraints: ScrollConstraints | null,
|
||||
) => {
|
||||
if (scrollConstraints) {
|
||||
this.setState({
|
||||
this.setState(
|
||||
{
|
||||
scrollConstraints,
|
||||
viewModeEnabled: true,
|
||||
},
|
||||
() => {
|
||||
const { animateTo } = constrainScrollState({
|
||||
...this.state,
|
||||
scrollConstraints,
|
||||
});
|
||||
|
||||
this.animateToConstrainedArea(
|
||||
{
|
||||
scrollX: this.state.scrollX,
|
||||
scrollY: this.state.scrollY,
|
||||
zoom: this.state.zoom.value,
|
||||
},
|
||||
{
|
||||
scrollX: animateTo!.scrollX,
|
||||
scrollY: animateTo!.scrollY,
|
||||
zoom: animateTo!.zoom.value,
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
this.setState({
|
||||
scrollConstraints: null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue