Charm 4.0.0 PopupView shows up only once

2019-03-05 23:51发布

问题:

I have a set of Controls which use PopupView. Since the update to Charm 4.0.0, they show some weird behaviour.

When I selected a Node contained in the PopupView, the PopupView used to get closed. Now the PopupView gets closed but immediately shows up again. Furthermore as soon as I click outside the PopupView it gets closed, but I am not able to show it again.

I've tested it with the example from the Gluon javadoc and experienced the same behaviour regarding the second issue:

 public class MyApp extends MobileApplication{
   private Button button;
   private PopupView popupView;

   @Override
   public void init() {
       addViewFactory(HOME_VIEW, ()  -> {
       button = new Button("Click");
       button.setOnAction(event  -> popupView.show());

       popupView = new PopupView(button);

       VBox vBox = new VBox();
       vBox.getChildren().addAll(new Label("Choice 1"), new Label("Choice 2"), new Label("Choice 3"));
       vBox.setSpacing(5);

       popupView.setContent(vBox);

       return new View(button) {
         @Override
         protected void updateAppBar(AppBar appBar) {
           appBar.setTitleText("PopupView");
         }
       };
     });
   }
 } 

回答1:

Thanks for reporting. I've filed an issue so it get fixed as soon as possible.

In the meantime, a workaround for the PopupView can be this:

PopupView popupView = new PopupView(button) {

    private final GlassPane glassPane = MobileApplication.getInstance().getGlassPane();

        {
            this.setOnMouseReleased(e -> this.hide());
        }

    @Override public void show() {
        // before showing add the glassPane (issue #2):
        this.mobileLayoutPaneProperty().set(glassPane);
        super.show(); 
    }

    @Override public void hide() {
        // when hiding don't show again (issue #1):
        setShowing(false);
        super.hide(); 
    }
};