Skip to content

Commit

Permalink
fix #761 Global config for a tooltip CollapseStrategy Supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Feb 9, 2023
1 parent 1518ca6 commit 6758572
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ public class Animation {
private StartHandler startHandler = DEFAULT_START_HANDLER;
private EventListener stopListener;
private double repeatCount = 1;
private Timer delayTimer;

/** @param element an {@link HTMLElement} to be animated */
public Animation(HTMLElement element) {
this.element = DominoElement.of(element);
delayTimer =
new Timer() {
@Override
public void run() {
animateElement();
}
};
}

/**
Expand Down Expand Up @@ -183,12 +191,7 @@ public Animation beforeStart(StartHandler startHandler) {
*/
public Animation animate() {
if (delay > 0) {
new Timer() {
@Override
public void run() {
animateElement();
}
}.schedule(delay);
delayTimer.schedule(delay);
} else {
animateElement();
}
Expand Down Expand Up @@ -229,6 +232,7 @@ public void stop() {

/** stops the animation and calls the {@link CompleteCallback} if it is set. */
public void stop(boolean silent) {
delayTimer.cancel();
element.removeCss(transition.getStyle());
element.removeCss("animated");
element.removeCss("infinite");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class AnimationCollapseOptions {
private CollapseDuration showDuration;
private CollapseDuration hideDuration;
private int showDelay = 0;
private int hideDelay = 0;

public Transition getShowTransition() {
return showTransition;
Expand Down Expand Up @@ -70,13 +69,4 @@ public AnimationCollapseOptions setShowDelay(int showDelay) {
this.showDelay = showDelay;
return this;
}

public int getHideDelay() {
return hideDelay;
}

public AnimationCollapseOptions setHideDelay(int hideDelay) {
this.hideDelay = hideDelay;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class AnimationCollapseStrategy implements CollapseStrategy {
private boolean showing = false;
private boolean hiding = false;
private CollapsibleHandlers handlers;
private Animation showAnimation;

@Override
public void init(
Expand Down Expand Up @@ -72,42 +73,43 @@ public void show(HTMLElement element, Style<HTMLElement, IsElement<HTMLElement>>
if (!showing) {
DominoElement.of(element).removeCss(this.options.getShowDuration().getStyle());
DominoElement.of(element).removeCss(this.options.getHideDuration().getStyle());
Animation.create(element)
.duration(this.options.getShowDuration().getDuration())
.transition(this.options.getShowTransition())
.delay(this.options.getShowDelay())
.beforeStart(
theElement -> {
showing = true;
if (nonNull(hideAnimation)) {
hideAnimation.stop(true);
hideAnimation = null;
hiding = false;
}
style.removeCssProperty("display");
DominoElement.of(element).removeAttribute("d-collapsed");
this.handlers.onBeforeShow().run();
})
.callback(
e -> {
showing = false;
this.handlers.onShowCompleted().run();
})
.animate();
showAnimation =
Animation.create(element)
.duration(this.options.getShowDuration().getDuration())
.transition(this.options.getShowTransition())
.delay(this.options.getShowDelay())
.beforeStart(
theElement -> {
showing = true;
if (nonNull(hideAnimation)) {
hideAnimation.stop(true);
hideAnimation = null;
hiding = false;
}
style.removeCssProperty("display");
DominoElement.of(element).removeAttribute("d-collapsed");
this.handlers.onBeforeShow().run();
})
.callback(
e -> {
showing = false;
this.handlers.onShowCompleted().run();
})
.animate();
}
}

/** {@inheritDoc} */
@Override
public void hide(HTMLElement element, Style<HTMLElement, IsElement<HTMLElement>> style) {
showAnimation.stop(false);
if (!hiding) {
DominoElement.of(element).removeCss(this.options.getShowDuration().getStyle());
DominoElement.of(element).removeCss(this.options.getHideDuration().getStyle());
hideAnimation =
Animation.create(element)
.duration(this.options.getHideDuration().getDuration())
.transition(this.options.getHideTransition())
.delay(this.options.getHideDelay())
.beforeStart(
element1 -> {
hiding = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public class DominoUIConfig {
.setHideTransition(Transition.FADE_OUT)
.setShowDuration(CollapseDuration._300ms)
.setHideDuration(CollapseDuration._300ms)
.setShowDelay(500)
.setHideDelay(100));
.setShowDelay(500));
private TreeCollapseSupplier defaultTreeCollapseStrategySupplier =
TreeHeightCollapseStrategy::new;

Expand Down

0 comments on commit 6758572

Please sign in to comment.