修复 TransitionPane 动画被打断时节点状态异常的问题 (#4957)

This commit is contained in:
Glavo
2025-12-09 15:32:17 +08:00
committed by GitHub
parent d2c985491a
commit 18000fae30

View File

@@ -31,6 +31,7 @@ import org.jetbrains.annotations.Nullable;
public class TransitionPane extends StackPane { public class TransitionPane extends StackPane {
private Node currentNode; private Node currentNode;
private Animation oldAnimation;
public TransitionPane() { public TransitionPane() {
FXUtils.setOverflowHidden(this); FXUtils.setOverflowHidden(this);
@@ -50,6 +51,11 @@ public class TransitionPane extends StackPane {
public void setContent(Node newView, AnimationProducer transition, public void setContent(Node newView, AnimationProducer transition,
Duration duration, Interpolator interpolator) { Duration duration, Interpolator interpolator) {
if (oldAnimation != null) {
oldAnimation.stop();
oldAnimation = null;
}
Node previousNode = currentNode != newView && getWidth() > 0 && getHeight() > 0 ? currentNode : null; Node previousNode = currentNode != newView && getWidth() > 0 && getHeight() > 0 ? currentNode : null;
currentNode = newView; currentNode = newView;
@@ -80,15 +86,19 @@ public class TransitionPane extends StackPane {
previousNode, previousNode,
newView, newView,
duration, interpolator); duration, interpolator);
newAnimation.setOnFinished(e -> { newAnimation.statusProperty().addListener((observable, oldValue, newValue) -> {
setMouseTransparent(false); if (oldValue == Animation.Status.RUNNING && newValue != Animation.Status.RUNNING) {
getChildren().remove(previousNode); setMouseTransparent(false);
getChildren().remove(previousNode);
if (cacheHint != null) { if (cacheHint != null) {
newView.setCache(false); newView.setCache(false);
}
} }
}); });
FXUtils.playAnimation(this, "transition_pane", newAnimation);
oldAnimation = newAnimation;
newAnimation.play();
}); });
} }