Skip to content

Commit

Permalink
Use ScrollBar instead of VirtualScrollBar in findScrollbar. Should fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Feb 27, 2024
1 parent 3f6e767 commit d57bb8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bisq.desktop.components.list_view;

import bisq.desktop.common.threading.UIScheduler;
import com.sun.javafx.scene.control.VirtualScrollBar;
import javafx.geometry.Orientation;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollBar;
import lombok.extern.slf4j.Slf4j;

import java.util.Optional;
Expand All @@ -13,30 +13,44 @@
@Slf4j
public class ListViewUtil {
// We need to lookup VirtualScrollBar not ScrollBar, as ScrollBar would return any of the parents scrollbars.
public static Optional<VirtualScrollBar> findScrollbar(ListView<?> listView, Orientation orientation) {
public static Optional<ScrollBar> findScrollbar(ListView<?> listView, Orientation orientation) {
return listView.lookupAll("VirtualScrollBar").stream()
.filter(node -> node instanceof VirtualScrollBar)
.map(node -> (VirtualScrollBar) node)
.filter(node -> {
// VirtualScrollBar is in package `com.sun.javafx.scene.control`
// and cause an IllegalAccessError on Apple Silicon macs.
// VirtualScrollBar inherits from ScrollBar which is in the
// accessible `javafx.scene.control package`.
// We still wrap it with an exception handler as it is not tested yet with
// Apple Silicon macs.
// See https://github.com/bisq-network/bisq2/issues/1697
try {
return node instanceof ScrollBar;
} catch (IllegalAccessError e) {
log.warn("Access to VirtualScrollBar failed", e);
return false;
}
})
.map(node -> (ScrollBar) node)
.filter(scrollBar -> scrollBar.getOrientation().equals(orientation))
.findFirst();
}

public static CompletableFuture<Optional<VirtualScrollBar>> findScrollbarAsync(ListView<?> listView, Orientation orientation, long timeout) {
Optional<VirtualScrollBar> scrollbar = findScrollbar(listView, orientation);
public static CompletableFuture<Optional<ScrollBar>> findScrollbarAsync(ListView<?> listView, Orientation orientation, long timeout) {
Optional<ScrollBar> scrollbar = findScrollbar(listView, orientation);
if (scrollbar.isPresent()) {
return CompletableFuture.completedFuture(scrollbar);
}
CompletableFuture<Optional<VirtualScrollBar>> future = new CompletableFuture<>();
CompletableFuture<Optional<ScrollBar>> future = new CompletableFuture<>();
future.orTimeout(timeout, TimeUnit.MILLISECONDS);

delayedScrollbarLookup(listView, orientation, future);

return future;
}

private static void delayedScrollbarLookup(ListView<?> listView, Orientation orientation, CompletableFuture<Optional<VirtualScrollBar>> future) {
private static void delayedScrollbarLookup(ListView<?> listView, Orientation orientation, CompletableFuture<Optional<ScrollBar>> future) {
UIScheduler.run(() -> {
Optional<VirtualScrollBar> scrollbar2 = findScrollbar(listView, orientation);
Optional<ScrollBar> scrollbar2 = findScrollbar(listView, orientation);
if (scrollbar2.isPresent()) {
future.complete(scrollbar2);
} else if (!future.isDone()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import bisq.user.profile.UserProfile;
import bisq.user.profile.UserProfileService;
import bisq.user.reputation.ReputationService;
import com.sun.javafx.scene.control.VirtualScrollBar;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
Expand All @@ -76,17 +75,26 @@
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -658,7 +666,7 @@ private static class View extends bisq.desktop.common.view.View<StackPane, Model
private final BisqTooltip scrollDownTooltip;
private final Label placeholderTitle = new Label("");
private final Label placeholderDescription = new Label("");
private Optional<VirtualScrollBar> scrollBar = Optional.empty();
private Optional<ScrollBar> scrollBar = Optional.empty();
private Subscription hasUnreadMessagesPin, showScrolledDownButtonPin;
private Timeline fadeInScrollDownBadgeTimeline;

Expand Down

0 comments on commit d57bb8f

Please sign in to comment.