Giter Club home page Giter Club logo

Comments (12)

kabumere avatar kabumere commented on May 25, 2024 1

Hey @kartik0198,

I think the available API does what you need for your use case.

If you need to see whether the ExpandableFab in the current screen orientation is opened or not, use the isOpen() method on your ExpandableFabLayout container.

If you want to change the icon on the ExpandableFab, use efabIcon like I mentioned before.

You can also call setOnClickListener on your ExpandableFab and set a custom callback that is invoked when the ExpandableFab (or its label) is clicked.

So a rough outline of what it sounds like you want to do would be something like this (I'm typing this Kotlin snippet on my phone, so it may contain some slight syntax errors and such):

val expandableFabLayout = view.findViewById<ExpandableFabLayout>(R.id.expandableFabLayout)
val expandableFab = view.findViewById<ExpandableFab>(R.id.expandableFab)
val openedIcon = ContextCompat.getDrawable(context, R.drawable.opened_icon_24dp)
val closedIcon = ContextCompat.getDrawable(context, R.drawable.closed_icon_24dp)

expandableFab.setOnClickListener {
  if(expandableFabLayout.isOpen()){
    expandableFab.efabIcon = openedIcon
  } else {
    expandableFab.efabIcon = closedIcon
  }
}

Please note that isOpen will only return true when the ExpandableFab is completely open and all animations are finished. So if your animations are long, the snippet I gave above may not work as expected. But there are multiple work arounds for this though. The easiest one for you may just be to clone the library locally, then change this method so that onClickListener?.onClick(it) is called before defaultOnClickBehavior?.invoke().

from expandable-fab.

kabumere avatar kabumere commented on May 25, 2024 1

Hey @kartik0198,

Every View within the library has animations for hiding and showing or opening and closing, so you need to update the right field for every View in the library you use.

For the ExpandableFab: use openingAnimationDurationMs and closingAnimationDurationMs.
For FabOptions: use openingAnimationDurationMs and closingAnimationDurationMs.
For Overlays: use openingAnimationDurationMs and closingAnimationDurationMs.
For Labels: use visibleToHiddenAnimationDurationMs and hiddenToVisibleAnimationDurationMs. You only need to modify label animation durations if you're actually using labels.

The example below shows how you can set all animation durations on the 3 custom Views below to 0 milliseconds:

<com.nambimobile.widgets.efab.ExpandableFabLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.nambimobile.widgets.efab.Overlay
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:overlay_openingAnimationDurationMs="0"
            app:overlay_closingAnimationDurationMs="0"/>
            
        <com.nambimobile.widgets.efab.ExpandableFab
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="@dimen/ui_margin_medium"
            android:layout_marginEnd="@dimen/ui_margin_medium"
            android:layout_marginRight="@dimen/ui_margin_medium"
            app:efab_openingAnimationDurationMs="0"
            app:efab_closingAnimationDurationMs="0"
            app:label_text="Click Me!"
            app:label_visibleToHiddenAnimationDurationMs="0"
            app:label_hiddenToVisibleAnimationDurationMs="0"/>
            
        <com.nambimobile.widgets.efab.FabOption
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_openingAnimationDurationMs="0"
            app:fab_closingAnimationDurationMs="0"
            app:label_text="Option 1"
            app:label_visibleToHiddenAnimationDurationMs="0"
            app:label_hiddenToVisibleAnimationDurationMs="0"/>
        
</com.nambimobile.widgets.efab.ExpandableFabLayout>

I made it this way because I wanted to give developers like you the ultimate control over the widget - I wanted you to be able to customize as much as possible and set different values for every single View if you wanted. But I can see how this becomes tedious in practice. I'll probably update the library soon to allow users to set the same animation duration for all components in a single place. For now though, if you wanted no animations at all, you'll have to set the animation duration on every single custom View you use.

However, since you're cloning the library and updating the onClick function as I suggested earlier, do you even need to update the animation durations? Or is this a separate issue and you just don't want animations?

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024 1

Hi, I was successfully able to disable all animations after your previous answer so I do not need to clone the lib locally. I was even apprehensive of cloning it locally as I would not be able to update it whenever you release new changes. Just a suggestion - you may provide API to set the same animation duration for all components in a single place and change the icon on close and open of expandableFAB gracefully. Or maybe I will raise a PR to contribute to your project. Great work, by the way!

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024 1

Another issue is that ideally isOpen should've been a livedata as I need to change open/close icon on user clicks on overlay(which closes the FAB), and also when user clicks on a FAB option. But currently since I was setting click listener on FAB button so other cases were missed.

from expandable-fab.

kabumere avatar kabumere commented on May 25, 2024

Hey @kartik0198,

For changing the icon on an ExpandableFab, you can use this field.

For changing the icon on a FabOption, you can use this field.

Is this the functionality you're looking for? If not, can you further clarify what you're trying to accomplish?

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024

from expandable-fab.

kabumere avatar kabumere commented on May 25, 2024

Hey @kartik0198,

Did the above solution help?

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024

Hey @kabumere, yes the above solution worked but due to the animation issue I am now cloning the library and changing the onClick method as you suggested. Thanks for the help.

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024

One more issue, even though I am setting openingAnimationDurationMs and closingAnimationDurationMs as 0L, the animation is still appearing. Any value that I set is not being reflected

from expandable-fab.

kabumere avatar kabumere commented on May 25, 2024

Thank you for the great suggestions and kind words, @kartik0198! I think implementing those features would definitely add value to the project. If you choose to implement them before I do, please read our Contributing guidelines.

Closing the ticket since the issue has been resolved, but of course feel free to open a new issue if anything else comes up.

from expandable-fab.

kabumere avatar kabumere commented on May 25, 2024

Hey @kartik0198,

Good news, starting from v1.2.1, the ExpandableFab library now lets you set global animation durations on the parent layout (instead of having to set the durations on each of the individual Overlays, ExpandableFabs, FabOptions and Labels). This version also includes other new features and bug fixes.

You can get it by cloning the master branch of this repo, or pulling it from Maven Central. Thanks for using the library!

**EDIT: to those viewing this in the future, please use v1.2.1 or higher, not v1.2.0 (v1.2.0 contains a bug in the Label class when ran on some older devices).

from expandable-fab.

kartik0198 avatar kartik0198 commented on May 25, 2024

from expandable-fab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.