Skip to content

Commit 18000fa

Browse files
authored
修复 TransitionPane 动画被打断时节点状态异常的问题 (#4957)
1 parent d2c9854 commit 18000fa

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
public class TransitionPane extends StackPane {
3232

3333
private Node currentNode;
34+
private Animation oldAnimation;
3435

3536
public TransitionPane() {
3637
FXUtils.setOverflowHidden(this);
@@ -50,6 +51,11 @@ public final void setContent(Node newView, AnimationProducer transition, Duratio
5051

5152
public void setContent(Node newView, AnimationProducer transition,
5253
Duration duration, Interpolator interpolator) {
54+
if (oldAnimation != null) {
55+
oldAnimation.stop();
56+
oldAnimation = null;
57+
}
58+
5359
Node previousNode = currentNode != newView && getWidth() > 0 && getHeight() > 0 ? currentNode : null;
5460
currentNode = newView;
5561

@@ -80,15 +86,19 @@ public void setContent(Node newView, AnimationProducer transition,
8086
previousNode,
8187
newView,
8288
duration, interpolator);
83-
newAnimation.setOnFinished(e -> {
84-
setMouseTransparent(false);
85-
getChildren().remove(previousNode);
86-
87-
if (cacheHint != null) {
88-
newView.setCache(false);
89+
newAnimation.statusProperty().addListener((observable, oldValue, newValue) -> {
90+
if (oldValue == Animation.Status.RUNNING && newValue != Animation.Status.RUNNING) {
91+
setMouseTransparent(false);
92+
getChildren().remove(previousNode);
93+
94+
if (cacheHint != null) {
95+
newView.setCache(false);
96+
}
8997
}
9098
});
91-
FXUtils.playAnimation(this, "transition_pane", newAnimation);
99+
100+
oldAnimation = newAnimation;
101+
newAnimation.play();
92102
});
93103

94104
}

0 commit comments

Comments
 (0)