nambicompany / expandable-fab

A highly customizable 'speed dial' FloatingActionButton implementation.
https://nambicompany.github.io/expandable-fab/
MIT License
200 stars 21 forks source link

Keeping ExpandableFab from closing when a FabOption is clicked #23

Closed Burakito closed 3 years ago

Burakito commented 3 years ago

Hi, first of all let me congratulate you on the quality of the library and the support I see you are providing.

I would like to use the expandable fab as a container for a set of checkboxes. In that scenario I need to keep the different FabOptions visible after clicking on one of them just in case the user wants to select more than one. The 'menu' would only be closed after clicking on the ExpandableFab itself. Is such a feature implemented? Is there any workaround to that?

kabumere commented 3 years ago

Hey @Burakito,

This seems like a very unique use case, so I'm hesitant to add the functionality to the official published API. However, there's an easy workaround to accomplish your desired effect:

1) Clone the library and add it to your project (so don't pull it in from Maven Central, add the source code as a dependency to your project manually) 2) Modify the FabOption's setOnClickListener function to directly call your custom onClick behavior without executing the default behavior when clicked (the default behavior for a FabOption's onClick includes closing the ExpandableFab). So in short, this method should now look like this:

override fun setOnClickListener(onClickListener: OnClickListener?) {
    super.setOnClickListener(onClickListener)

    setLabelOnClickListener()
}

If this functionality ever gets requested again, I may consider adding it to the library properly. And if I do, I'll comment on this ticket and let you know. As of now though, I can't imagine too many others needing to use the ExpandableFab as a container for checkboxes (though I must say that's a very cool and unique use case!).

EDIT: In case you're using an Overlay and want to prevent clicks on that from automatically closing the ExpandableFab as well, you can easily do that by deleting its overridden setOnClickListener method. So just delete this method. Any custom onClickListener you set on the Overlay will still be executed.

kabumere commented 3 years ago

Closing due to inactivity.