Search code examples
javafxgluongluon-mobilefloating-action-button

Gluon Mobile 5.0.0 - New FAB behaviour causes trouble


In our app we use multiple floating action buttons. With Gluon 4.4.4 we added them as layers, which had the following behaviour:

  • Each view had it's own FAB.
  • When changing the view, the FAB was hiding.
  • When changing back to the view, the FAB was showing.

Now, with Gluon 5.0.0 (FAB's as objects) the following happens:

  • The buttons get stacked over each other, when they are not hidden.
  • When they are hidden and we change back to a view, the FAB is no longer showing.

This led to a lot of trouble and unnecessary code lines. How can we improve this or how is it intended to be used? We could imagine to use one FAB for the whole app and exchange it's content for each view - however, this ends up in a bigger mess as well, since it would have to be declared public etc.

Any help is appreciated :-)


Solution

  • You are looking for the new FloatingActionButton#showOn(View) method.

    This method makes sure to automatically show and hide the FAB depending on the View's showing property, removing most of the boiler code required in earlier versions to achieve the same functionality.

    From the Javadocs:

    Makes sure that the FAB is automatically shown when the supplied view is shown. The FAB also automatically hides when the view is hidden. This allows the developer to not worry about calling show() and hide() methods explicitly.